1 | // Sourced from:
|
---|
2 | // https://github.com/fossology/fossology
|
---|
3 |
|
---|
4 | /*
|
---|
5 | * File: jquery.dataTables.editable.js
|
---|
6 | * Version: 2.3.3.
|
---|
7 | * Author: Jovan Popovic
|
---|
8 | *
|
---|
9 | * Copyright 2010-2012 Jovan Popovic, all rights reserved.
|
---|
10 | *
|
---|
11 | * This source file is free software, under either the GPL v2 license or a
|
---|
12 | * BSD style license, as supplied with this software.
|
---|
13 | *
|
---|
14 | * This source file is distributed in the hope that it will be useful, but
|
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
---|
16 | * or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | *
|
---|
18 | * Parameters:
|
---|
19 | * @sUpdateURL String URL of the server-side page used for updating cell. Default value is "UpdateData".
|
---|
20 | * @sAddURL String URL of the server-side page used for adding new row. Default value is "AddData".
|
---|
21 | * @sDeleteURL String URL of the server-side page used to delete row by id. Default value is "DeleteData".
|
---|
22 | * @fnShowError Function function(message, action){...} used to show error message. Action value can be "update", "add" or "delete".
|
---|
23 | * @sAddNewRowFormId String Id of the form for adding new row. Default id is "formAddNewRow".
|
---|
24 | * @oAddNewRowFormOptions Object Options that will be set to the "Add new row" dialog
|
---|
25 | * @sAddNewRowButtonId String Id of the button for adding new row. Default id is "btnAddNewRow".
|
---|
26 | * @oAddNewRowButtonOptions Object Options that will be set to the "Add new" button
|
---|
27 | * @sAddNewRowOkButtonId String Id of the OK button placed in add new row dialog. Default value is "btnAddNewRowOk".
|
---|
28 | * @oAddNewRowOkButtonOptions Object Options that will be set to the Ok button in the "Add new row" form
|
---|
29 | * @sAddNewRowCancelButtonId String Id of the Cancel button placed in add new row dialog. Default value is "btnAddNewRowCancel".
|
---|
30 | * @oAddNewRowCancelButtonOptions Object Options that will be set to the Cancel button in the "Add new row" form
|
---|
31 | * @sDeleteRowButtonId String Id of the button for adding new row. Default id is "btnDeleteRow".
|
---|
32 | * @oDeleteRowButtonOptions Object Options that will be set to the Delete button
|
---|
33 | * @sSelectedRowClass String Class that will be associated to the selected row. Default class is "row_selected".
|
---|
34 | * @sReadOnlyCellClass String Class of the cells that should not be editable. Default value is "read_only".
|
---|
35 | * @sAddDeleteToolbarSelector String Selector used to identify place where add and delete buttons should be placed. Default value is ".add_delete_toolbar".
|
---|
36 | * @fnStartProcessingMode Function function(){...} called when AJAX call is started. Use this function to add "Please wait..." message when some button is pressed.
|
---|
37 | * @fnEndProcessingMode Function function(){...} called when AJAX call is ended. Use this function to close "Please wait..." message.
|
---|
38 | * @aoColumns Array Array of the JEditable settings that will be applied on the columns
|
---|
39 | * @sAddHttpMethod String Method used for the Add AJAX request (default is 'POST')
|
---|
40 | * @sAddDataType String Data type expected from the server when adding a row; allowed values are the same as those accepted by JQuery's "datatype" parameter, e.g. 'text' and 'json'. The default is 'text'.
|
---|
41 | * @sDeleteHttpMethod String Method used for the Delete AJAX request (default is 'POST')
|
---|
42 | * @sDeleteDataType String Data type expected from the server when deleting a row; allowed values are the same as those accepted by JQuery's "datatype" parameter, e.g. 'text' and 'json'. The default is 'text'.
|
---|
43 | * @fnOnDeleting Function function(tr, id, fnDeleteRow){...} Function called before row is deleted.
|
---|
44 | tr isJQuery object encapsulating row that will be deleted
|
---|
45 | id is an id of the record that will be deleted.
|
---|
46 | fnDeleteRow(id) callback function that should be called to delete row with id
|
---|
47 | returns true if plugin should continue with deleting row, false will abort delete.
|
---|
48 | * @fnOnDeleted Function function(status){...} Function called after delete action. Status can be "success" or "failure"
|
---|
49 | * @fnOnAdding Function function(){...} Function called before row is added.
|
---|
50 | returns true if plugin should continue with adding row, false will abort add.
|
---|
51 | * @fnOnNewRowPosted Function function(data) Function that can override default function that is called when server-side sAddURL returns result
|
---|
52 | You can use this function to add different behaviour when server-side page returns result
|
---|
53 | * @fnOnAdded Function function(status){...} Function called after add action. Status can be "success" or "failure"
|
---|
54 | * @fnOnEditing Function function(input){...} Function called before cell is updated.
|
---|
55 | input JQuery object wrapping the input element used for editing value in the cell.
|
---|
56 | returns true if plugin should continue with sending AJAX request, false will abort update.
|
---|
57 | * @fnOnEdited Function function(status){...} Function called after edit action. Status can be "success" or "failure"
|
---|
58 | * @sEditorHeight String Default height of the cell editors
|
---|
59 | * @sEditorWidth String Default width of the cell editors
|
---|
60 | * @oDeleteParameters Object Additonal objects added to the DELETE Ajax request
|
---|
61 | * @oUpdateParameters Object Additonal objects added to the UPDATE Ajax request
|
---|
62 | * @sIDToken String Token in the add new row dialog that will be replaced with a returned id of the record that is created eg DT_RowId
|
---|
63 | * @sSuccessResponse String Text returned from the server if record is successfully deleted or edited. Default "ok"
|
---|
64 | * @sFailureResponsePrefix String Prefix of the error message returned form the server during edit action
|
---|
65 | */
|
---|
66 | (function ($) {
|
---|
67 |
|
---|
68 | $.fn.makeEditable = function (options) {
|
---|
69 |
|
---|
70 | var iDisplayStart = 0;
|
---|
71 |
|
---|
72 | function fnGetCellID(cell) {
|
---|
73 | ///<summary>
|
---|
74 | ///Utility function used to determine id of the cell
|
---|
75 | ///By default it is assumed that id is placed as an id attribute of <tr> that that surround the cell (<td> tag). E.g.:
|
---|
76 | ///<tr id="17">
|
---|
77 | /// <td>...</td><td>...</td><td>...</td><td>...</td>
|
---|
78 | ///</tr>
|
---|
79 | ///</summary>
|
---|
80 | ///<param name="cell" type="DOM" domElement="true">TD cell refference</param>
|
---|
81 |
|
---|
82 | return properties.fnGetRowID($(cell.parentNode));
|
---|
83 | }
|
---|
84 |
|
---|
85 | function _fnSetRowIDInAttribute(row, id, overwrite) {
|
---|
86 | ///<summary>
|
---|
87 | ///Utility function used to set id of the row. Usually when a new record is created, added to the table,
|
---|
88 | ///and when id of the record is retrieved from the server-side.
|
---|
89 | ///It is assumed that id is placed as an id attribute of <tr> that that surround the cell (<td> tag). E.g.:
|
---|
90 | ///<tr id="17">
|
---|
91 | /// <td>...</td><td>...</td><td>...</td><td>...</td>
|
---|
92 | ///</tr>
|
---|
93 | ///This function is used when a datatable is configured in the server side processing mode or ajax source mode
|
---|
94 | ///</summary>
|
---|
95 | ///<param name="row" type="DOM" domElement="true">TR row where record is placed</param>
|
---|
96 |
|
---|
97 | if (overwrite) {
|
---|
98 | row.attr("id", id);
|
---|
99 | } else {
|
---|
100 | if (row.attr("id") == null || row.attr("id") == "") {
|
---|
101 | row.attr("id", id);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | function _fnGetRowIDFromAttribute(row) {
|
---|
107 | ///<summary>
|
---|
108 | ///Utility function used to get id of the row.
|
---|
109 | ///It is assumed that id is placed as an id attribute of <tr> that that surround the cell (<td> tag). E.g.:
|
---|
110 | ///<tr id="17">
|
---|
111 | /// <td>...</td><td>...</td><td>...</td><td>...</td>
|
---|
112 | ///</tr>
|
---|
113 | ///This function is used when a datatable is configured in the standard client side mode
|
---|
114 | ///</summary>
|
---|
115 | ///<param name="row" type="DOM" domElement="true">TR row where record is placed</param>
|
---|
116 | ///<returns type="Number">Id of the row - by default id attribute placed in the TR tag</returns>
|
---|
117 |
|
---|
118 | return row.attr("id");
|
---|
119 | }
|
---|
120 |
|
---|
121 | function _fnSetRowIDInFirstCell(row, id) {
|
---|
122 | ///<summary>
|
---|
123 | ///Utility function used to set id of the row. Usually when a new record is created, added to the table,
|
---|
124 | ///and when id of the record is retrieved from the server-side).
|
---|
125 | ///It is assumed that id is placed as a value of the first <TD> cell in the <TR>. As example:
|
---|
126 | ///<tr>
|
---|
127 | /// <td>17</td><td>...</td><td>...</td><td>...</td>
|
---|
128 | ///</tr>
|
---|
129 | ///This function is used when a datatable is configured in the server side processing mode or ajax source mode
|
---|
130 | ///</summary>
|
---|
131 | ///<param name="row" type="DOM" domElement="true">TR row where record is placed</param>
|
---|
132 |
|
---|
133 | $("td:first", row).html(id);
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | function _fnGetRowIDFromFirstCell(row) {
|
---|
138 | ///<summary>
|
---|
139 | ///Utility function used to get id of the row.
|
---|
140 | ///It is assumed that id is placed as a value of the first <TD> cell in the <TR>. As example:
|
---|
141 | ///<tr>
|
---|
142 | /// <td>17</td><td>...</td><td>...</td><td>...</td>
|
---|
143 | ///</tr>
|
---|
144 | ///This function is used when a datatable is configured in the server side processing mode or ajax source mode
|
---|
145 | ///</summary>
|
---|
146 | ///<param name="row" type="DOM" domElement="true">TR row where record is placed</param>
|
---|
147 | ///<returns type="Number">Id of the row - by default id attribute placed in the TR tag</returns>
|
---|
148 |
|
---|
149 | return $("td:first", row).html();
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 | //Reference to the DataTable object
|
---|
154 | var oTable;
|
---|
155 | //Refences to the buttons used for manipulating table data
|
---|
156 | var oAddNewRowButton, oDeleteRowButton, oConfirmRowAddingButton, oCancelRowAddingButton;
|
---|
157 | //Reference to the form used for adding new data
|
---|
158 | var oAddNewRowForm;
|
---|
159 |
|
---|
160 | //Plugin options
|
---|
161 | var properties;
|
---|
162 |
|
---|
163 | function _fnShowError(errorText, action) {
|
---|
164 | ///<summary>
|
---|
165 | ///Shows an error message (Default function)
|
---|
166 | ///</summary>
|
---|
167 | ///<param name="errorText" type="String">text that should be shown</param>
|
---|
168 | ///<param name="action" type="String"> action that was executed when error occured e.g. "update", "delete", or "add"</param>
|
---|
169 |
|
---|
170 | alert(errorText);
|
---|
171 | }
|
---|
172 |
|
---|
173 | function _fnStartProcessingMode() {
|
---|
174 | ///<summary>
|
---|
175 | ///Function that starts "Processing" mode i.e. shows "Processing..." dialog while some action is executing(Default function)
|
---|
176 | ///</summary>
|
---|
177 |
|
---|
178 | if (oTable.fnSettings().oFeatures.bProcessing) {
|
---|
179 | $(".dataTables_processing").css('visibility', 'visible');
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | function _fnEndProcessingMode() {
|
---|
184 | ///<summary>
|
---|
185 | ///Function that ends the "Processing" mode and returns the table in the normal state(Default function)
|
---|
186 | ///It shows processing message only if bProcessing setting is set to true
|
---|
187 | ///</summary>
|
---|
188 |
|
---|
189 | if (oTable.fnSettings().oFeatures.bProcessing) {
|
---|
190 | $(".dataTables_processing").css('visibility', 'hidden');
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | var sOldValue, sNewCellValue, sNewCellDislayValue;
|
---|
195 |
|
---|
196 | function fnApplyEditable(aoNodes) {
|
---|
197 | ///<summary>
|
---|
198 | ///Function that applies editable plugin to the array of table rows
|
---|
199 | ///</summary>
|
---|
200 | ///<param name="aoNodes" type="Array[TR]">Aray of table rows <TR> that should be initialized with editable plugin</param>
|
---|
201 |
|
---|
202 | if (properties.bDisableEditing) {
|
---|
203 | return;
|
---|
204 | }
|
---|
205 | var oDefaultEditableSettings = {
|
---|
206 | event: 'click',
|
---|
207 |
|
---|
208 | "onsubmit": function (settings, original) {
|
---|
209 | sOldValue = original.revert;
|
---|
210 | sNewCellValue = null;
|
---|
211 | sNewCellDisplayValue = null;
|
---|
212 | iDisplayStart = fnGetDisplayStart();
|
---|
213 |
|
---|
214 | if(settings.type == "text" || settings.type == "select" || settings.type == "textarea" )
|
---|
215 | {
|
---|
216 | var input = $("input,select,textarea", this);
|
---|
217 | sNewCellValue = $("input,select,textarea", $(this)).val();
|
---|
218 | if (input.length == 1) {
|
---|
219 | var oEditElement = input[0];
|
---|
220 | if (oEditElement.nodeName.toLowerCase() == "select" || oEditElement.tagName.toLowerCase() == "select") {
|
---|
221 | sNewCellDisplayValue = $("option:selected", oEditElement).text(); //For select list use selected text instead of value for displaying in table
|
---|
222 | } else {
|
---|
223 | sNewCellDisplayValue = sNewCellValue;
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | if (!properties.fnOnEditing(input, settings, original.revert, fnGetCellID(original))) {
|
---|
228 | return false;
|
---|
229 | }
|
---|
230 | var x = settings;
|
---|
231 |
|
---|
232 | //2.2.2 INLINE VALIDATION
|
---|
233 | if (settings.oValidationOptions != null) {
|
---|
234 | input.parents("form").validate(settings.oValidationOptions);
|
---|
235 | }
|
---|
236 | if (settings.cssclass != null) {
|
---|
237 | input.addClass(settings.cssclass);
|
---|
238 | }
|
---|
239 | if(settings.cssclass == null && settings.oValidationOptions == null){
|
---|
240 | return true;
|
---|
241 | }else{
|
---|
242 | if (!input.valid() || 0 == input.valid()) {
|
---|
243 | return false;
|
---|
244 | } else {
|
---|
245 | return true;
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | }
|
---|
250 |
|
---|
251 | properties.fnStartProcessingMode();
|
---|
252 | },
|
---|
253 | "submitdata": function (value, settings) {
|
---|
254 | //iDisplayStart = fnGetDisplayStart();
|
---|
255 | //properties.fnStartProcessingMode();
|
---|
256 | var id = fnGetCellID(this);
|
---|
257 | var rowId = oTable.fnGetPosition(this)[0];
|
---|
258 | var columnPosition = oTable.fnGetPosition(this)[1];
|
---|
259 | var columnId = oTable.fnGetPosition(this)[2];
|
---|
260 | var sColumnName = oTable.fnSettings().aoColumns[columnId].sName;
|
---|
261 | if (sColumnName == null || sColumnName == "") {
|
---|
262 | sColumnName = oTable.fnSettings().aoColumns[columnId].sTitle;
|
---|
263 | }
|
---|
264 | var updateData = null;
|
---|
265 | if (properties.aoColumns == null || properties.aoColumns[columnId] == null) {
|
---|
266 | updateData = $.extend({},
|
---|
267 | properties.oUpdateParameters,
|
---|
268 | {
|
---|
269 | "id": id,
|
---|
270 | "rowId": rowId,
|
---|
271 | "columnPosition": columnPosition,
|
---|
272 | "columnId": columnId,
|
---|
273 | "columnName": sColumnName
|
---|
274 | });
|
---|
275 | }
|
---|
276 | else {
|
---|
277 | updateData = $.extend({},
|
---|
278 | properties.oUpdateParameters,
|
---|
279 | properties.aoColumns[columnId].oUpdateParameters,
|
---|
280 | {
|
---|
281 | "id": id,
|
---|
282 | "rowId": rowId,
|
---|
283 | "columnPosition": columnPosition,
|
---|
284 | "columnId": columnId,
|
---|
285 | "columnName": sColumnName
|
---|
286 | });
|
---|
287 | }
|
---|
288 | return updateData;
|
---|
289 | },
|
---|
290 | "callback": function (sValue, settings) {
|
---|
291 | properties.fnEndProcessingMode();
|
---|
292 | var status = "";
|
---|
293 | var aPos = oTable.fnGetPosition(this);
|
---|
294 |
|
---|
295 | var bRefreshTable = !oSettings.oFeatures.bServerSide;
|
---|
296 | $("td.last-updated-cell", oTable.fnGetNodes( )).removeClass("last-updated-cell");
|
---|
297 | if(sValue.indexOf(properties.sFailureResponsePrefix)>-1)
|
---|
298 | {
|
---|
299 | oTable.fnUpdate(sOldValue, aPos[0], aPos[2], bRefreshTable);
|
---|
300 | $("td.last-updated-cell", oTable).removeClass("last-updated-cell");
|
---|
301 | $(this).addClass("last-updated-cell");
|
---|
302 | properties.fnShowError(sValue.replace(properties.sFailureResponsePrefix, "").trim(), "update");
|
---|
303 | status = "failure";
|
---|
304 | } else {
|
---|
305 |
|
---|
306 | if (properties.sSuccessResponse == "IGNORE" ||
|
---|
307 | ( properties.aoColumns != null
|
---|
308 | && properties.aoColumns[aPos[2]] != null
|
---|
309 | && properties.aoColumns[aPos[2]].sSuccessResponse == "IGNORE") ||
|
---|
310 | (sNewCellValue == null) || (sNewCellValue == sValue) ||
|
---|
311 | properties.sSuccessResponse == sValue) {
|
---|
312 | if(sNewCellDisplayValue == null)
|
---|
313 | {
|
---|
314 | //sNewCellDisplayValue = sValue;
|
---|
315 | oTable.fnUpdate(sValue, aPos[0], aPos[2], bRefreshTable);
|
---|
316 | }else{
|
---|
317 | oTable.fnUpdate(sNewCellDisplayValue, aPos[0], aPos[2], bRefreshTable);
|
---|
318 | }
|
---|
319 | $("td.last-updated-cell", oTable).removeClass("last-updated-cell");
|
---|
320 | $(this).addClass("last-updated-cell");
|
---|
321 | status = "success";
|
---|
322 | } else {
|
---|
323 | oTable.fnUpdate(sOldValue, aPos[0], aPos[2], bRefreshTable);
|
---|
324 | properties.fnShowError(sValue, "update");
|
---|
325 | status = "failure";
|
---|
326 | }
|
---|
327 | }
|
---|
328 |
|
---|
329 | properties.fnOnEdited(status, sOldValue, sNewCellDisplayValue, aPos[0], aPos[1], aPos[2]);
|
---|
330 | if (settings.fnOnCellUpdated != null) {
|
---|
331 | settings.fnOnCellUpdated(status, sValue, aPos[0], aPos[2], settings);
|
---|
332 | }
|
---|
333 |
|
---|
334 | fnSetDisplayStart();
|
---|
335 | if (properties.bUseKeyTable) {
|
---|
336 | var keys = oTable.keys;
|
---|
337 | /* Unblock KeyTable, but only after this 'esc' key event has finished. Otherwise
|
---|
338 | * it will 'esc' KeyTable as well
|
---|
339 | */
|
---|
340 | setTimeout(function () { keys.block = false; }, 0);
|
---|
341 | }
|
---|
342 | },
|
---|
343 | "onerror": function () {
|
---|
344 | properties.fnEndProcessingMode();
|
---|
345 | properties.fnShowError("Cell cannot be updated", "update");
|
---|
346 | properties.fnOnEdited("failure");
|
---|
347 | },
|
---|
348 |
|
---|
349 | "onreset": function(){
|
---|
350 | if (properties.bUseKeyTable) {
|
---|
351 | var keys = oTable.keys;
|
---|
352 | /* Unblock KeyTable, but only after this 'esc' key event has finished. Otherwise
|
---|
353 | * it will 'esc' KeyTable as well
|
---|
354 | */
|
---|
355 | setTimeout(function () { keys.block = false; }, 0);
|
---|
356 | }
|
---|
357 |
|
---|
358 | },
|
---|
359 | "height": properties.sEditorHeight,
|
---|
360 | "width": properties.sEditorWidth
|
---|
361 | };
|
---|
362 |
|
---|
363 | var cells = null;
|
---|
364 |
|
---|
365 | if (properties.aoColumns != null) {
|
---|
366 |
|
---|
367 | for (var iDTindex = 0, iDTEindex = 0; iDTindex < oSettings.aoColumns.length; iDTindex++) {
|
---|
368 | if (oSettings.aoColumns[iDTindex].bVisible) {//if DataTables column is visible
|
---|
369 | if (properties.aoColumns[iDTEindex] == null) {
|
---|
370 | //If editor for the column is not defined go to the next column
|
---|
371 | iDTEindex++;
|
---|
372 | continue;
|
---|
373 | }
|
---|
374 | //Get all cells in the iDTEindex column (nth child is 1-indexed array)
|
---|
375 | cells = $("td:nth-child(" + (iDTEindex + 1) + ")", aoNodes);
|
---|
376 |
|
---|
377 | var oColumnSettings = oDefaultEditableSettings;
|
---|
378 | oColumnSettings = $.extend({}, oDefaultEditableSettings, properties.oEditableSettings, properties.aoColumns[iDTEindex]);
|
---|
379 | iDTEindex++;
|
---|
380 | var sUpdateURL = properties.sUpdateURL;
|
---|
381 | try {
|
---|
382 | if (oColumnSettings.sUpdateURL != null) {
|
---|
383 | sUpdateURL = oColumnSettings.sUpdateURL;
|
---|
384 | }
|
---|
385 | } catch (ex) {
|
---|
386 | }
|
---|
387 | //cells.editable(sUpdateURL, oColumnSettings);
|
---|
388 | cells.each(function () {
|
---|
389 | if (!$(this).hasClass(properties.sReadOnlyCellClass)) {
|
---|
390 | $(this).editable(sUpdateURL, oColumnSettings);
|
---|
391 | }
|
---|
392 | });
|
---|
393 | }
|
---|
394 |
|
---|
395 | } //end for
|
---|
396 | } else {
|
---|
397 | cells = $('td:not(.' + properties.sReadOnlyCellClass + ')', aoNodes);
|
---|
398 | cells.editable(properties.sUpdateURL, $.extend({}, oDefaultEditableSettings, properties.oEditableSettings));
|
---|
399 | }
|
---|
400 | }
|
---|
401 |
|
---|
402 | function fnOnRowAdding(event) {
|
---|
403 | ///<summary>
|
---|
404 | ///Event handler called when a user click on the submit button in the "Add new row" form.
|
---|
405 | ///</summary>
|
---|
406 | ///<param name="event">Event that caused the action</param>
|
---|
407 |
|
---|
408 | if (properties.fnOnAdding()) {
|
---|
409 | if (oAddNewRowForm.valid()) {
|
---|
410 | iDisplayStart = fnGetDisplayStart();
|
---|
411 | properties.fnStartProcessingMode();
|
---|
412 |
|
---|
413 | if (properties.bUseFormsPlugin) {
|
---|
414 | //Still in beta(development)
|
---|
415 | $(oAddNewRowForm).ajaxSubmit({
|
---|
416 | dataType: 'xml',
|
---|
417 | success: function (response, statusString, xhr) {
|
---|
418 | if (xhr.responseText.toLowerCase().indexOf("error") != -1) {
|
---|
419 | properties.fnEndProcessingMode();
|
---|
420 | properties.fnShowError(xhr.responseText.replace("Error",""), "add");
|
---|
421 | properties.fnOnAdded("failure");
|
---|
422 | } else {
|
---|
423 | fnOnRowAdded(xhr.responseText);
|
---|
424 | }
|
---|
425 |
|
---|
426 | },
|
---|
427 | error: function (response) {
|
---|
428 | properties.fnEndProcessingMode();
|
---|
429 | properties.fnShowError(response.responseText, "add");
|
---|
430 | properties.fnOnAdded("failure");
|
---|
431 | }
|
---|
432 | }
|
---|
433 | );
|
---|
434 |
|
---|
435 | } else {
|
---|
436 |
|
---|
437 | var params = oAddNewRowForm.serialize();
|
---|
438 | $.ajax({ 'url': properties.sAddURL,
|
---|
439 | 'data': params,
|
---|
440 | 'type': properties.sAddHttpMethod,
|
---|
441 | 'dataType': properties.sAddDataType,
|
---|
442 | success: fnOnRowAdded,
|
---|
443 | error: function (response) {
|
---|
444 | properties.fnEndProcessingMode();
|
---|
445 | properties.fnShowError(response.responseText, "add");
|
---|
446 | properties.fnOnAdded("failure");
|
---|
447 | }
|
---|
448 | });
|
---|
449 | }
|
---|
450 | }
|
---|
451 | }
|
---|
452 | event.stopPropagation();
|
---|
453 | event.preventDefault();
|
---|
454 | }
|
---|
455 |
|
---|
456 | function _fnOnNewRowPosted(data) {
|
---|
457 | ///<summary>Callback function called BEFORE a new record is posted to the server</summary>
|
---|
458 | ///TODO: Check this
|
---|
459 |
|
---|
460 | return true;
|
---|
461 | }
|
---|
462 |
|
---|
463 |
|
---|
464 | function fnOnRowAdded(data) {
|
---|
465 | ///<summary>
|
---|
466 | ///Function that is called when a new row is added, and Ajax response is returned from server
|
---|
467 | /// This function takes data from the add form and adds them into the table.
|
---|
468 | ///</summary>
|
---|
469 | ///<param name="data" type="int">Id of the new row that is returned from the server</param>
|
---|
470 |
|
---|
471 | properties.fnEndProcessingMode();
|
---|
472 |
|
---|
473 | if (properties.fnOnNewRowPosted(data)) {
|
---|
474 |
|
---|
475 | var oSettings = oTable.fnSettings();
|
---|
476 | if (!oSettings.oFeatures.bServerSide) {
|
---|
477 | jQuery.data(oAddNewRowForm, 'DT_RowId', data);
|
---|
478 | var values = fnTakeRowDataFromFormElements(oAddNewRowForm);
|
---|
479 |
|
---|
480 |
|
---|
481 | var rtn;
|
---|
482 | //Add values from the form into the table
|
---|
483 | if (oSettings.aoColumns != null && isNaN(parseInt(oSettings.aoColumns[0].mDataProp))) {
|
---|
484 | rtn = oTable.fnAddData(rowData);
|
---|
485 | }
|
---|
486 | else {
|
---|
487 | rtn = oTable.fnAddData(values);
|
---|
488 | }
|
---|
489 |
|
---|
490 | var oTRAdded = oTable.fnGetNodes(rtn);
|
---|
491 | //add id returned by server page as an TR id attribute
|
---|
492 | properties.fnSetRowID($(oTRAdded), data, true);
|
---|
493 | //Apply editable plugin on the cells of the table
|
---|
494 | fnApplyEditable(oTRAdded);
|
---|
495 |
|
---|
496 | $("tr.last-added-row", oTable).removeClass("last-added-row");
|
---|
497 | $(oTRAdded).addClass("last-added-row");
|
---|
498 | } /*else {
|
---|
499 | oTable.fnDraw(false);
|
---|
500 | }*/
|
---|
501 | //Close the dialog
|
---|
502 | oAddNewRowForm.dialog('close');
|
---|
503 | $(oAddNewRowForm)[0].reset();
|
---|
504 | $(".error", $(oAddNewRowForm)).html("");
|
---|
505 |
|
---|
506 | fnSetDisplayStart();
|
---|
507 | properties.fnOnAdded("success");
|
---|
508 | if (properties.bUseKeyTable) {
|
---|
509 | var keys = oTable.keys;
|
---|
510 | /* Unblock KeyTable, but only after this 'esc' key event has finished. Otherwise
|
---|
511 | * it will 'esc' KeyTable as well
|
---|
512 | */
|
---|
513 | setTimeout(function () { keys.block = false; }, 0);
|
---|
514 | }
|
---|
515 | }
|
---|
516 | }
|
---|
517 |
|
---|
518 | function fnOnCancelRowAdding(event) {
|
---|
519 | ///<summary>
|
---|
520 | ///Event handler function that is executed when a user press cancel button in the add new row form
|
---|
521 | ///This function clean the add form and error messages if some of them are shown
|
---|
522 | ///</summary>
|
---|
523 | ///<param name="event" type="int">DOM event that caused an error</param>
|
---|
524 |
|
---|
525 | //Clear the validation messages and reset form
|
---|
526 | $(oAddNewRowForm).validate().resetForm(); // Clears the validation errors
|
---|
527 | $(oAddNewRowForm)[0].reset();
|
---|
528 |
|
---|
529 | $(".error", $(oAddNewRowForm)).html("");
|
---|
530 | $(".error", $(oAddNewRowForm)).hide(); // Hides the error element
|
---|
531 |
|
---|
532 | //Close the dialog
|
---|
533 | oAddNewRowForm.dialog('close');
|
---|
534 | event.stopPropagation();
|
---|
535 | event.preventDefault();
|
---|
536 | }
|
---|
537 |
|
---|
538 |
|
---|
539 | function fnDisableDeleteButton() {
|
---|
540 | ///<summary>
|
---|
541 | ///Function that disables delete button
|
---|
542 | ///</summary>
|
---|
543 |
|
---|
544 | if (properties.bUseKeyTable) {
|
---|
545 | return;
|
---|
546 | }
|
---|
547 | if (properties.oDeleteRowButtonOptions != null) {
|
---|
548 | //oDeleteRowButton.disable();
|
---|
549 | oDeleteRowButton.button("option", "disabled", true);
|
---|
550 | } else {
|
---|
551 | oDeleteRowButton.attr("disabled", "true");
|
---|
552 | }
|
---|
553 | }
|
---|
554 |
|
---|
555 | function fnEnableDeleteButton() {
|
---|
556 | ///<summary>
|
---|
557 | ///Function that enables delete button
|
---|
558 | ///</summary>
|
---|
559 |
|
---|
560 | if (properties.oDeleteRowButtonOptions != null) {
|
---|
561 | //oDeleteRowButton.enable();
|
---|
562 | oDeleteRowButton.button("option", "disabled", false);
|
---|
563 | } else {
|
---|
564 | oDeleteRowButton.removeAttr("disabled");
|
---|
565 | }
|
---|
566 | }
|
---|
567 |
|
---|
568 | var nSelectedRow, nSelectedCell;
|
---|
569 | var oKeyTablePosition;
|
---|
570 |
|
---|
571 |
|
---|
572 | function _fnOnRowDeleteInline(e) {
|
---|
573 |
|
---|
574 | var sURL = $(this).attr("href");
|
---|
575 | if (sURL == null || sURL == "") {
|
---|
576 | sURL = properties.sDeleteURL;
|
---|
577 | }
|
---|
578 |
|
---|
579 | e.preventDefault();
|
---|
580 | e.stopPropagation();
|
---|
581 |
|
---|
582 | iDisplayStart = fnGetDisplayStart();
|
---|
583 |
|
---|
584 | nSelectedCell = ($(this).parents('td'))[0];
|
---|
585 | jSelectedRow = ($(this).parents('tr'));
|
---|
586 | nSelectedRow = jSelectedRow[0];
|
---|
587 |
|
---|
588 | jSelectedRow.addClass(properties.sSelectedRowClass);
|
---|
589 |
|
---|
590 | var id = fnGetCellID(nSelectedCell);
|
---|
591 | if (properties.fnOnDeleting(jSelectedRow, id, fnDeleteRow)) {
|
---|
592 | fnDeleteRow(id, sURL);
|
---|
593 | }
|
---|
594 | }
|
---|
595 |
|
---|
596 |
|
---|
597 | function _fnOnRowDelete(event) {
|
---|
598 | ///<summary>
|
---|
599 | ///Event handler for the delete button
|
---|
600 | ///</summary>
|
---|
601 | ///<param name="event" type="Event">DOM event</param>
|
---|
602 |
|
---|
603 | event.preventDefault();
|
---|
604 | event.stopPropagation();
|
---|
605 |
|
---|
606 | iDisplayStart = fnGetDisplayStart();
|
---|
607 |
|
---|
608 | nSelectedRow = null;
|
---|
609 | nSelectedCell = null;
|
---|
610 |
|
---|
611 | if (!properties.bUseKeyTable) {
|
---|
612 | if ($('tr.' + properties.sSelectedRowClass + ' td', oTable).length == 0) {
|
---|
613 | //oDeleteRowButton.attr("disabled", "true");
|
---|
614 | _fnDisableDeleteButton();
|
---|
615 | return;
|
---|
616 | }
|
---|
617 | nSelectedCell = $('tr.' + properties.sSelectedRowClass + ' td', oTable)[0];
|
---|
618 | } else {
|
---|
619 | nSelectedCell = $('td.focus', oTable)[0];
|
---|
620 |
|
---|
621 | }
|
---|
622 | if (nSelectedCell == null) {
|
---|
623 | fnDisableDeleteButton();
|
---|
624 | return;
|
---|
625 | }
|
---|
626 | if (properties.bUseKeyTable) {
|
---|
627 | oKeyTablePosition = oTable.keys.fnGetCurrentPosition();
|
---|
628 | }
|
---|
629 | var id = fnGetCellID(nSelectedCell);
|
---|
630 | var jSelectedRow = $(nSelectedCell).parent("tr");
|
---|
631 | nSelectedRow = jSelectedRow[0];
|
---|
632 | if (properties.fnOnDeleting(jSelectedRow, id, fnDeleteRow)) {
|
---|
633 | fnDeleteRow(id);
|
---|
634 | }
|
---|
635 | }
|
---|
636 |
|
---|
637 | function _fnOnDeleting(tr, id, fnDeleteRow) {
|
---|
638 | ///<summary>
|
---|
639 | ///The default function that is called before row is deleted
|
---|
640 | ///Returning false will abort delete
|
---|
641 | ///Function can be overriden via plugin properties in order to create custom delete functionality
|
---|
642 | ///in that case call fnDeleteRow with parameter id, and return false to prevent double delete action
|
---|
643 | ///</summary>
|
---|
644 | ///<param name="tr" type="JQuery">JQuery wrapper around the TR tag that will be deleted</param>
|
---|
645 | ///<param name="id" type="String">Id of the record that wil be deleted</param>
|
---|
646 | ///<param name="fnDeleteRow" type="Function(id)">Function that will be called to delete a row. Default - fnDeleteRow(id)</param>
|
---|
647 |
|
---|
648 | return confirm("Are you sure that you want to delete this record?"); ;
|
---|
649 | }
|
---|
650 |
|
---|
651 |
|
---|
652 | function fnDeleteRow(id, sDeleteURL) {
|
---|
653 | ///<summary>
|
---|
654 | ///Function that deletes a row with an id, using the sDeleteURL server page
|
---|
655 | ///</summary>
|
---|
656 | ///<param name="id" type="int">Id of the row that will be deleted. Id value is placed in the attribute of the TR tag that will be deleted</param>
|
---|
657 | ///<param name="sDeleteURL" type="String">Server URL where delete request will be posted</param>
|
---|
658 |
|
---|
659 | var sURL = sDeleteURL;
|
---|
660 | if (sDeleteURL == null) {
|
---|
661 | sURL = properties.sDeleteURL;
|
---|
662 | }
|
---|
663 | properties.fnStartProcessingMode();
|
---|
664 | var data = $.extend(properties.oDeleteParameters, { "id": id });
|
---|
665 | $.ajax({ 'url': sURL,
|
---|
666 | 'type': properties.sDeleteHttpMethod,
|
---|
667 | 'data': data,
|
---|
668 | "success": fnOnRowDeleted,
|
---|
669 | "dataType": properties.sDeleteDataType,
|
---|
670 | "error": function (response) {
|
---|
671 | properties.fnEndProcessingMode();
|
---|
672 | properties.fnShowError(response.responseText, "delete");
|
---|
673 | properties.fnOnDeleted("failure");
|
---|
674 |
|
---|
675 | }
|
---|
676 | });
|
---|
677 | }
|
---|
678 |
|
---|
679 |
|
---|
680 |
|
---|
681 | function fnOnRowDeleted(response) {
|
---|
682 | ///<summary>
|
---|
683 | ///Called after the record is deleted on the server (in the ajax success callback)
|
---|
684 | ///</summary>
|
---|
685 | ///<param name="response" type="String">Response text eturned from the server-side page</param>
|
---|
686 |
|
---|
687 | properties.fnEndProcessingMode();
|
---|
688 | var oTRSelected = nSelectedRow;
|
---|
689 | /*
|
---|
690 | if (!properties.bUseKeyTable) {
|
---|
691 | oTRSelected = $('tr.' + properties.sSelectedRowClass, oTable)[0];
|
---|
692 | } else {
|
---|
693 | oTRSelected = $("td.focus", oTable)[0].parents("tr")[0];
|
---|
694 | }
|
---|
695 | */
|
---|
696 | if (response == properties.sSuccessResponse || response == "" || (response.success)) {
|
---|
697 | oTable.fnDeleteRow(oTRSelected);
|
---|
698 | fnDisableDeleteButton();
|
---|
699 | fnSetDisplayStart();
|
---|
700 | if (properties.bUseKeyTable) {
|
---|
701 | oTable.keys.fnSetPosition( oKeyTablePosition[0], oKeyTablePosition[1] );
|
---|
702 | }
|
---|
703 | properties.fnOnDeleted("success");
|
---|
704 | }
|
---|
705 | else {
|
---|
706 | properties.fnShowError(response, "delete");
|
---|
707 | properties.fnOnDeleted("failure");
|
---|
708 | }
|
---|
709 | }
|
---|
710 |
|
---|
711 |
|
---|
712 |
|
---|
713 | /* Function called after delete action
|
---|
714 | * @param result string
|
---|
715 | * "success" if row is actually deleted
|
---|
716 | * "failure" if delete failed
|
---|
717 | * @return void
|
---|
718 | */
|
---|
719 | function _fnOnDeleted(result) { }
|
---|
720 |
|
---|
721 | function _fnOnEditing(input) { return true; }
|
---|
722 | function _fnOnEdited(result, sOldValue, sNewValue, iRowIndex, iColumnIndex, iRealColumnIndex) {
|
---|
723 |
|
---|
724 | }
|
---|
725 |
|
---|
726 | function fnOnAdding() { return true; }
|
---|
727 | function _fnOnAdded(result) { }
|
---|
728 |
|
---|
729 | var oSettings;
|
---|
730 | function fnGetDisplayStart() {
|
---|
731 | return oSettings._iDisplayStart;
|
---|
732 | }
|
---|
733 |
|
---|
734 | function fnSetDisplayStart() {
|
---|
735 | ///<summary>
|
---|
736 | ///Set the pagination position(do nothing in the server-side mode)
|
---|
737 | ///</summary>
|
---|
738 |
|
---|
739 | //To refresh table with preserver pagination on cell edit
|
---|
740 | //if (oSettings.oFeatures.bServerSide === false) {
|
---|
741 | oSettings._iDisplayStart = iDisplayStart;
|
---|
742 | oSettings.oApi._fnCalculateEnd(oSettings);
|
---|
743 | //draw the 'current' page
|
---|
744 | oSettings.oApi._fnDraw(oSettings);
|
---|
745 | //}
|
---|
746 | }
|
---|
747 |
|
---|
748 | function _fnOnBeforeAction(sAction) {
|
---|
749 | return true;
|
---|
750 | }
|
---|
751 |
|
---|
752 | function _fnOnActionCompleted(sStatus) {
|
---|
753 |
|
---|
754 | }
|
---|
755 |
|
---|
756 | function fnGetActionSettings(sAction) {
|
---|
757 | ///<summary>Returns settings object for the action</summary>
|
---|
758 | ///<param name="sAction" type="String">The name of the action</param>
|
---|
759 |
|
---|
760 | if (properties.aoTableAction) {
|
---|
761 | properties.fnShowError("Configuration error - aoTableAction setting are not set", sAction);
|
---|
762 | }
|
---|
763 | var i = 0;
|
---|
764 |
|
---|
765 | for (i = 0; i < properties.aoTableActions.length; i++) {
|
---|
766 | if (properties.aoTableActions[i].sAction == sAction) {
|
---|
767 | return properties.aoTableActions[i];
|
---|
768 | }
|
---|
769 | }
|
---|
770 |
|
---|
771 | properties.fnShowError("Cannot find action configuration settings", sAction);
|
---|
772 | }
|
---|
773 |
|
---|
774 |
|
---|
775 | function fnPopulateFormWithRowCells(oForm, oTR) {
|
---|
776 | ///<summary>Populates forms with row data</summary>
|
---|
777 | ///<param name="oForm" type="DOM">Form used to enter data</param>
|
---|
778 | ///<param name="oTR" type="DOM">Table Row that will populate data</param>
|
---|
779 |
|
---|
780 | var iRowID = oTable.fnGetPosition(oTR);
|
---|
781 |
|
---|
782 | var id = properties.fnGetRowID($(oTR));
|
---|
783 |
|
---|
784 | $(oForm).validate().resetForm();
|
---|
785 | jQuery.data($(oForm)[0], 'DT_RowId', id);
|
---|
786 | $("input.DT_RowId", $(oForm)).val(id);
|
---|
787 | jQuery.data($(oForm)[0], 'ROWID', iRowID);
|
---|
788 | $("input.ROWID", $(oForm)).val(iRowID);
|
---|
789 |
|
---|
790 |
|
---|
791 | var oSettings = oTable.fnSettings();
|
---|
792 | var iColumnCount = oSettings.aoColumns.length;
|
---|
793 |
|
---|
794 |
|
---|
795 | $("input:text[rel],input:radio[rel][checked],input:hidden[rel],select[rel],textarea[rel],input:checkbox[rel]",
|
---|
796 | $(oForm)).each(function () {
|
---|
797 | var rel = $(this).attr("rel");
|
---|
798 |
|
---|
799 | if (rel >= iColumnCount) {
|
---|
800 | properties.fnShowError("In the form is placed input element with the name '" + $(this).attr("name") + "' with the 'rel' attribute that must be less than a column count - " + iColumnCount, "action");
|
---|
801 | } else {
|
---|
802 | var sCellValue = oTable.fnGetData(oTR)[rel];
|
---|
803 | if (this.nodeName.toLowerCase() == "select" || this.tagName.toLowerCase() == "select") {
|
---|
804 |
|
---|
805 | if (this.multiple == true) {
|
---|
806 | var aoSelectedValue = new Array();
|
---|
807 | aoCellValues = sCellValue.split(",");
|
---|
808 | for (i = 0; i <= this.options.length - 1; i++) {
|
---|
809 | if (jQuery.inArray(this.options[i].text.toLowerCase().trim(), aoCellValues) != -1) {
|
---|
810 | aoSelectedValue.push(this.options[i].value);
|
---|
811 | }
|
---|
812 | }
|
---|
813 | $(this).val(aoSelectedValue);
|
---|
814 | } else {
|
---|
815 | for (i = 0; i <= this.options.length - 1; i++) {
|
---|
816 | if (this.options[i].text.toLowerCase() == sCellValue.toLowerCase()) {
|
---|
817 | $(this).val(this.options[i].value);
|
---|
818 | }
|
---|
819 | }
|
---|
820 | }
|
---|
821 |
|
---|
822 | }
|
---|
823 | else if (this.nodeName.toLowerCase() == "span" || this.tagName.toLowerCase() == "span") {
|
---|
824 | $(this).html(sCellValue);
|
---|
825 | } else {
|
---|
826 | if (this.type == "checkbox") {
|
---|
827 | if (sCellValue == "true") {
|
---|
828 | $(this).attr("checked", true);
|
---|
829 | }
|
---|
830 | } else {
|
---|
831 | if (this.type == "radio") {
|
---|
832 | if (this.value == sCellValue) {
|
---|
833 | this.checked = true;
|
---|
834 | }
|
---|
835 | } else {
|
---|
836 | this.value = sCellValue;
|
---|
837 | }
|
---|
838 | }
|
---|
839 | }
|
---|
840 |
|
---|
841 | //sCellValue = sCellValue.replace(properties.sIDToken, data);
|
---|
842 | //values[rel] = sCellValue;
|
---|
843 | //oTable.fnUpdate(sCellValue, iRowID, rel);
|
---|
844 | }
|
---|
845 | });
|
---|
846 |
|
---|
847 |
|
---|
848 |
|
---|
849 | } //End function fnPopulateFormWithRowCells
|
---|
850 |
|
---|
851 | function fnTakeRowDataFromFormElements(oForm) {
|
---|
852 | ///<summary>Populates row with form elements(This should be nly function that read fom elements from form)</summary>
|
---|
853 | ///<param name="iRowID" type="DOM">DatabaseRowID</param>
|
---|
854 | ///<param name="oForm" type="DOM">Form used to enter data</param>
|
---|
855 | ///<returns>Object or array</returns>
|
---|
856 |
|
---|
857 | var iDT_RowId = jQuery.data(oForm, 'DT_RowId');
|
---|
858 | var iColumnCount = oSettings.aoColumns.length;
|
---|
859 |
|
---|
860 | var values = new Array();
|
---|
861 | var rowData = new Object();
|
---|
862 |
|
---|
863 | $("input:text[rel],input:radio[rel][checked],input:hidden[rel],select[rel],textarea[rel],span.datafield[rel],input:checkbox[rel]", oForm).each(function () {
|
---|
864 | var rel = $(this).attr("rel");
|
---|
865 | var sCellValue = "";
|
---|
866 | if (rel >= iColumnCount) {
|
---|
867 | properties.fnShowError("In the add form is placed input element with the name '" + $(this).attr("name") + "' with the 'rel' attribute that must be less than a column count - " + iColumnCount, "add");
|
---|
868 | } else {
|
---|
869 | if (this.nodeName.toLowerCase() == "select" || this.tagName.toLowerCase() == "select") {
|
---|
870 | //sCellValue = $("option:selected", this).text();
|
---|
871 | sCellValue = $.map(
|
---|
872 | $.makeArray($("option:selected", this)),
|
---|
873 | function (n, i) {
|
---|
874 | return $(n).text();
|
---|
875 | }).join(",");
|
---|
876 | }
|
---|
877 | else if (this.nodeName.toLowerCase() == "span" || this.tagName.toLowerCase() == "span") {
|
---|
878 | sCellValue = $(this).html();
|
---|
879 | } else {
|
---|
880 | if (this.type == "checkbox") {
|
---|
881 | if (this.checked) {
|
---|
882 | sCellValue = (this.value != "on") ? this.value : "true";
|
---|
883 | } else {
|
---|
884 | sCellValue = (this.value != "on") ? "" : "false";
|
---|
885 | }
|
---|
886 | } else {
|
---|
887 | sCellValue = this.value;
|
---|
888 | }
|
---|
889 | }
|
---|
890 | //Deprecated
|
---|
891 | sCellValue = sCellValue.replace("DATAROWID", iDT_RowId);
|
---|
892 | sCellValue = sCellValue.replace(properties.sIDToken, iDT_RowId);
|
---|
893 | if (oSettings.aoColumns != null
|
---|
894 | && oSettings.aoColumns[rel] != null
|
---|
895 | && isNaN(parseInt(oSettings.aoColumns[0].mDataProp))) {
|
---|
896 | rowData[oSettings.aoColumns[rel].mDataProp] = sCellValue;
|
---|
897 | } else {
|
---|
898 | values[rel] = sCellValue;
|
---|
899 | }
|
---|
900 | }
|
---|
901 | });
|
---|
902 |
|
---|
903 | if (oSettings.aoColumns != null && isNaN(parseInt(oSettings.aoColumns[0].mDataProp))) {
|
---|
904 | return rowData;
|
---|
905 | }
|
---|
906 | else {
|
---|
907 | return values;
|
---|
908 | }
|
---|
909 |
|
---|
910 |
|
---|
911 | } //End function fnPopulateRowWithFormElements
|
---|
912 |
|
---|
913 |
|
---|
914 |
|
---|
915 |
|
---|
916 | function fnSendFormUpdateRequest(nActionForm) {
|
---|
917 | ///<summary>Updates table row using form fields</summary>
|
---|
918 | ///<param name="nActionForm" type="DOM">Form used to enter data</param>
|
---|
919 |
|
---|
920 | var jActionForm = $(nActionForm);
|
---|
921 | var sAction = jActionForm.attr("id");
|
---|
922 |
|
---|
923 | sAction = sAction.replace("form", "");
|
---|
924 | var sActionURL = jActionForm.attr("action");
|
---|
925 | if (properties.fnOnBeforeAction(sAction)) {
|
---|
926 | if (jActionForm.valid()) {
|
---|
927 | iDisplayStart = fnGetDisplayStart();
|
---|
928 | properties.fnStartProcessingMode();
|
---|
929 | if (properties.bUseFormsPlugin) {
|
---|
930 |
|
---|
931 | //Still in beta(development)
|
---|
932 | var oAjaxSubmitOptions = {
|
---|
933 | success: function (response, statusString, xhr) {
|
---|
934 | properties.fnEndProcessingMode();
|
---|
935 | if (response.toLowerCase().indexOf("error") != -1 || statusString != "success") {
|
---|
936 | properties.fnShowError(response, sAction);
|
---|
937 | properties.fnOnActionCompleted("failure");
|
---|
938 | } else {
|
---|
939 | fnUpdateRowOnSuccess(nActionForm);
|
---|
940 | properties.fnOnActionCompleted("success");
|
---|
941 | }
|
---|
942 |
|
---|
943 | },
|
---|
944 | error: function (response) {
|
---|
945 | properties.fnEndProcessingMode();
|
---|
946 | properties.fnShowError(response.responseText, sAction);
|
---|
947 | properties.fnOnActionCompleted("failure");
|
---|
948 | }
|
---|
949 | };
|
---|
950 | var oActionSettings = fnGetActionSettings(sAction);
|
---|
951 | oAjaxSubmitOptions = $.extend({}, properties.oAjaxSubmitOptions, oAjaxSubmitOptions);
|
---|
952 | $(oActionForm).ajaxSubmit(oAjaxSubmitOptions);
|
---|
953 |
|
---|
954 | } else {
|
---|
955 | var params = jActionForm.serialize();
|
---|
956 | $.ajax({ 'url': sActionURL,
|
---|
957 | 'data': params,
|
---|
958 | 'type': properties.sAddHttpMethod,
|
---|
959 | 'dataType': properties.sAddDataType,
|
---|
960 | success: function (response) {
|
---|
961 | properties.fnEndProcessingMode();
|
---|
962 | fnUpdateRowOnSuccess(nActionForm);
|
---|
963 | properties.fnOnActionCompleted("success");
|
---|
964 | },
|
---|
965 | error: function (response) {
|
---|
966 | properties.fnEndProcessingMode();
|
---|
967 | properties.fnShowError(response.responseText, sAction);
|
---|
968 | properties.fnOnActionCompleted("failure");
|
---|
969 | }
|
---|
970 | });
|
---|
971 | }
|
---|
972 | }
|
---|
973 | }
|
---|
974 | }
|
---|
975 |
|
---|
976 | function fnUpdateRowOnSuccess(nActionForm) {
|
---|
977 | ///<summary>Updates table row using form fields after the ajax success callback is executed</summary>
|
---|
978 | ///<param name="nActionForm" type="DOM">Form used to enter data</param>
|
---|
979 |
|
---|
980 | var values = fnTakeRowDataFromFormElements(nActionForm);
|
---|
981 |
|
---|
982 | var iRowID = jQuery.data(nActionForm, 'ROWID');
|
---|
983 | var oSettings = oTable.fnSettings();
|
---|
984 | var iColumnCount = oSettings.aoColumns.length;
|
---|
985 | for (var rel = 0; rel < iColumnCount; rel++) {
|
---|
986 | if (oSettings.aoColumns != null
|
---|
987 | && oSettings.aoColumns[rel] != null
|
---|
988 | && isNaN(parseInt(oSettings.aoColumns[0].mDataProp))) {
|
---|
989 | sCellValue = rowData[oSettings.aoColumns[rel].mDataProp];
|
---|
990 | } else {
|
---|
991 | sCellValue = values[rel];
|
---|
992 | }
|
---|
993 | if (sCellValue != undefined) {
|
---|
994 | oTable.fnUpdate(sCellValue, iRowID, rel);
|
---|
995 | }
|
---|
996 | }
|
---|
997 |
|
---|
998 | fnSetDisplayStart();
|
---|
999 | $(nActionForm).dialog('close');
|
---|
1000 | return;
|
---|
1001 |
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 |
|
---|
1005 | oTable = this;
|
---|
1006 |
|
---|
1007 | var defaults = {
|
---|
1008 |
|
---|
1009 | sUpdateURL: "UpdateData",
|
---|
1010 | sAddURL: "AddData",
|
---|
1011 | sDeleteURL: "DeleteData",
|
---|
1012 | sAddNewRowFormId: "formAddNewRow",
|
---|
1013 | oAddNewRowFormOptions: { autoOpen: false, modal: true },
|
---|
1014 | sAddNewRowButtonId: "btnAddNewRow",
|
---|
1015 | oAddNewRowButtonOptions: null,
|
---|
1016 | sAddNewRowOkButtonId: "btnAddNewRowOk",
|
---|
1017 | sAddNewRowCancelButtonId: "btnAddNewRowCancel",
|
---|
1018 | oAddNewRowOkButtonOptions: { label: "Ok" },
|
---|
1019 | oAddNewRowCancelButtonOptions: { label: "Cancel" },
|
---|
1020 | sDeleteRowButtonId: "btnDeleteRow",
|
---|
1021 | oDeleteRowButtonOptions: null,
|
---|
1022 | sSelectedRowClass: "row_selected",
|
---|
1023 | sReadOnlyCellClass: "read_only",
|
---|
1024 | sAddDeleteToolbarSelector: ".add_delete_toolbar",
|
---|
1025 | fnShowError: _fnShowError,
|
---|
1026 | fnStartProcessingMode: _fnStartProcessingMode,
|
---|
1027 | fnEndProcessingMode: _fnEndProcessingMode,
|
---|
1028 | aoColumns: null,
|
---|
1029 | fnOnDeleting: _fnOnDeleting,
|
---|
1030 | fnOnDeleted: _fnOnDeleted,
|
---|
1031 | fnOnAdding: fnOnAdding,
|
---|
1032 | fnOnNewRowPosted: _fnOnNewRowPosted,
|
---|
1033 | fnOnAdded: _fnOnAdded,
|
---|
1034 | fnOnEditing: _fnOnEditing,
|
---|
1035 | fnOnEdited: _fnOnEdited,
|
---|
1036 | sAddHttpMethod: 'POST',
|
---|
1037 | sAddDataType: "text",
|
---|
1038 | sDeleteHttpMethod: 'POST',
|
---|
1039 | sDeleteDataType: "text",
|
---|
1040 | fnGetRowID: _fnGetRowIDFromAttribute,
|
---|
1041 | fnSetRowID: _fnSetRowIDInAttribute,
|
---|
1042 | sEditorHeight: "100%",
|
---|
1043 | sEditorWidth: "100%",
|
---|
1044 | bDisableEditing: false,
|
---|
1045 | oDeleteParameters: {},
|
---|
1046 | oUpdateParameters: {},
|
---|
1047 | sIDToken: "DT_RowId",
|
---|
1048 | aoTableActions: null,
|
---|
1049 | fnOnBeforeAction: _fnOnBeforeAction,
|
---|
1050 | bUseFormsPlugin: false,
|
---|
1051 | fnOnActionCompleted: _fnOnActionCompleted,
|
---|
1052 | sSuccessResponse: "ok",
|
---|
1053 | sFailureResponsePrefix: "ERROR",
|
---|
1054 | oKeyTable: null //KEYTABLE
|
---|
1055 |
|
---|
1056 | };
|
---|
1057 |
|
---|
1058 | properties = $.extend(defaults, options);
|
---|
1059 | oSettings = oTable.fnSettings();
|
---|
1060 | properties.bUseKeyTable = (properties.oKeyTable != null);
|
---|
1061 |
|
---|
1062 | return this.each(function () {
|
---|
1063 | var sTableId = oTable.dataTableSettings[0].sTableId;
|
---|
1064 | //KEYTABLE
|
---|
1065 | if (properties.bUseKeyTable) {
|
---|
1066 | var keys = new KeyTable({
|
---|
1067 | "table": document.getElementById(sTableId),
|
---|
1068 | "datatable": oTable
|
---|
1069 | });
|
---|
1070 | oTable.keys = keys;
|
---|
1071 |
|
---|
1072 | /* Apply a return key event to each cell in the table */
|
---|
1073 | keys.event.action(null, null, function (nCell) {
|
---|
1074 | if( $(nCell).hasClass(properties.sReadOnlyCellClass)) {
|
---|
1075 | return;
|
---|
1076 | }
|
---|
1077 | /* Block KeyTable from performing any events while jEditable is in edit mode */
|
---|
1078 | keys.block = true;
|
---|
1079 | /* Dispatch click event to go into edit mode - Saf 4 needs a timeout... */
|
---|
1080 | setTimeout(function () { $(nCell).dblclick(); }, 0);
|
---|
1081 | //properties.bDisableEditing = true;
|
---|
1082 | });
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 |
|
---|
1086 |
|
---|
1087 |
|
---|
1088 |
|
---|
1089 |
|
---|
1090 | //KEYTABLE
|
---|
1091 |
|
---|
1092 | if (oTable.fnSettings().sAjaxSource != null) {
|
---|
1093 | oTable.fnSettings().aoDrawCallback.push({
|
---|
1094 | "fn": function () {
|
---|
1095 | //Apply jEditable plugin on the table cells
|
---|
1096 | fnApplyEditable(oTable.fnGetNodes());
|
---|
1097 | $(oTable.fnGetNodes()).each(function () {
|
---|
1098 | var position = oTable.fnGetPosition(this);
|
---|
1099 | var id = oTable.fnGetData(position)[0];
|
---|
1100 | properties.fnSetRowID($(this), id);
|
---|
1101 | }
|
---|
1102 | );
|
---|
1103 | },
|
---|
1104 | "sName": "fnApplyEditable"
|
---|
1105 | });
|
---|
1106 |
|
---|
1107 | } else {
|
---|
1108 | //Apply jEditable plugin on the table cells
|
---|
1109 | fnApplyEditable(oTable.fnGetNodes());
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | //Setup form to open in dialog
|
---|
1113 | oAddNewRowForm = $("#" + properties.sAddNewRowFormId);
|
---|
1114 |
|
---|
1115 | if (oAddNewRowForm.length != 0) {
|
---|
1116 |
|
---|
1117 | ///Check does the add new form has all nessecary fields
|
---|
1118 | var oSettings = oTable.fnSettings();
|
---|
1119 | var iColumnCount = oSettings.aoColumns.length;
|
---|
1120 | for (i = 0; i < iColumnCount; i++) {
|
---|
1121 | if ($("[rel=" + i + "]", oAddNewRowForm).length == 0) {
|
---|
1122 | properties.fnShowError("In the form that is used for adding new records cannot be found an input element with rel=" + i + " that will be bound to the value in the column " + i + ". See http://code.google.com/p/jquery-datatables-editable/wiki/AddingNewRecords#Add_new_record_form for more details", "init");
|
---|
1123 | }
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 |
|
---|
1127 | if (properties.oAddNewRowFormOptions != null) {
|
---|
1128 | properties.oAddNewRowFormOptions.autoOpen = false;
|
---|
1129 | } else {
|
---|
1130 | properties.oAddNewRowFormOptions = { autoOpen: false };
|
---|
1131 | }
|
---|
1132 | oAddNewRowForm.dialog(properties.oAddNewRowFormOptions);
|
---|
1133 |
|
---|
1134 | //Add button click handler on the "Add new row" button
|
---|
1135 | oAddNewRowButton = $("#" + properties.sAddNewRowButtonId);
|
---|
1136 | if (oAddNewRowButton.length != 0) {
|
---|
1137 |
|
---|
1138 | if(oAddNewRowButton.data("add-event-attached")!="true")
|
---|
1139 | {
|
---|
1140 | oAddNewRowButton.click(function () {
|
---|
1141 | oAddNewRowForm.dialog('open');
|
---|
1142 | });
|
---|
1143 | oAddNewRowButton.data("add-event-attached", "true");
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | } else {
|
---|
1147 | if ($(properties.sAddDeleteToolbarSelector).length == 0) {
|
---|
1148 | throw "Cannot find a button with an id '" + properties.sAddNewRowButtonId + "', or placeholder with an id '" + properties.sAddDeleteToolbarSelector + "' that should be used for adding new row although form for adding new record is specified";
|
---|
1149 | } else {
|
---|
1150 | oAddNewRowButton = null; //It will be auto-generated later
|
---|
1151 | }
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | //Prevent Submit handler
|
---|
1155 | if (oAddNewRowForm[0].nodeName.toLowerCase() == "form") {
|
---|
1156 | oAddNewRowForm.unbind('submit');
|
---|
1157 | oAddNewRowForm.submit(function (event) {
|
---|
1158 | fnOnRowAdding(event);
|
---|
1159 | return false;
|
---|
1160 | });
|
---|
1161 | } else {
|
---|
1162 | $("form", oAddNewRowForm[0]).unbind('submit');
|
---|
1163 | $("form", oAddNewRowForm[0]).submit(function (event) {
|
---|
1164 | fnOnRowAdding(event);
|
---|
1165 | return false;
|
---|
1166 | });
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | // array to add default buttons to
|
---|
1170 | var aAddNewRowFormButtons = [];
|
---|
1171 |
|
---|
1172 | oConfirmRowAddingButton = $("#" + properties.sAddNewRowOkButtonId, oAddNewRowForm);
|
---|
1173 | if (oConfirmRowAddingButton.length == 0) {
|
---|
1174 | //If someone forgotten to set the button text
|
---|
1175 | if (properties.oAddNewRowOkButtonOptions.text == null
|
---|
1176 | || properties.oAddNewRowOkButtonOptions.text == "") {
|
---|
1177 | properties.oAddNewRowOkButtonOptions.text = "Ok";
|
---|
1178 | }
|
---|
1179 | properties.oAddNewRowOkButtonOptions.click = fnOnRowAdding;
|
---|
1180 | properties.oAddNewRowOkButtonOptions.id = properties.sAddNewRowOkButtonId;
|
---|
1181 | // push the add button onto the array
|
---|
1182 | aAddNewRowFormButtons.push(properties.oAddNewRowOkButtonOptions);
|
---|
1183 | } else {
|
---|
1184 | oConfirmRowAddingButton.click(fnOnRowAdding);
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 | oCancelRowAddingButton = $("#" + properties.sAddNewRowCancelButtonId);
|
---|
1188 | if (oCancelRowAddingButton.length == 0) {
|
---|
1189 | //If someone forgotten to the button text
|
---|
1190 | if (properties.oAddNewRowCancelButtonOptions.text == null
|
---|
1191 | || properties.oAddNewRowCancelButtonOptions.text == "") {
|
---|
1192 | properties.oAddNewRowCancelButtonOptions.text = "Cancel";
|
---|
1193 | }
|
---|
1194 | properties.oAddNewRowCancelButtonOptions.click = fnOnCancelRowAdding;
|
---|
1195 | properties.oAddNewRowCancelButtonOptions.id = properties.sAddNewRowCancelButtonId;
|
---|
1196 | // push the cancel button onto the array
|
---|
1197 | aAddNewRowFormButtons.push(properties.oAddNewRowCancelButtonOptions);
|
---|
1198 | } else {
|
---|
1199 | oCancelRowAddingButton.click(fnOnCancelRowAdding);
|
---|
1200 | }
|
---|
1201 | // if the array contains elements, add them to the dialog
|
---|
1202 | if (aAddNewRowFormButtons.length > 0) {
|
---|
1203 | oAddNewRowForm.dialog('option', 'buttons', aAddNewRowFormButtons);
|
---|
1204 | }
|
---|
1205 | //Issue: It cannot find it with this call:
|
---|
1206 | //oConfirmRowAddingButton = $("#" + properties.sAddNewRowOkButtonId, oAddNewRowForm);
|
---|
1207 | //oCancelRowAddingButton = $("#" + properties.sAddNewRowCancelButtonId, oAddNewRowForm);
|
---|
1208 | oConfirmRowAddingButton = $("#" + properties.sAddNewRowOkButtonId);
|
---|
1209 | oCancelRowAddingButton = $("#" + properties.sAddNewRowCancelButtonId);
|
---|
1210 |
|
---|
1211 | if (properties.oAddNewRowFormValidation != null) {
|
---|
1212 | oAddNewRowForm.validate(properties.oAddNewRowFormValidation);
|
---|
1213 | }
|
---|
1214 | } else {
|
---|
1215 | oAddNewRowForm = null;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | //Set the click handler on the "Delete selected row" button
|
---|
1219 | oDeleteRowButton = $('#' + properties.sDeleteRowButtonId);
|
---|
1220 | if (oDeleteRowButton.length != 0)
|
---|
1221 | {
|
---|
1222 | if(oDeleteRowButton.data("delete-event-attached")!="true")
|
---|
1223 | {
|
---|
1224 | oDeleteRowButton.click(_fnOnRowDelete);
|
---|
1225 | oDeleteRowButton.data("delete-event-attached", "true");
|
---|
1226 | }
|
---|
1227 | }
|
---|
1228 | else {
|
---|
1229 | oDeleteRowButton = null;
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | //If an add and delete buttons does not exists but Add-delete toolbar is specificed
|
---|
1233 | //Autogenerate these buttons
|
---|
1234 | oAddDeleteToolbar = $(properties.sAddDeleteToolbarSelector);
|
---|
1235 | if (oAddDeleteToolbar.length != 0) {
|
---|
1236 | if (oAddNewRowButton == null && properties.sAddNewRowButtonId != ""
|
---|
1237 | && oAddNewRowForm != null) {
|
---|
1238 | oAddDeleteToolbar.append("<button id='" + properties.sAddNewRowButtonId + "' class='add_row'>Add</button>");
|
---|
1239 | oAddNewRowButton = $("#" + properties.sAddNewRowButtonId);
|
---|
1240 | oAddNewRowButton.click(function () { oAddNewRowForm.dialog('open'); });
|
---|
1241 | }
|
---|
1242 | if (oDeleteRowButton == null && properties.sDeleteRowButtonId != "") {
|
---|
1243 | oAddDeleteToolbar.append("<button id='" + properties.sDeleteRowButtonId + "' class='delete_row'>Delete</button>");
|
---|
1244 | oDeleteRowButton = $("#" + properties.sDeleteRowButtonId);
|
---|
1245 | oDeleteRowButton.click(_fnOnRowDelete);
|
---|
1246 | }
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | //If delete button exists disable it until some row is selected
|
---|
1250 | if (oDeleteRowButton != null) {
|
---|
1251 | if (properties.oDeleteRowButtonOptions != null) {
|
---|
1252 | oDeleteRowButton.button(properties.oDeleteRowButtonOptions);
|
---|
1253 | }
|
---|
1254 | fnDisableDeleteButton();
|
---|
1255 | }
|
---|
1256 |
|
---|
1257 | //If add button exists convert it to the JQuery-ui button
|
---|
1258 | if (oAddNewRowButton != null) {
|
---|
1259 | if (properties.oAddNewRowButtonOptions != null) {
|
---|
1260 | oAddNewRowButton.button(properties.oAddNewRowButtonOptions);
|
---|
1261 | }
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 |
|
---|
1265 | //If form ok button exists convert it to the JQuery-ui button
|
---|
1266 | if (oConfirmRowAddingButton != null) {
|
---|
1267 | if (properties.oAddNewRowOkButtonOptions != null) {
|
---|
1268 | oConfirmRowAddingButton.button(properties.oAddNewRowOkButtonOptions);
|
---|
1269 | }
|
---|
1270 | }
|
---|
1271 |
|
---|
1272 | //If form cancel button exists convert it to the JQuery-ui button
|
---|
1273 | if (oCancelRowAddingButton != null) {
|
---|
1274 | if (properties.oAddNewRowCancelButtonOptions != null) {
|
---|
1275 | oCancelRowAddingButton.button(properties.oAddNewRowCancelButtonOptions);
|
---|
1276 | }
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | // AndrewFix
|
---|
1280 | // $('tr', dt.nTBody).live( 'click', function(e) {
|
---|
1281 | // $(dt.nTBody).on('click', 'tr', function(e) {
|
---|
1282 |
|
---|
1283 | //Add handler to the inline delete buttons
|
---|
1284 | //$(".table-action-deletelink", oTable).live("click", _fnOnRowDeleteInline); // backup
|
---|
1285 | $(oTable).on("click", '.table-action-deletelink', _fnOnRowDeleteInline);
|
---|
1286 |
|
---|
1287 | if (!properties.bUseKeyTable) {
|
---|
1288 | //Set selected class on row that is clicked
|
---|
1289 | //Enable delete button if row is selected, disable delete button if selected class is removed
|
---|
1290 | $("tbody", oTable).click(function (event) {
|
---|
1291 | if ($(event.target.parentNode).hasClass(properties.sSelectedRowClass)) {
|
---|
1292 | $(event.target.parentNode).removeClass(properties.sSelectedRowClass);
|
---|
1293 | if (oDeleteRowButton != null) {
|
---|
1294 | fnDisableDeleteButton();
|
---|
1295 | }
|
---|
1296 | } else {
|
---|
1297 | $(oTable.fnSettings().aoData).each(function () {
|
---|
1298 | $(this.nTr).removeClass(properties.sSelectedRowClass);
|
---|
1299 | });
|
---|
1300 | $(event.target.parentNode).addClass(properties.sSelectedRowClass);
|
---|
1301 | if (oDeleteRowButton != null) {
|
---|
1302 | fnEnableDeleteButton();
|
---|
1303 | }
|
---|
1304 | }
|
---|
1305 | });
|
---|
1306 | } else {
|
---|
1307 | oTable.keys.event.focus(null, null, function (nNode, x, y) {
|
---|
1308 |
|
---|
1309 | });
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | if (properties.aoTableActions != null) {
|
---|
1313 | for (var i = 0; i < properties.aoTableActions.length; i++) {
|
---|
1314 | var oTableAction = $.extend({ sType: "edit" }, properties.aoTableActions[i]);
|
---|
1315 | var sAction = oTableAction.sAction;
|
---|
1316 | var sActionFormId = oTableAction.sActionFormId;
|
---|
1317 |
|
---|
1318 | var oActionForm = $("#form" + sAction);
|
---|
1319 | if (oActionForm.length != 0) {
|
---|
1320 | var oFormOptions = { autoOpen: false, modal: true };
|
---|
1321 | oFormOptions = $.extend({}, oTableAction.oFormOptions, oFormOptions);
|
---|
1322 | oActionForm.dialog(oFormOptions);
|
---|
1323 | oActionForm.data("action-options", oTableAction);
|
---|
1324 |
|
---|
1325 | var oActionFormLink = $(".table-action-" + sAction);
|
---|
1326 | if (oActionFormLink.length != 0) {
|
---|
1327 |
|
---|
1328 | // AndrewFix
|
---|
1329 | // $('tr', dt.nTBody).live( 'click', function(e) {
|
---|
1330 | // $(dt.nTBody).on('click', 'tr', function(e) {
|
---|
1331 |
|
---|
1332 | // oActionFormLink.live("click", function () // backup
|
---|
1333 | oActionFormLink.on("click", function () {
|
---|
1334 |
|
---|
1335 |
|
---|
1336 | var sClass = this.className;
|
---|
1337 | var classList = sClass.split(/\s+/);
|
---|
1338 | var sActionFormId = "";
|
---|
1339 | var sAction = "";
|
---|
1340 | for (i = 0; i < classList.length; i++) {
|
---|
1341 | if (classList[i].indexOf("table-action-") > -1) {
|
---|
1342 | sAction = classList[i].replace("table-action-", "");
|
---|
1343 | sActionFormId = "#form" + sAction;
|
---|
1344 | }
|
---|
1345 | }
|
---|
1346 | if (sActionFormId == "") {
|
---|
1347 | properties.fnShowError("Cannot find a form with an id " + sActionFormId + " that should be associated to the action - " + sAction, sAction)
|
---|
1348 | }
|
---|
1349 |
|
---|
1350 | var oTableAction = $(sActionFormId).data("action-options");
|
---|
1351 |
|
---|
1352 | if (oTableAction.sType == "edit") {
|
---|
1353 |
|
---|
1354 | //var oTD = ($(this).parents('td'))[0];
|
---|
1355 | var oTR = ($(this).parents('tr'))[0];
|
---|
1356 | fnPopulateFormWithRowCells(oActionForm, oTR);
|
---|
1357 | }
|
---|
1358 | $(oActionForm).dialog('open');
|
---|
1359 | });
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | oActionForm.submit(function (event) {
|
---|
1363 |
|
---|
1364 | fnSendFormUpdateRequest(this);
|
---|
1365 | return false;
|
---|
1366 |
|
---|
1367 | });
|
---|
1368 |
|
---|
1369 |
|
---|
1370 | var aActionFormButtons = new Array();
|
---|
1371 |
|
---|
1372 | //var oActionSubmitButton = $("#form" + sAction + "Ok", oActionForm);
|
---|
1373 | //aActionFormButtons.push(oActionSubmitButton);
|
---|
1374 | var oActionFormCancel = $("#form" + sAction + "Cancel", oActionForm);
|
---|
1375 | if (oActionFormCancel.length != 0) {
|
---|
1376 | aActionFormButtons.push(oActionFormCancel);
|
---|
1377 | oActionFormCancel.click(function () {
|
---|
1378 |
|
---|
1379 | var oActionForm = $(this).parents("form")[0];
|
---|
1380 | //Clear the validation messages and reset form
|
---|
1381 | $(oActionForm).validate().resetForm(); // Clears the validation errors
|
---|
1382 | $(oActionForm)[0].reset();
|
---|
1383 |
|
---|
1384 | $(".error", $(oActionForm)).html("");
|
---|
1385 | $(".error", $(oActionForm)).hide(); // Hides the error element
|
---|
1386 | $(oActionForm).dialog('close');
|
---|
1387 | });
|
---|
1388 | }
|
---|
1389 |
|
---|
1390 | //Convert all action form buttons to the JQuery UI buttons
|
---|
1391 | $("button", oActionForm).button();
|
---|
1392 | /*
|
---|
1393 | if (aActionFormButtons.length > 0) {
|
---|
1394 | oActionForm.dialog('option', 'buttons', aActionFormButtons);
|
---|
1395 | }
|
---|
1396 | */
|
---|
1397 |
|
---|
1398 |
|
---|
1399 |
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 |
|
---|
1403 |
|
---|
1404 |
|
---|
1405 | } // end for (var i = 0; i < properties.aoTableActions.length; i++)
|
---|
1406 | } //end if (properties.aoTableActions != null)
|
---|
1407 |
|
---|
1408 |
|
---|
1409 | });
|
---|
1410 | };
|
---|
1411 | })(jQuery);
|
---|
1412 |
|
---|