Open Journal Systems  3.0.0
 All Classes 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  $this->setInstructions('manager.setup.submissionPreparationChecklistDescription');
43 
44 
45  // Add grid-level actions
46  import('lib.pkp.classes.linkAction.request.AjaxModal');
47  $router = $request->getRouter();
48  $this->addAction(
49  new LinkAction(
50  'addItem',
51  new AjaxModal(
52  $router->url($request, null, null, 'addItem', null, array('gridId' => $this->getId())),
53  __('grid.action.addItem'),
54  'modal_add_item',
55  true),
56  __('grid.action.addItem'),
57  'add_item')
58  );
59 
60  // Columns
61  $this->addColumn(
62  new GridColumn(
63  'content',
64  'grid.submissionChecklist.column.checklistItem',
65  null,
66  'controllers/grid/gridCell.tpl',
67  null,
68  array('multiline' => true, 'html' => true, 'maxLength' => 220)
69  )
70  );
71  }
72 
73 
74  //
75  // Overridden methods from GridHandler
76  //
80  function initFeatures($request, $args) {
81  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
82  return array(new OrderGridItemsFeature());
83  }
84 
88  function getRowInstance() {
89  return new SubmissionChecklistGridRow();
90  }
91 
95  function loadData($request, $filter) {
96  // Elements to be displayed in the grid
97  $router = $request->getRouter();
98  $context = $router->getContext($request);
99  $submissionChecklist = $context->getSetting('submissionChecklist');
100 
101  return $submissionChecklist[AppLocale::getLocale()];
102  }
103 
104 
105  //
106  // Public grid actions.
107  //
113  function addItem($args, $request) {
114  // Calling editItem with an empty row id will add a new row.
115  return $this->editItem($args, $request);
116  }
117 
124  function editItem($args, $request) {
125  import('lib.pkp.controllers.grid.settings.submissionChecklist.form.SubmissionChecklistForm');
126  $submissionChecklistId = isset($args['rowId']) ? $args['rowId'] : null;
127  $submissionChecklistForm = new SubmissionChecklistForm($submissionChecklistId);
128 
129  $submissionChecklistForm->initData($args, $request);
130 
131  $json = new JSONMessage(true, $submissionChecklistForm->fetch($request));
132  return $json->getString();
133  }
134 
141  function updateItem($args, $request) {
142  // -> submissionChecklistId must be present and valid
143  // -> htmlId must be present and valid
144 
145  import('lib.pkp.controllers.grid.settings.submissionChecklist.form.SubmissionChecklistForm');
146  $submissionChecklistId = isset($args['rowId']) ? $args['rowId'] : null;
147  $submissionChecklistForm = new SubmissionChecklistForm($submissionChecklistId);
148  $submissionChecklistForm->readInputData();
149 
150  if ($submissionChecklistForm->validate()) {
151  $submissionChecklistForm->execute($args, $request);
152  return DAO::getDataChangedEvent($submissionChecklistForm->submissionChecklistId);
153  } else {
154  $json = new JSONMessage(false);
155  return $json->getString();
156  }
157  }
158 
165  function deleteItem($args, $request) {
166  $rowId = $request->getUserVar('rowId');
167 
168  $router = $request->getRouter();
169  $context = $router->getContext($request);
170 
171  // get all of the submissionChecklists
172  $submissionChecklistAll = $context->getSetting('submissionChecklist');
173 
174  foreach (AppLocale::getSupportedLocales() as $locale => $name) {
175  if ( isset($submissionChecklistAll[$locale][$rowId]) ) {
176  unset($submissionChecklistAll[$locale][$rowId]);
177  } else {
178  // only fail if the currently displayed locale was not set
179  // (this is the one that needs to be removed from the currently displayed grid)
180  if ( $locale == AppLocale::getLocale() ) {
181  $json = new JSONMessage(false, __('manager.setup.errorDeletingSubmissionChecklist'));
182  return $json->getString();
183  exit;
184  }
185  }
186  }
187 
188  $context->updateSetting('submissionChecklist', $submissionChecklistAll, 'object', true);
189  return DAO::getDataChangedEvent($rowId);
190  }
191 
195  function getDataElementSequence($gridDataElement) {
196  return $gridDataElement['order'];
197  }
198 
202  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
203  $router = $request->getRouter();
204  $context = $router->getContext($request);
205 
206  // Get all of the submissionChecklists.
207  $submissionChecklistAll = $context->getSetting('submissionChecklist');
208  $locale = AppLocale::getLocale();
209 
210  if (isset($submissionChecklistAll[$locale][$rowId])) {
211  $submissionChecklistAll[$locale][$rowId]['order'] = $newSequence;
212  }
213 
214  $orderMap = array();
215  foreach ($submissionChecklistAll[$locale] as $id => $checklistItem) {
216  $orderMap[$id] = $checklistItem['order'];
217  }
218 
219  asort($orderMap);
220 
221  // Build the new order checklist object.
222  $orderedChecklistItems = array();
223  foreach ($orderMap as $id => $order) {
224  if (isset($submissionChecklistAll[$locale][$id])) {
225  $orderedChecklistItems[$locale][$id] = $submissionChecklistAll[$locale][$id];
226  }
227  }
228 
229  $context->updateSetting('submissionChecklist', $orderedChecklistItems, 'object', true);
230  }
231 }
232 
233 ?>
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()
static getDataChangedEvent($elementId=null, $parentElementId=null)
Definition: DAO.inc.php:606
setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
Implements grid ordering functionality.
setInstructions($instructions)
Base class for setup grid handlers.
Represents a column within a grid. It is used to configure the way cells within a column are displaye...
Base class defining an action that can be performed by the user in the user interface.