diff --git a/css/GridField.css b/css/GridField.css index 2280438fd..4489839a4 100644 --- a/css/GridField.css +++ b/css/GridField.css @@ -38,7 +38,9 @@ multiple images. */ .cms table.ss-gridfield-table tbody td button { border: none; background: none; margin: 0 0 0 2px; padding: 0; width: auto; text-shadow: none; } .cms table.ss-gridfield-table tbody td button.ui-state-hover { background: none; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; } .cms table.ss-gridfield-table tbody td button.ui-state-active { border: none; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; } -.cms table.ss-gridfield-table tbody td a.edit-link { display: inline-block; width: 16px; height: 20px; text-indent: 9999em; overflow: hidden; vertical-align: middle; background: url(../images/icons/document--pencil.png) no-repeat 0 1px; } +.cms table.ss-gridfield-table tbody td a.view-link, .cms table.ss-gridfield-table tbody td a.edit-link { display: inline-block; width: 16px; height: 20px; text-indent: 9999em; overflow: hidden; vertical-align: middle; } +.cms table.ss-gridfield-table tbody td a.view-link { background: url(../admin/images/btn-icon/magnifier.png) no-repeat 0 1px; } +.cms table.ss-gridfield-table tbody td a.edit-link { background: url(../admin/images/btn-icon/document--pencil.png) no-repeat 0 1px; } .cms table.ss-gridfield-table tfoot { color: #1d2224; } .cms table.ss-gridfield-table tfoot tr td { background: #95a5ab; padding: .7em; border-bottom: 1px solid rgba(0, 0, 0, 0.1); } .cms table.ss-gridfield-table tr.title th { position: relative; background: #7f9198; border-top: 1px solid rgba(0, 0, 0, 0.1); padding: 5px; min-height: 40px; background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2IxYzBjNSIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzdmOTE5OCIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA=='); background-size: 100%; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #b1c0c5), color-stop(100%, #7f9198)); background-image: -webkit-linear-gradient(#b1c0c5, #7f9198); background-image: -moz-linear-gradient(#b1c0c5, #7f9198); background-image: -o-linear-gradient(#b1c0c5, #7f9198); background-image: -ms-linear-gradient(#b1c0c5, #7f9198); background-image: linear-gradient(#b1c0c5, #7f9198); text-shadow: rgba(0, 0, 0, 0.3) 0px -1px 0; } diff --git a/forms/gridfield/GridFieldConfig.php b/forms/gridfield/GridFieldConfig.php old mode 100755 new mode 100644 index 2a17054f5..23c682f62 --- a/forms/gridfield/GridFieldConfig.php +++ b/forms/gridfield/GridFieldConfig.php @@ -143,6 +143,20 @@ class GridFieldConfig_Base extends GridFieldConfig { } } +/** + * Allows viewing readonly details of individual records. + */ +class GridFieldConfig_RecordViewer extends GridFieldConfig_Base { + + public function __construct($itemsPerPage = null) { + parent::__construct($itemsPerPage); + + $this->addComponent(new GridFieldViewButton()); + $this->addComponent(new GridFieldDetailForm()); + } + +} + /** * */ diff --git a/forms/gridfield/GridFieldDetailForm.php b/forms/gridfield/GridFieldDetailForm.php old mode 100755 new mode 100644 index 113cd0566..6874d37d7 --- a/forms/gridfield/GridFieldDetailForm.php +++ b/forms/gridfield/GridFieldDetailForm.php @@ -225,7 +225,30 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler { public function Link($action = null) { return Controller::join_links($this->gridField->Link('item'), $this->record->ID ? $this->record->ID : 'new', $action); } - + + public function view($request) { + if(!$this->record->canView()) { + $this->httpError(403); + } + + $controller = $this->getToplevelController(); + + $form = $this->ItemEditForm($this->gridField, $request); + $form->makeReadonly(); + + $data = new ArrayData(array( + 'Backlink' => $controller->Link(), + 'ItemEditForm' => $form + )); + $return = $data->renderWith($this->template); + + if($request->isAjax()) { + return $return; + } else { + return $controller->customise(array('Content' => $return)); + } + } + function edit($request) { $controller = $this->getToplevelController(); $form = $this->ItemEditForm($this->gridField, $request); diff --git a/forms/gridfield/GridFieldViewButton.php b/forms/gridfield/GridFieldViewButton.php new file mode 100644 index 000000000..729196a6d --- /dev/null +++ b/forms/gridfield/GridFieldViewButton.php @@ -0,0 +1,35 @@ +canView()) { + $data = new ArrayData(array( + 'Link' => Controller::join_links($field->Link('item'), $record->ID, 'view') + )); + return $data->renderWith('GridFieldViewButton'); + } + } + + public function getColumnAttributes($field, $record, $col) { + return array('class' => 'col-buttons'); + } + + public function getColumnMetadata($gridField, $col) { + return array('title' => null); + } + +} diff --git a/scss/GridField.scss b/scss/GridField.scss index c84dfc2ac..70eb7978b 100644 --- a/scss/GridField.scss +++ b/scss/GridField.scss @@ -219,14 +219,19 @@ $gf_grid_x: 16px; @include box-shadow-none; } } - a.edit-link { + a.view-link, a.edit-link { display:inline-block; width:$gf_grid_x; height:20px; //min height to fit the edit icon text-indent:9999em; overflow: hidden; vertical-align: middle; - background: url(../images/icons/document--pencil.png) no-repeat 0 1px; + } + a.view-link { + background: url(../admin/images/btn-icon/magnifier.png) no-repeat 0 1px; + } + a.edit-link { + background: url(../admin/images/btn-icon/document--pencil.png) no-repeat 0 1px; } } } diff --git a/templates/Includes/GridFieldViewButton.ss b/templates/Includes/GridFieldViewButton.ss new file mode 100644 index 000000000..126061cde --- /dev/null +++ b/templates/Includes/GridFieldViewButton.ss @@ -0,0 +1 @@ +View \ No newline at end of file diff --git a/tests/forms/gridfield/GridFieldDetailFormTest.php b/tests/forms/gridfield/GridFieldDetailFormTest.php index 73dc4aea8..b42fe35f0 100644 --- a/tests/forms/gridfield/GridFieldDetailFormTest.php +++ b/tests/forms/gridfield/GridFieldDetailFormTest.php @@ -47,6 +47,26 @@ class GridFieldDetailFormTest extends FunctionalTest { $this->assertEquals($count + 1, $group->People()->Count()); } + public function testViewForm() { + $this->logInWithPermission('ADMIN'); + + $response = $this->get('GridFieldDetailFormTest_Controller'); + $parser = new CSSContentParser($response->getBody()); + + $viewLink = $parser->getBySelector('.ss-gridfield-items .first .view-link'); + $viewLink = (string) $viewLink[0]['href']; + + $response = $this->get($viewLink); + $parser = new CSSContentParser($response->getBody()); + + $firstName = $parser->getBySelector('#Form_ItemEditForm_FirstName'); + $surname = $parser->getBySelector('#Form_ItemEditForm_Surname'); + + $this->assertFalse($response->isError()); + $this->assertEquals('Joe', (string) $firstName[0]); + $this->assertEquals('Bloggs', (string) $surname[0]); + } + function testEditForm() { $this->logInWithPermission('ADMIN'); $group = DataList::create('GridFieldDetailFormTest_PeopleGroup') @@ -237,6 +257,7 @@ class GridFieldDetailFormTest_Controller extends Controller implements TestOnly $field = new GridField('testfield', 'testfield', $group->People()); $field->getConfig()->addComponent(new GridFieldToolbarHeader()); $field->getConfig()->addComponent(new GridFieldAddNewButton('toolbar-header-right')); + $field->getConfig()->addComponent(new GridFieldViewButton()); $field->getConfig()->addComponent(new GridFieldEditButton()); $field->getConfig()->addComponent($gridFieldForm = new GridFieldDetailForm($this, 'Form')); $field->getConfig()->addComponent(new GridFieldEditButton());