Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
SubmissionChecklistGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.grid.settings.SetupGridHandler');
17 import('lib.pkp.controllers.grid.settings.submissionChecklist.SubmissionChecklistGridRow');
18 
20 
25  parent::SetupGridHandler();
26  $this->addRoleAssignment(array(ROLE_ID_MANAGER),
27  array('fetchGrid', 'fetchRow', 'addItem', 'editItem', 'updateItem', 'deleteItem', 'saveSequence'));
28  }
29 
30  //
31  // Overridden template methods
32  //
36  function initialize($request) {
37  parent::initialize($request);
38 
39  // Basic grid configuration
40  $this->setId('submissionChecklist');
41  $this->setTitle('manager.setup.submissionPreparationChecklist');
42 
43  // Add grid-level actions
44  import('lib.pkp.classes.linkAction.request.AjaxModal');
45  $router = $request->getRouter();
46  $this->addAction(
47  new LinkAction(
48  'addItem',
49  new AjaxModal(
50  $router->url($request, null, null, 'addItem', null, array('gridId' => $this->getId())),
51  __('grid.action.addItem'),
52  'modal_add_item',
53  true),
54  __('grid.action.addItem'),
55  'add_item')
56  );
57 
58  // Columns
59  $this->addColumn(
60  new GridColumn(
61  'content',
62  'grid.submissionChecklist.column.checklistItem',
63  null,
64  null,
65  null,
66  array('html' => true, 'maxLength' => 220)
67  )
68  );
69  }
70 
71 
72  //
73  // Overridden methods from GridHandler
74  //
78  function initFeatures($request, $args) {
79  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
80  return array(new OrderGridItemsFeature());
81  }
82 
86  protected function getRowInstance() {
87  return new SubmissionChecklistGridRow();
88  }
89 
93  protected function loadData($request, $filter) {
94  // Elements to be displayed in the grid
95  $router = $request->getRouter();
96  $context = $router->getContext($request);
97  $submissionChecklist = $context->getSetting('submissionChecklist');
98 
99  return $submissionChecklist[AppLocale::getLocale()];
100  }
101 
102 
103  //
104  // Public grid actions.
105  //
111  function addItem($args, $request) {
112  // Calling editItem with an empty row id will add a new row.
113  return $this->editItem($args, $request);
114  }
115 
122  function editItem($args, $request) {
123  import('lib.pkp.controllers.grid.settings.submissionChecklist.form.SubmissionChecklistForm');
124  $submissionChecklistId = isset($args['rowId']) ? $args['rowId'] : null;
125  $submissionChecklistForm = new SubmissionChecklistForm($submissionChecklistId);
126 
127  $submissionChecklistForm->initData($args, $request);
128 
129  return new JSONMessage(true, $submissionChecklistForm->fetch($request));
130  }
131 
138  function updateItem($args, $request) {
139  // -> submissionChecklistId must be present and valid
140  // -> htmlId must be present and valid
141 
142  import('lib.pkp.controllers.grid.settings.submissionChecklist.form.SubmissionChecklistForm');
143  $submissionChecklistId = isset($args['rowId']) ? $args['rowId'] : null;
144  $submissionChecklistForm = new SubmissionChecklistForm($submissionChecklistId);
145  $submissionChecklistForm->readInputData();
146 
147  if ($submissionChecklistForm->validate()) {
148  $submissionChecklistForm->execute($args, $request);
149  return DAO::getDataChangedEvent($submissionChecklistForm->submissionChecklistId);
150  } else {
151  return new JSONMessage(false);
152  }
153  }
154 
161  function deleteItem($args, $request) {
162  $rowId = $request->getUserVar('rowId');
163 
164  $router = $request->getRouter();
165  $context = $router->getContext($request);
166 
167  // get all of the submissionChecklists
168  $submissionChecklistAll = $context->getSetting('submissionChecklist');
169 
170  foreach (AppLocale::getSupportedLocales() as $locale => $name) {
171  if ( isset($submissionChecklistAll[$locale][$rowId]) ) {
172  unset($submissionChecklistAll[$locale][$rowId]);
173  } else {
174  // only fail if the currently displayed locale was not set
175  // (this is the one that needs to be removed from the currently displayed grid)
176  if ( $locale == AppLocale::getLocale() ) {
177  return new JSONMessage(false, __('manager.setup.errorDeletingSubmissionChecklist'));
178  }
179  }
180  }
181 
182  $context->updateSetting('submissionChecklist', $submissionChecklistAll, 'object', true);
183  return DAO::getDataChangedEvent($rowId);
184  }
185 
189  function getDataElementSequence($gridDataElement) {
190  return $gridDataElement['order'];
191  }
192 
196  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
197  $router = $request->getRouter();
198  $context = $router->getContext($request);
199 
200  // Get all of the submissionChecklists.
201  $submissionChecklistAll = $context->getSetting('submissionChecklist');
202  $locale = AppLocale::getLocale();
203 
204  if (isset($submissionChecklistAll[$locale][$rowId])) {
205  $submissionChecklistAll[$locale][$rowId]['order'] = $newSequence;
206  }
207 
208  $orderMap = array();
209  foreach ($submissionChecklistAll[$locale] as $id => $checklistItem) {
210  $orderMap[$id] = $checklistItem['order'];
211  }
212 
213  asort($orderMap);
214 
215  // Build the new order checklist object.
216  $orderedChecklistItems = array();
217  foreach ($orderMap as $id => $order) {
218  if (isset($submissionChecklistAll[$locale][$id])) {
219  $orderedChecklistItems[$locale][$id] = $submissionChecklistAll[$locale][$id];
220  }
221  }
222 
223  $context->updateSetting('submissionChecklist', $orderedChecklistItems, 'object', true);
224  }
225 }
226 
227 ?>
Handle submissionChecklist grid row requests.
Handle submissionChecklist grid requests.
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
addColumn($column)
static getSupportedLocales()
addRoleAssignment($roleIds, $operations)
A modal that retrieves its content from via AJAX.
Form for adding/edditing a submissionChecklist stores/retrieves from an associative array...
Class to represent a JSON (Javascript Object Notation) message.
static getLocale()
setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
Implements grid ordering functionality.
Base class for setup grid handlers.
The GridColumn class represents a column within a grid. It is used to format the data presented in a ...
static getDataChangedEvent($elementId=null, $parentElementId=null, $content= '')
Definition: DAO.inc.php:633
Base class defining an action that can be performed by the user in the user interface.