diff options
author | hikalkan <hi_kalkan@yahoo.com> | 2013-09-21 12:19:12 +0300 |
---|---|---|
committer | hikalkan <hi_kalkan@yahoo.com> | 2013-09-21 12:19:12 +0300 |
commit | 88e4d6e2f42462e421b95230556cb534d24958e1 (patch) | |
tree | f2a03895bfd44c084111fbd76cc96105d98b9054 /lib/jquery.jtable.js | |
parent | 4d2ec0b55ae2c0b7e2cd3089d9b5cb25bde833de (diff) | |
download | jtable-88e4d6e2f42462e421b95230556cb534d24958e1.zip jtable-88e4d6e2f42462e421b95230556cb534d24958e1.tar.gz jtable-88e4d6e2f42462e421b95230556cb534d24958e1.tar.bz2 |
jTable v2.3.1v2.3.1
Bugfixes (#161, #254, #357, #570, #822) and localizations.
Diffstat (limited to 'lib/jquery.jtable.js')
-rw-r--r-- | lib/jquery.jtable.js | 124 |
1 files changed, 86 insertions, 38 deletions
diff --git a/lib/jquery.jtable.js b/lib/jquery.jtable.js index b70b111..243b9b1 100644 --- a/lib/jquery.jtable.js +++ b/lib/jquery.jtable.js @@ -1,6 +1,6 @@ /* -jTable 2.3.0 +jTable 2.3.1 http://www.jtable.org --------------------------------------------------------------------------- @@ -32,6 +32,15 @@ THE SOFTWARE. *************************************************************************/ (function ($) { + var unloadingPage; + + $(window).on('beforeunload', function () { + unloadingPage = true; + }); + $(window).on('unload', function () { + unloadingPage = false; + }); + $.widget("hik.jtable", { /************************************************************************ @@ -136,7 +145,7 @@ THE SOFTWARE. this._createErrorDialogDiv(); this._addNoDataRow(); - this._cookieKeyPrefix = this._generateCookieKeyPrefix(); + this._cookieKeyPrefix = this._generateCookieKeyPrefix(); }, /* Normalizes some options for all fields (sets default values). @@ -1128,9 +1137,14 @@ THE SOFTWARE. }; //Override error - opts.error = function () { + opts.error = function (jqXHR, textStatus, errorThrown) { + if (unloadingPage) { + jqXHR.abort(); + return; + } + if (options.error) { - options.error(); + options.error(arguments); } }; @@ -1926,6 +1940,11 @@ THE SOFTWARE. *************************************************************************/ _create: function () { base._create.apply(this, arguments); + + if (!this.options.actions.createAction) { + return; + } + this._createAddRecordDialogDiv(); }, @@ -1934,11 +1953,6 @@ THE SOFTWARE. _createAddRecordDialogDiv: function () { var self = this; - //Check if createAction is supplied - if (!self.options.actions.createAction) { - return; - } - //Create a div for dialog and add to container element self._$addRecordDiv = $('<div />') .appendTo(self._$mainContainer); @@ -1962,13 +1976,7 @@ THE SOFTWARE. id: 'AddRecordDialogSaveButton', text: self.options.messages.save, click: function () { - var $saveButton = $('#AddRecordDialogSaveButton'); - var $addRecordForm = self._$addRecordDiv.find('form'); - - if (self._trigger("formSubmitting", null, { form: $addRecordForm, formType: 'create' }) != false) { - self._setEnabledOfDialogButton($saveButton, false, self.options.messages.saving); - self._saveAddRecordForm($addRecordForm, $saveButton); - } + self._onSaveClickedOnCreateForm(); } }], close: function () { @@ -1998,6 +2006,18 @@ THE SOFTWARE. }); } }, + + _onSaveClickedOnCreateForm: function () { + var self = this; + + var $saveButton = $('#AddRecordDialogSaveButton'); + var $addRecordForm = self._$addRecordDiv.find('form'); + + if (self._trigger("formSubmitting", null, { form: $addRecordForm, formType: 'create' }) != false) { + self._setEnabledOfDialogButton($saveButton, false, self.options.messages.saving); + self._saveAddRecordForm($addRecordForm, $saveButton); + } + }, /************************************************************************ * PUBLIC METHODS * @@ -2079,7 +2099,7 @@ THE SOFTWARE. var self = this; //Create add new record form - var $addRecordForm = $('<form id="jtable-create-form" class="jtable-dialog-form jtable-create-form" action="' + self.options.actions.createAction + '" method="POST"></form>'); + var $addRecordForm = $('<form id="jtable-create-form" class="jtable-dialog-form jtable-create-form"></form>'); //Create input elements for (var i = 0; i < self._fieldList.length; i++) { @@ -2121,6 +2141,11 @@ THE SOFTWARE. self._makeCascadeDropDowns($addRecordForm, undefined, 'create'); + $addRecordForm.submit(function () { + self._onSaveClickedOnCreateForm(); + return false; + }); + //Open the form self._$addRecordDiv.append($addRecordForm).dialog('open'); self._trigger("formCreated", null, { form: $addRecordForm, formType: 'create' }); @@ -2135,7 +2160,7 @@ THE SOFTWARE. $addRecordForm.data('submitting', true); self._submitFormUsingAjax( - $addRecordForm.attr('action'), + self.options.actions.createAction, $addRecordForm.serialize(), function (data) { @@ -2218,6 +2243,11 @@ THE SOFTWARE. *************************************************************************/ _create: function () { base._create.apply(this, arguments); + + if (!this.options.actions.updateAction) { + return; + } + this._createEditDialogDiv(); }, @@ -2249,19 +2279,7 @@ THE SOFTWARE. id: 'EditDialogSaveButton', text: self.options.messages.save, click: function () { - - //row maybe removed by another source, if so, do nothing - if (self._$editingRow.hasClass('jtable-row-removed')) { - self._$editDiv.dialog('close'); - return; - } - - var $saveButton = $('#EditDialogSaveButton'); - var $editForm = self._$editDiv.find('form'); - if (self._trigger("formSubmitting", null, { form: $editForm, formType: 'edit', row: self._$editingRow }) != false) { - self._setEnabledOfDialogButton($saveButton, false, self.options.messages.saving); - self._saveEditForm($editForm, $saveButton); - } + self._onSaveClickedOnEditForm(); } }], close: function () { @@ -2274,8 +2292,27 @@ THE SOFTWARE. }); }, + /* Saves editing form to server. + *************************************************************************/ + _onSaveClickedOnEditForm: function () { + var self = this; + + //row maybe removed by another source, if so, do nothing + if (self._$editingRow.hasClass('jtable-row-removed')) { + self._$editDiv.dialog('close'); + return; + } + + var $saveButton = $('#EditDialogSaveButton'); + var $editForm = self._$editDiv.find('form'); + if (self._trigger("formSubmitting", null, { form: $editForm, formType: 'edit', row: self._$editingRow }) != false) { + self._setEnabledOfDialogButton($saveButton, false, self.options.messages.saving); + self._saveEditForm($editForm, $saveButton); + } + }, + /************************************************************************ - * PUNLIC METHODS * + * PUBLIC METHODS * *************************************************************************/ /* Updates a record on the table (optionally on the server also) @@ -2393,7 +2430,7 @@ THE SOFTWARE. var record = $tableRow.data('record'); //Create edit form - var $editForm = $('<form id="jtable-edit-form" class="jtable-dialog-form jtable-edit-form" action="' + self.options.actions.updateAction + '" method="POST"></form>'); + var $editForm = $('<form id="jtable-edit-form" class="jtable-dialog-form jtable-edit-form"></form>'); //Create input fields for (var i = 0; i < self._fieldList.length; i++) { @@ -2441,9 +2478,14 @@ THE SOFTWARE. form: $editForm })); } - + self._makeCascadeDropDowns($editForm, record, 'edit'); + $editForm.submit(function () { + self._onSaveClickedOnEditForm(); + return false; + }); + //Open dialog self._$editingRow = $tableRow; self._$editDiv.append($editForm).dialog('open'); @@ -2455,7 +2497,7 @@ THE SOFTWARE. _saveEditForm: function ($editForm, $saveButton) { var self = this; self._submitFormUsingAjax( - $editForm.attr('action'), + self.options.actions.updateAction, $editForm.serialize(), function (data) { //Check for errors @@ -2517,6 +2559,7 @@ THE SOFTWARE. var $columns = $tableRow.find('td'); for (var i = 0; i < this._columnList.length; i++) { var displayItem = this._getDisplayTextForRecordField(record, this._columnList[i]); + if (displayItem == 0) displayItem = "0"; $columns.eq(this._firstDataColumnOffset + i).html(displayItem || ''); } @@ -2611,6 +2654,11 @@ THE SOFTWARE. *************************************************************************/ _createDeleteDialogDiv: function () { var self = this; + + //Check if deleteAction is supplied + if (!self.options.actions.deleteAction) { + return; + } //Create div element for delete confirmation dialog self._$deleteRecordDiv = $('<div><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><span class="jtable-delete-confirm-message"></span></p></div>').appendTo(self._$mainContainer); @@ -4007,7 +4055,7 @@ THE SOFTWARE. if (fieldProps.sorting) { var colOffset = orderValue.indexOf(fieldName); if (colOffset > -1) { - if (orderValue.toUpperCase().indexOf('DESC', colOffset) > -1) { + if (orderValue.toUpperCase().indexOf(' DESC', colOffset) > -1) { self._lastSorting.push({ fieldName: fieldName, sortOrder: 'DESC' @@ -4704,14 +4752,14 @@ THE SOFTWARE. /* Overrides _removeRowsFromTable method to remove child rows of deleted rows. *************************************************************************/ _removeRowsFromTable: function ($rows, reason) { - var self = this; + //var self = this; if (reason == 'deleted') { $rows.each(function () { var $row = $(this); var $childRow = $row.data('childRow'); if ($childRow) { - self.closeChildTable($row); + //self.closeChildTable($row); //Removed since it causes "Uncaught Error: cannot call methods on jtable prior to initialization; attempted to call method 'destroy'" $childRow.remove(); } }); |