wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
actions.js.php
Go to the documentation of this file.
1 /**
2  * @class wcmf.grid.Action. Base class for grid actions
3  */
4 wcmf.grid.Action = function(config) {
5  Ext.apply(this, config);
6  wcmf.grid.Action.superclass.constructor.call(this);
7 };
8 
9 Ext.extend(wcmf.grid.Action, Ext.util.Observable, {
10  header:'',
11  width:25,
12  sortable:false,
13  fixed:true,
14  dataIndex:'',
15 
16  init: function(grid) {
17  this.grid = grid;
18 
19  // add click listener
20  grid.on('render', function() {
21  grid.getView().mainBody.on('mousedown', this.onMouseDown, this);
22  }, this);
23  },
24 
25  /**
26  * Perform the action. The name is derived from the className of the clicked image.
27  */
28  onMouseDown: function(e, t) {
29  var action = t.className;
30  var regexp = /Action$/;
31  if (action.search(regexp) > 0) {
32  var actionName = action.replace(regexp, '');
33  if (this.getSupportedActions().indexOf(actionName) != -1) {
34 
35  // get row
36  var row = e.getTarget('.x-grid3-row');
37  // get the row record
38  var record = this.grid.getStore().getAt(row.rowIndex);
39  // select the row
40  this.grid.getSelectionModel().selectRow(row.rowIndex, false);
41 
42  e.stopEvent();
43  this.performAction(actionName, record);
44  }
45  }
46  },
47 
48  /**
49  * Get the names of actions that this class handles. Subclasses have to
50  * specify this
51  */
52  getSupportedActions: function() {
53  return [];
54  },
55 
56  /**
57  * Perform the given action
58  */
59  performAction: function(actionName, record) {
60  // do nothing
61  },
62 
63  /**
64  * Render a link. Any parameter may be null.
65  */
66  renderAction: function(actionName, text, image) {
67  var link = '';
68 
69  if (image != null)
70  link += String.format('<img class="{0}" src="{1}" alt="{2}" title="{2}" border="0" style="cursor:pointer;">', actionName, image, text);
71  else
72  link += text;
73 
74  return link;
75  }
76 });
77 
78 /**
79  * @class wcmf.grid.SortAction. Action for sorting row items
80  */
81 wcmf.grid.SortAction = function(config) {
82  Ext.apply(this, config);
83  wcmf.grid.SortAction.superclass.constructor.call(this);
84 };
85 Ext.extend(wcmf.grid.SortAction, wcmf.grid.Action, {
86  width:30,
87 
88  getSupportedActions: function() {
89  return ['sortDown', 'sortUp'];
90  },
91 
92  performAction: function(actionName, record) {
93  // DATATYPE_IGNORE values
94  var ignoreValues = record.data.DATATYPE_IGNORE;
95  // sort up action
96  if (actionName == 'sortUp') {
97  Action.perform('sortup', {sortoid:record['id'], prevoid:ignoreValues['prevoid']}, this.grid.actionPerformed, this);
98  }
99  // sort down action
100  else if (actionName == 'sortDown') {
101  Action.perform('sortdown', {sortoid:record['id'], nextoid:ignoreValues['nextoid']}, this.grid.actionPerformed, this);
102  }
103  },
104 
105  renderer: function(v, p, record) {
106  var actionNav = '';
107  // DATATYPE_IGNORE values
108  var ignoreValues = record.data.DATATYPE_IGNORE;
109 
110  // sort up action
111  if (ignoreValues['hasSortUp'] && ignoreValues['hasSortUp'])
112  actionNav += wcmf.grid.Action.prototype.renderAction("sortUpAction", Message.get("Up"), "images/up.png");
113  else
114  actionNav += wcmf.grid.Action.prototype.renderAction("", Message.get("Up"), "images/up_grey.png");
115 
116  // sort down action
117  if (ignoreValues['hasSortDown'] && ignoreValues['hasSortDown'])
118  actionNav += wcmf.grid.Action.prototype.renderAction("sortDownAction", Message.get("Down"), "images/down.png");
119  else
120  actionNav += wcmf.grid.Action.prototype.renderAction("", Message.get("Down"), "images/down_grey.png");
121 
122  return '<span class="txtdefault">'+actionNav+'</span>';
123  }
124 });
125 
126 /**
127  * @class wcmf.grid.EditAction. Action for editing row items
128  */
129 wcmf.grid.EditAction = function(config) {
130  Ext.apply(this, config);
131  wcmf.grid.EditAction.superclass.constructor.call(this);
132 };
133 Ext.extend(wcmf.grid.EditAction, wcmf.grid.Action, {
134 
135  getSupportedActions: function() {
136  return ['edit'];
137  },
138 
139  performAction: function(actionName, record) {
140  // see if we have a real subject to use instead of record
141  var realSubject = record.data._properties.realSubject;
142  // edit action
143  if (realSubject) {
144  setContext(realSubject['type']); doDisplay(realSubject['oid']); submitAction('display');
145  }
146  else {
147  setContext(record.data._type); doDisplay(record['id']); submitAction('display');
148  }
149  },
150 
151  renderer: function(v, p, record) {
152  var actionNav = '';
153  // see if we have a real subject to use instead of record
154  var realSubject = record.data._properties.realSubject;
155 
156  // edit action
157  if (realSubject)
158  actionNav += wcmf.grid.Action.prototype.renderAction("editAction", Message.get("Edit %1%", [realSubject['oid']]), "images/edit.png");
159  else
160  actionNav += wcmf.grid.Action.prototype.renderAction("editAction", Message.get("Edit %1%", [record['id']]), "images/edit.png");
161 
162  return '<span class="txtdefault">'+actionNav+'</span>';
163  }
164 });
165 
166 /**
167  * @class wcmf.grid.DuplicateAction. Action for duplicating row items
168  */
169 wcmf.grid.DuplicateAction = function(config) {
170  Ext.apply(this, config);
171  wcmf.grid.DuplicateAction.superclass.constructor.call(this);
172 };
173 Ext.extend(wcmf.grid.DuplicateAction, wcmf.grid.Action, {
174 
175  getSupportedActions: function() {
176  return ['duplicate'];
177  },
178 
179  performAction: function(actionName, record) {
180  // duplicate action
181  var params = {oid:record['id'], oneCall:true};
182  if (this.grid.store.baseParams && this.grid.store.baseParams['poid'])
183  params.targetoid = this.grid.store.baseParams['poid'];
184  Action.perform('copy', params, this.grid.actionPerformed, this);
185  },
186 
187  renderer: function(v, p, record) {
188  var actionNav = '';
189 
190  // duplicate action
191  actionNav += wcmf.grid.Action.prototype.renderAction("duplicateAction", Message.get("Duplicate %1%", [record['id']]), "images/duplicate.png");
192 
193  return '<span class="txtdefault">'+actionNav+'</span>';
194  }
195 });
196 
197 /**
198  * @class wcmf.grid.DeleteAction. Action for deleting row items
199  */
200 wcmf.grid.DeleteAction = function(config) {
201  Ext.apply(this, config);
202  wcmf.grid.DeleteAction.superclass.constructor.call(this);
203 };
204 Ext.extend(wcmf.grid.DeleteAction, wcmf.grid.Action, {
205  width: 40,
206 
207  getSupportedActions: function() {
208  return ['delete', 'unlink'];
209  },
210 
211  performAction: function(actionName, record) {
212  // see if we have a real subject to use instead of record
213  var realSubject = record.data._properties.realSubject;
214  // delete action
215  if (actionName == 'delete') {
216  var _this = this;
217  var _grid = this.grid;
218  Ext.MessageBox.confirm(Message.get("Delete %1%", [record['id']]), Message.get("Really delete node %1%?", [record['id']]),
219  function(btn) {
220  if (btn == "yes") {
221  Action.perform('delete', {deleteoids:record['id']}, _grid.actionPerformed, _this);
222  }
223  });
224  }
225  // unlink action
226  else if (actionName == 'unlink') {
227  if (realSubject)
228  associateoid = realSubject['oid'];
229  else
230  associateoid = record['id'];
231  Action.perform('disassociate', {oid:record.data._properties.clientOID, associateoids:associateoid}, this.grid.actionPerformed, this);
232  }
233  },
234 
235  renderer: function(v, p, record) {
236  var actionNav = '';
237  // see if we have a real subject to use instead of record
238  var realSubject = record.data._properties.realSubject;
239 
240  // delete/unlink action
241  if (record.data._properties.composition == undefined || record.data._properties.composition == true)
242  actionNav += wcmf.grid.Action.prototype.renderAction("deleteAction", Message.get("Delete %1%", [record['id']]), "images/delete.png");
243  else {
244  if (realSubject || record.data._properties.aggregation == true) {
245  actionNav += wcmf.grid.Action.prototype.renderAction("unlinkAction", Message.get("Disassociate %1%", [record['id']]), "images/unlink.png");
246  actionNav += wcmf.grid.Action.prototype.renderAction("deleteAction", Message.get("Delete %1%", [record['id']]), "images/delete.png");
247  }
248  }
249 
250  return '<span class="txtdefault">'+actionNav+'</span>';
251  }
252 });
get($message, $parameters=null, $domain='', $lang='')
Use the Message class to output messages. You need not instantiate a Message object because the metho...