diff --git a/README.md b/README.md
index 9b236f51..d99b7f68 100644
--- a/README.md
+++ b/README.md
@@ -1,29 +1,68 @@
-What is jTable
+What is msjTable
======
-http://www.jtable.org
+
[](http://jtable.org/)
-jTable is a jQuery plugin used to create AJAX based CRUD tables without coding HTML or Javascript. It has several features including:
-
-* Automatically creates HTML table and loads records from server using AJAX.
-* Creates 'create new record' jQueryUI dialog form. When user creates a record, it sends data to server using AJAX and adds the same record to the table in the page.
-* Creates 'edit record' jQueryUI dialog form. When user edits a record, it updates server using AJAX and updates all cells on the table in the page.
-* Allow user to 'delete a record' by jQueryUI dialog based confirmation. When user deletes a record, it deletes the record from server using AJAX and deletes the record from the table in the page.
-* Shows animations for create/delete/edit operations on the table.
-* Supports server side paging using AJAX.
-* Supports server side sorting using AJAX.
-* Supports master/child tables.
-* Allows user to select rows.
-* Allows user to resize columns.
-* Allows user to show/hide columns.
-* Exposes some events to enable validation with forms.
-* It can be localized easily.
-* All styling of table and forms are defined in a CSS file, so you can easily change style of everything to use plugin in your pages. CSS file is well defined and commented.
-* It comes with pre-defined color themes.
-* It is not depended on any server side technology.
-* It is platform independed and works on all common browsers.
+#### msjTable is a jQuery plugin forked from jTable, to create AJAX based CRUD tables without coding HTML or Javascript.
+
+#### Additional features of msjTable :
+
+* Record Preview feature :
+```javascript
+$("#myjtable").jtable({
+...,
+recordPreview : true, // setting recordPreview to true, a view icon will appeare beside edit icon in each row
+...,
+fields : {
+ ...,
+ first_name : {
+ title : 'First name',
+ edit : true,
+ create : true,
+ preview : true, // specify which field you want to be shown in preview dialog
+ type : 'text'
+ },
+ ...
+});
+
+```
+
+* Multi columns form for Create, Edit and Preview dialogs.
+```javascript
+$("#myjtable").jtable({
+...,
+createFormColumns : 2, // set the number of columns in new record dialog
+editFormColumns : 2, // set the number of columns in edit record dialog
+viewFormColumns : 2, // set the number of columns in record preview dialog
+...
+
+});
+```
+
+* You can send any required fields to row-delete-request as POST data (jTable only sends single key field)
+```javascript
+$("#myjtable").jtable({
+...,
+fields : {
+ ...,
+ first_name : {
+ title : 'First name',
+ edit : true,
+ create : true,
+ delete : true, // setting delete option of field to true, sends this field beside key field as parameters to delete request.
+ type : 'text'
+ },
+ ...
+});
+
+```
+
+
+
+
+Read More about additional features and its usage [here](https://m-shaeri.ir/blog/jquery-jtable-awesome-full-featured-plugin-for-crud-table/)
Notes
======
diff --git a/dev/jquery.jtable.build.txt b/dev/jquery.jtable.build.txt
index 49f8ca72..18c5dc8e 100644
--- a/dev/jquery.jtable.build.txt
+++ b/dev/jquery.jtable.build.txt
@@ -5,9 +5,10 @@ add jquery.jtable.utils.js
add jquery.jtable.forms.js
add jquery.jtable.creation.js
add jquery.jtable.editing.js
+add jquery.jtable.preview.js
add jquery.jtable.deletion.js
add jquery.jtable.selecting.js
add jquery.jtable.paging.js
add jquery.jtable.sorting.js
add jquery.jtable.dynamiccolumns.js
-add jquery.jtable.masterchild.js
\ No newline at end of file
+add jquery.jtable.masterchild.js
diff --git a/dev/jquery.jtable.creation.js b/dev/jquery.jtable.creation.js
index 4212e967..31b9a207 100644
--- a/dev/jquery.jtable.creation.js
+++ b/dev/jquery.jtable.creation.js
@@ -225,7 +225,10 @@
//Create add new record form
var $addRecordForm = $('
');
-
+ var ColumnCount=self.options.createFormColumns ? self.options.createFormColumns : 1;
+ var CurrentColumnCount=0;
+ var $CreateFormTable = $('
').appendTo($addRecordForm);
+ var $RowContainer = $('
').appendTo($CreateFormTable);
//Create input elements
for (var i = 0; i < self._fieldList.length; i++) {
@@ -247,10 +250,16 @@
continue;
}
- //Create a container div for this input field and add to form
- var $fieldContainer = $('')
+ //Create a container table cell for this input field and add to form
+ var $fieldContainer = $('
').appendTo($CreateFormTable);
+ CurrentColumnCount=0;
+ }
//Create a label for input
$fieldContainer.append(self._createInputLabelForRecordField(fieldName));
diff --git a/dev/jquery.jtable.deletion.js b/dev/jquery.jtable.deletion.js
index 99960837..395a4e40 100644
--- a/dev/jquery.jtable.deletion.js
+++ b/dev/jquery.jtable.deletion.js
@@ -364,6 +364,25 @@
var postData = {};
postData[self._keyField] = self._getKeyValueOfRecord($row.data('record'));
+ //Add additional field to delete request POST
+ for (var i = 0; i < this._fieldList.length; i++) {
+ var fieldName = this._fieldList[i];
+ var field = this.options.fields[fieldName];
+
+ //Do not send this field to server if field delete option is not explicitly set to true
+ if (!field.delete) {
+ continue;
+ }
+
+ //Key field is already added to postData
+ if (self._keyField == fieldName) {
+ continue;
+ }
+
+ //Add field to postData to be sent to server
+ postData[fieldName] = $row.data('record')[fieldName];
+ }
+
//deleteAction may be a function, check if it is
if (!url && $.isFunction(self.options.actions.deleteAction)) {
diff --git a/dev/jquery.jtable.editing.js b/dev/jquery.jtable.editing.js
index d0a5c587..929c05e8 100644
--- a/dev/jquery.jtable.editing.js
+++ b/dev/jquery.jtable.editing.js
@@ -258,7 +258,10 @@
//Create edit form
var $editForm = $('');
-
+ var ColumnCount=self.options.editFormColumns ? self.options.editFormColumns : 1;
+ var CurrentColumnCount=0;
+ var $EditFormTable = $('
').appendTo($editForm);
+ var $RowContainer = $('
').appendTo($EditFormTable);
//Create input fields
for (var i = 0; i < self._fieldList.length; i++) {
@@ -289,7 +292,15 @@
}
//Create a container div for this input field and add to form
- var $fieldContainer = $('').appendTo($editForm);
+ var $fieldContainer = $('
').appendTo($EditFormTable);
+ CurrentColumnCount=0;
+ }
//Create a label for input
$fieldContainer.append(self._createInputLabelForRecordField(fieldName));
diff --git a/dev/jquery.jtable.forms.js b/dev/jquery.jtable.forms.js
index 799a35b0..116b5530 100644
--- a/dev/jquery.jtable.forms.js
+++ b/dev/jquery.jtable.forms.js
@@ -1,5 +1,6 @@
-/************************************************************************
-* FORMS extension for jTable (base for edit/create forms) *
+
+/************************************************************************
+* FORMS extension for jTable (base for edit/create/preview forms) *
*************************************************************************/
(function ($) {
@@ -30,6 +31,14 @@
.addClass('jtable-input-label')
.html(this.options.fields[fieldName].inputTitle || this.options.fields[fieldName].title);
},
+ /* Creates label for an input element.
+ *************************************************************************/
+ _createViewLabelForRecordField: function (fieldName) {
+ //TODO: May create label tag instead of a div.
+ return $('')
+ .addClass('jtable-view-label')
+ .html(this.options.fields[fieldName].title);
+ },
/* Creates an input element according to field type.
*************************************************************************/
@@ -45,7 +54,7 @@
//If value if not supplied, use defaultValue of the field
if (value == undefined || value == null) {
- value = field.defaultValue;
+ value = field.defaultValue;
}
//Use custom function if supplied
@@ -68,6 +77,7 @@
.append($input);
}
+
//Create input according to field type
if (field.type == 'date') {
return this._createDateInputForField(field, fieldName, value);
@@ -76,7 +86,7 @@
} else if (field.type == 'password') {
return this._createPasswordInputForField(field, fieldName, value);
} else if (field.type == 'checkbox') {
- return this._createCheckboxForField(field, fieldName, value);
+ return this._createCheckboxForField(field, fieldName, value, formType);
} else if (field.options) {
if (field.type == 'radiobutton') {
return this._createRadioButtonListForField(field, fieldName, value, record, formType);
@@ -88,6 +98,64 @@
}
},
+ /* Creates an View element according to field type.
+ *************************************************************************/
+ _createViewForRecordField: function (funcParams) {
+ var fieldName = funcParams.fieldName,
+ value = funcParams.value,
+ record = funcParams.record,
+ formType = funcParams.formType,
+ form = funcParams.form;
+
+ //Get the field
+ var field = this.options.fields[fieldName];
+
+ //If value if not supplied, use defaultValue of the field
+ if (value == undefined || value == null) {
+ value = field.defaultViewValue;
+ }
+
+ //Use custom function if supplied
+ if (field.customView) {
+ var $view = $(field.customView({
+ value: value,
+ record: record,
+ formType: formType,
+ form: form
+ }));
+
+ //Add id attribute if does not exists
+ if (!$view.attr('id')) {
+ $view.attr('id', 'View-' + fieldName);
+ }
+
+ //Wrap input element with div
+ return $('')
+ .addClass('jtable-view jtable-custom-view')
+ .append($view);
+ }
+
+
+ //Create input according to field type
+ if (field.type == 'date') {
+ return this._createTextViewForField(field, fieldName, value);
+ } else if (field.type == 'textarea') {
+ return this._createTextViewForField(field, fieldName, value);
+ } else if (field.type == 'password') {
+ return this._createTextViewForField(field, fieldName, value);
+ } else if (field.type == 'checkbox') {
+ return this._createTextViewForCheckboxField(field, fieldName, value,formType);
+ } else if (field.options) {
+ if (field.type == 'radiobutton') {
+ return this._createTextViewForOptions(field, fieldName, value, record, formType);
+ } else {
+ return this._createTextViewForOptions(field, fieldName, value, record, formType);
+ }
+ } else {
+ return this._createTextViewForField(field, fieldName, value);
+ }
+ },
+
//Creates a hidden input element with given name and value.
_createInputForHidden: function (fieldName, value) {
if (value == undefined) {
@@ -105,20 +173,9 @@
if(value != undefined) {
$input.val(value);
}
-
+
var displayFormat = field.displayFormat || this.options.defaultDateFormat;
- var changeMonth = field.changeMonth || this.options.defaultChangeMonth;
- var changeYear = field.changeYear || this.options.defaultChangeYear;
- var yearRange = field.yearRange || this.options.defaultYearRange;
- var maxDate = field.maxDate || this.options.defaultMaxDate;
-
- $input.datepicker({
- dateFormat: displayFormat,
- changeMonth: changeMonth,
- changeYear: changeYear,
- yearRange: yearRange,
- maxDate: maxDate
- });
+ $input.datepicker({ dateFormat: displayFormat });
return $('')
.addClass('jtable-input jtable-date-input')
.append($input);
@@ -131,7 +188,7 @@
if (value != undefined) {
$textArea.val(value);
}
-
+
return $('')
.addClass('jtable-input jtable-textarea-input')
.append($textArea);
@@ -140,11 +197,11 @@
/* Creates a standart textbox for a field.
*************************************************************************/
_createTextInputForField: function (field, fieldName, value) {
- var $input = $('');
+ var $input = $('');
if (value != undefined) {
$input.val(value);
}
-
+
return $('')
.addClass('jtable-input jtable-text-input')
.append($input);
@@ -153,19 +210,74 @@
/* Creates a password input for a field.
*************************************************************************/
_createPasswordInputForField: function (field, fieldName, value) {
- var $input = $('');
+ var $input = $('');
if (value != undefined) {
$input.val(value);
}
-
+
return $('')
.addClass('jtable-input jtable-password-input')
.append($input);
},
+ /* Creates a standart view span for a field.
+ *************************************************************************/
+ _createTextViewForField: function (field, fieldName, value) {
+ var $view = $('');
+ if (value != undefined) {
+ $view.html(value);
+ }
+
+ return $('')
+ .addClass('jtable-view jtable-view-text')
+ .append($view);
+ },
+
+ /* Creates a standart view for DropDownBoxs and Radio Options field.
+ *************************************************************************/
+ _createTextViewForOptions: function (field, fieldName, value, record, source ) {
+ var $view = $('');
+ var options = this._getOptionsForField(fieldName, {
+ record: record,
+ source: source
+ });
+
+ var DisplayValue = this._getOptionsSelectedItem(options,value)
+
+ if (DisplayValue != undefined && DisplayValue != null ) {
+ $view.html(DisplayValue);
+ }
+
+ return $('')
+ .addClass('jtable-view jtable-view-text')
+ .append($view);
+ },
+ /* Creates a view for checkboxfor a field.
+ *************************************************************************/
+ _createTextViewForCheckboxField: function (field, fieldName, value, formType) {
+
+ var $view = $('');
+ var self = this;
+
+ //If value is undefined, get unchecked state's value
+ if (value == undefined) {
+ value = self._getCheckBoxPropertiesForFieldByState(fieldName, false).Value;
+ }
+ var DisplayValue = self._getCheckBoxTextForFieldByValue(fieldName, value)
+
+ if (DisplayValue != undefined && DisplayValue != null ) {
+ $view.html(DisplayValue);
+ }
+
+ return $('')
+ .addClass('jtable-view jtable-view-text')
+ .append($view);
+
+ },
+
/* Creates a checkboxfor a field.
*************************************************************************/
- _createCheckboxForField: function (field, fieldName, value) {
+ _createCheckboxForField: function (field, fieldName, value, formType) {
var self = this;
//If value is undefined, get unchecked state's value
@@ -178,7 +290,7 @@
.addClass('jtable-input jtable-checkbox-input');
//Create checkbox and check if needed
- var $checkBox = $('')
+ var $checkBox = $('')
.appendTo($containerDiv);
if (value != undefined) {
$checkBox.val(value);
@@ -193,6 +305,8 @@
$checkBox.attr('checked', 'checked');
}
+
+
//This method sets checkbox's value and text according to state of the checkbox
var refreshCheckBoxValueAndText = function () {
var checkboxProps = self._getCheckBoxPropertiesForFieldByState(fieldName, $checkBox.is(':checked'));
@@ -247,7 +361,7 @@
return $containerDiv;
},
-
+
/* Fills a dropdown list with given options.
*************************************************************************/
_fillDropDownListWithOptions: function ($select, options, value) {
@@ -258,6 +372,15 @@
.appendTo($select);
}
},
+ /* get selected item from given options
+ *************************************************************************/
+ _getOptionsSelectedItem: function (options, value) {
+ for (var i = 0; i < options.length; i++) {
+ if (options[i].Value == value )
+ return options[i].DisplayText ;
+ }
+ return null;
+ },
/* Creates depended values object from given form.
*************************************************************************/
@@ -307,6 +430,10 @@
.html(option.DisplayText)
.appendTo($radioButtonDiv);
+ if (source = 'view'){
+ $radioButton.attr('disabled', 'disabled');
+ }
+
if (field.setOnTextClick != false) {
$textSpan
.addClass('jtable-option-text-clickable')
@@ -384,7 +511,7 @@
}
var field = self.options.fields[fieldName];
-
+
//check if this combobox depends on others
if (!field.dependsOn) {
return;
diff --git a/dev/jquery.jtable.preview.js b/dev/jquery.jtable.preview.js
new file mode 100644
index 00000000..07498d43
--- /dev/null
+++ b/dev/jquery.jtable.preview.js
@@ -0,0 +1,227 @@
+/************************************************************************
+ * VIEW RECORD extension for jTable *
+ *************************************************************************/
+(function ($) {
+
+ //Reference to base object members
+ var base = {
+ _create: $.hik.jtable.prototype._create,
+ _addColumnsToHeaderRow: $.hik.jtable.prototype._addColumnsToHeaderRow,
+ _addCellsToRowUsingRecord: $.hik.jtable.prototype._addCellsToRowUsingRecord
+ };
+
+ //extension members
+ $.extend(true, $.hik.jtable.prototype, {
+
+ /************************************************************************
+ * DEFAULT OPTIONS / EVENTS *
+ *************************************************************************/
+ options: {
+
+ //Events
+ recordUpdated: function (event, data) { },
+ rowUpdated: function (event, data) { },
+
+ //Localization
+ messages: {
+ viewRecord: 'View'
+ }
+ },
+
+ /************************************************************************
+ * PRIVATE FIELDS *
+ *************************************************************************/
+
+ _$viewDiv: null, //Reference to the viewing dialog div (jQuery object)
+ _$viewingRow: null, //Reference to currently viewing row (jQuery object)
+
+ /************************************************************************
+ * CONSTRUCTOR AND INITIALIZATION METHODS *
+ *************************************************************************/
+
+ /* Overrides base method to do viewing-specific constructions.
+ *************************************************************************/
+ _create: function () {
+ base._create.apply(this, arguments);
+
+ if (!this.options.recordPreview) {
+ return;
+ }
+
+ this._createViewDialogDiv();
+ },
+
+ /* Creates and prepares preview dialog div
+ *************************************************************************/
+ _createViewDialogDiv: function () {
+ var self = this;
+
+ //Create a div for dialog and add to container element
+ self._$viewDiv = $('')
+ .appendTo(self._$mainContainer);
+
+ //Prepare dialog
+ self._$viewDiv.dialog({
+ autoOpen: false,
+ show: self.options.dialogShowEffect,
+ hide: self.options.dialogHideEffect,
+ width: 'auto',
+ minWidth: '300',
+ modal: true,
+ title: self.options.messages.viewRecord,
+ buttons:
+ [{ //close button
+ text: self.options.messages.close,
+ click: function () {
+ self._$viewDiv.dialog('close');
+ }
+ }],
+ close: function () {
+ var $viewForm = self._$viewDiv.find('form:first');
+ self._trigger("formClosed", null, { form: $viewForm, formType: 'edit', row: self._$viewingRow });
+ $viewForm.remove();
+ }
+ });
+ },
+
+
+
+ /************************************************************************
+ * PUBLIC METHODS *
+ *************************************************************************/
+
+
+ /************************************************************************
+ * OVERRIDED METHODS *
+ *************************************************************************/
+
+ /* Overrides base method to add a 'view coomand column cell' to header row.
+ *************************************************************************/
+ _addColumnsToHeaderRow: function ($tr) {
+ base._addColumnsToHeaderRow.apply(this, arguments);
+ if (self.options.recordPreview == true) {
+ $tr.append(this._createEmptyCommandHeader());
+ }
+ },
+
+ /* Overrides base method to add a 'edit command cell' to a row.
+ *************************************************************************/
+ _addCellsToRowUsingRecord: function ($row) {
+ var self = this;
+ base._addCellsToRowUsingRecord.apply(this, arguments);
+
+
+ // Add View command cell if the viewable option is sef to true
+ if (self.options.recordPreview == true ) {
+ var $span = $('').html(self.options.messages.viewRecord);
+ var $button = $('')
+ .addClass('jtable-command-button jtable-view-command-button')
+ .append($span)
+ .click(function (e) {
+ e.preventDefault();
+ e.stopPropagation();
+ self._showViewForm($row);
+ });
+ $('
')
+ .addClass('jtable-command-column')
+ .append($button)
+ .appendTo($row);
+ }
+
+
+
+ },
+
+
+ /************************************************************************
+ * PRIVATE METHODS *
+ *************************************************************************/
+
+ /* Shows view form for a row.
+ *************************************************************************/
+ _showViewForm: function ($tableRow) {
+ var self = this;
+ var record = $tableRow.data('record');
+
+ //Create view form
+ var $ViewForm = $('');
+ var ColumnCount=self.options.viewFormColumns ? self.options.viewFormColumns : 1;
+ var CurrentColumnCount=0;
+ var $ViewFormTable = $('
').appendTo($ViewForm);
+ var $RowContainer = $('
').appendTo($ViewFormTable);
+ //Create input fields
+ for (var i = 0; i < self._fieldList.length; i++) {
+
+ var fieldName = self._fieldList[i];
+ var field = self.options.fields[fieldName];
+ var fieldValue = record[fieldName];
+
+
+ //Do not create element for non-viewable fields
+ if (field.view == false) {
+ continue;
+ }
+
+
+
+ //Create a container div for this input field and add to form
+ var $fieldContainer = $('
').appendTo($ViewFormTable);
+ CurrentColumnCount=0;
+ }
+
+ //Create a label for input
+ $fieldContainer.append(self._createViewLabelForRecordField(fieldName));
+
+ //Create input element with it's current value
+ var currentValue = self._getValueForRecordField(record, fieldName);
+ $fieldContainer.append(
+ self._createViewForRecordField({
+ fieldName: fieldName,
+ value: currentValue,
+ record: record,
+ formType: 'view',
+ form: $ViewForm
+ }));
+ }
+
+ self._makeCascadeDropDowns($ViewForm, record, 'view');
+
+
+
+ //Open dialog
+ self._$viewingRow = $tableRow;
+ self._$viewDiv.clear();
+ self._$viewDiv.append($ViewForm).dialog('open');
+ self._trigger("formCreated", null, { form: $ViewForm, formType: 'view', record: record, row: $tableRow });
+ }
+ ,
+
+
+
+ /* Gets text for a field of a record according to it's type.
+ *************************************************************************/
+ _getValueForRecordField: function (record, fieldName) {
+ var field = this.options.fields[fieldName];
+ var fieldValue = record[fieldName];
+ if (field.type == 'date') {
+ return this._getDisplayTextForDateRecordField(field, fieldValue);
+ } else {
+ return fieldValue;
+ }
+ }
+
+
+ /************************************************************************
+ * EVENT RAISING METHODS *
+ *************************************************************************/
+
+
+ });
+
+})(jQuery);
\ No newline at end of file
diff --git a/jTable.jquery.json b/jTable.jquery.json
index b66d95c6..bbc8e2d1 100644
--- a/jTable.jquery.json
+++ b/jTable.jquery.json
@@ -1,6 +1,6 @@
{
- "name": "jTable",
- "title": "jTable",
+ "name": "msjTable",
+ "title": "msjTable",
"description": "A JQuery plugin to create AJAX based CRUD tables (grids). It supports paging, sorting, selecting, master/child tables, show/hide/resize columns, localization, themes and more.",
"keywords": [
"ajax",
@@ -14,14 +14,14 @@
"version": "2.6.0",
"author": {
"name": "Halil ibrahim Kalkan",
- "email": "halil@jtable.org",
+ "email": "halil@jtable.org",
"url": "http://www.halilibrahimkalkan.com"
},
"maintainers": [
{
- "name": "Halil ibrahim Kalkan",
- "email": "hi_kalkan@yahoo.com",
- "url": "http://www.halilibrahimkalkan.com"
+ "name": "Mostafa Shaeri",
+
+ "url": "https://m-shaeri.ir"
}
],
"licenses": [
@@ -30,7 +30,7 @@
"url": "http://en.wikipedia.org/wiki/MIT_License"
}
],
- "bugs": "https://github.com/volosoft/jtable/issues",
+ "bugs": "https://github.com/birddevelper/msjtable/issues",
"homepage": "http://www.jtable.org",
"docs": "http://jtable.org/Home/Documents",
"download": "http://jtable.org/Home/Downloads",
@@ -38,4 +38,4 @@
"jquery": ">=1.9.1",
"jqueryui": ">=1.9.2"
}
-}
\ No newline at end of file
+}
diff --git a/jquery.jtable.js b/jquery.jtable.js
index e69f83e0..336614b2 100644
--- a/jquery.jtable.js
+++ b/jquery.jtable.js
@@ -1,11 +1,11 @@
/*
-jTable 2.5.0
+msjTable 2.6.0
http://www.jtable.org
---------------------------------------------------------------------------
-Copyright (C) 2011-2014 by Halil İbrahim Kalkan (http://www.halilibrahimkalkan.com)
+Copyright (C) 2020-2021 by Mostafa Shaeri (https://www.m-shaeri.ir)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -25,8 +25,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-*/
-
+*/
+
/************************************************************************
* CORE jTable module *
*************************************************************************/
@@ -1388,8 +1388,8 @@ THE SOFTWARE.
});
}(jQuery));
-
-
+
+
/************************************************************************
* Some UTULITY methods used by jTable *
*************************************************************************/
@@ -1549,10 +1549,11 @@ THE SOFTWARE.
}
})(jQuery);
-
+
+
/************************************************************************
-* FORMS extension for jTable (base for edit/create forms) *
+* FORMS extension for jTable (base for edit/create/preview forms) *
*************************************************************************/
(function ($) {
@@ -1583,6 +1584,14 @@ THE SOFTWARE.
.addClass('jtable-input-label')
.html(this.options.fields[fieldName].inputTitle || this.options.fields[fieldName].title);
},
+ /* Creates label for an input element.
+ *************************************************************************/
+ _createViewLabelForRecordField: function (fieldName) {
+ //TODO: May create label tag instead of a div.
+ return $('')
+ .addClass('jtable-view-label')
+ .html(this.options.fields[fieldName].title);
+ },
/* Creates an input element according to field type.
*************************************************************************/
@@ -1598,7 +1607,7 @@ THE SOFTWARE.
//If value if not supplied, use defaultValue of the field
if (value == undefined || value == null) {
- value = field.defaultValue;
+ value = field.defaultValue;
}
//Use custom function if supplied
@@ -1621,6 +1630,7 @@ THE SOFTWARE.
.append($input);
}
+
//Create input according to field type
if (field.type == 'date') {
return this._createDateInputForField(field, fieldName, value);
@@ -1629,7 +1639,7 @@ THE SOFTWARE.
} else if (field.type == 'password') {
return this._createPasswordInputForField(field, fieldName, value);
} else if (field.type == 'checkbox') {
- return this._createCheckboxForField(field, fieldName, value);
+ return this._createCheckboxForField(field, fieldName, value, formType);
} else if (field.options) {
if (field.type == 'radiobutton') {
return this._createRadioButtonListForField(field, fieldName, value, record, formType);
@@ -1641,6 +1651,64 @@ THE SOFTWARE.
}
},
+ /* Creates an View element according to field type.
+ *************************************************************************/
+ _createViewForRecordField: function (funcParams) {
+ var fieldName = funcParams.fieldName,
+ value = funcParams.value,
+ record = funcParams.record,
+ formType = funcParams.formType,
+ form = funcParams.form;
+
+ //Get the field
+ var field = this.options.fields[fieldName];
+
+ //If value if not supplied, use defaultValue of the field
+ if (value == undefined || value == null) {
+ value = field.defaultViewValue;
+ }
+
+ //Use custom function if supplied
+ if (field.customView) {
+ var $view = $(field.customView({
+ value: value,
+ record: record,
+ formType: formType,
+ form: form
+ }));
+
+ //Add id attribute if does not exists
+ if (!$view.attr('id')) {
+ $view.attr('id', 'View-' + fieldName);
+ }
+
+ //Wrap input element with div
+ return $('')
+ .addClass('jtable-view jtable-custom-view')
+ .append($view);
+ }
+
+
+ //Create input according to field type
+ if (field.type == 'date') {
+ return this._createTextViewForField(field, fieldName, value);
+ } else if (field.type == 'textarea') {
+ return this._createTextViewForField(field, fieldName, value);
+ } else if (field.type == 'password') {
+ return this._createTextViewForField(field, fieldName, value);
+ } else if (field.type == 'checkbox') {
+ return this._createTextViewForCheckboxField(field, fieldName, value,formType);
+ } else if (field.options) {
+ if (field.type == 'radiobutton') {
+ return this._createTextViewForOptions(field, fieldName, value, record, formType);
+ } else {
+ return this._createTextViewForOptions(field, fieldName, value, record, formType);
+ }
+ } else {
+ return this._createTextViewForField(field, fieldName, value);
+ }
+ },
+
//Creates a hidden input element with given name and value.
_createInputForHidden: function (fieldName, value) {
if (value == undefined) {
@@ -1658,20 +1726,9 @@ THE SOFTWARE.
if(value != undefined) {
$input.val(value);
}
-
+
var displayFormat = field.displayFormat || this.options.defaultDateFormat;
- var changeMonth = field.changeMonth || this.options.defaultChangeMonth;
- var changeYear = field.changeYear || this.options.defaultChangeYear;
- var yearRange = field.yearRange || this.options.defaultYearRange;
- var maxDate = field.maxDate || this.options.defaultMaxDate;
-
- $input.datepicker({
- dateFormat: displayFormat,
- changeMonth: changeMonth,
- changeYear: changeYear,
- yearRange: yearRange,
- maxDate: maxDate
- });
+ $input.datepicker({ dateFormat: displayFormat });
return $('')
.addClass('jtable-input jtable-date-input')
.append($input);
@@ -1684,7 +1741,7 @@ THE SOFTWARE.
if (value != undefined) {
$textArea.val(value);
}
-
+
return $('')
.addClass('jtable-input jtable-textarea-input')
.append($textArea);
@@ -1693,11 +1750,11 @@ THE SOFTWARE.
/* Creates a standart textbox for a field.
*************************************************************************/
_createTextInputForField: function (field, fieldName, value) {
- var $input = $('');
+ var $input = $('');
if (value != undefined) {
$input.val(value);
}
-
+
return $('')
.addClass('jtable-input jtable-text-input')
.append($input);
@@ -1706,19 +1763,74 @@ THE SOFTWARE.
/* Creates a password input for a field.
*************************************************************************/
_createPasswordInputForField: function (field, fieldName, value) {
- var $input = $('');
+ var $input = $('');
if (value != undefined) {
$input.val(value);
}
-
+
return $('')
.addClass('jtable-input jtable-password-input')
.append($input);
},
+ /* Creates a standart view span for a field.
+ *************************************************************************/
+ _createTextViewForField: function (field, fieldName, value) {
+ var $view = $('');
+ if (value != undefined) {
+ $view.html(value);
+ }
+
+ return $('')
+ .addClass('jtable-view jtable-view-text')
+ .append($view);
+ },
+
+ /* Creates a standart view for DropDownBoxs and Radio Options field.
+ *************************************************************************/
+ _createTextViewForOptions: function (field, fieldName, value, record, source ) {
+ var $view = $('');
+ var options = this._getOptionsForField(fieldName, {
+ record: record,
+ source: source
+ });
+
+ var DisplayValue = this._getOptionsSelectedItem(options,value)
+
+ if (DisplayValue != undefined && DisplayValue != null ) {
+ $view.html(DisplayValue);
+ }
+
+ return $('')
+ .addClass('jtable-view jtable-view-text')
+ .append($view);
+ },
+ /* Creates a view for checkboxfor a field.
+ *************************************************************************/
+ _createTextViewForCheckboxField: function (field, fieldName, value, formType) {
+
+ var $view = $('');
+ var self = this;
+
+ //If value is undefined, get unchecked state's value
+ if (value == undefined) {
+ value = self._getCheckBoxPropertiesForFieldByState(fieldName, false).Value;
+ }
+ var DisplayValue = self._getCheckBoxTextForFieldByValue(fieldName, value)
+
+ if (DisplayValue != undefined && DisplayValue != null ) {
+ $view.html(DisplayValue);
+ }
+
+ return $('')
+ .addClass('jtable-view jtable-view-text')
+ .append($view);
+
+ },
+
/* Creates a checkboxfor a field.
*************************************************************************/
- _createCheckboxForField: function (field, fieldName, value) {
+ _createCheckboxForField: function (field, fieldName, value, formType) {
var self = this;
//If value is undefined, get unchecked state's value
@@ -1731,7 +1843,7 @@ THE SOFTWARE.
.addClass('jtable-input jtable-checkbox-input');
//Create checkbox and check if needed
- var $checkBox = $('')
+ var $checkBox = $('')
.appendTo($containerDiv);
if (value != undefined) {
$checkBox.val(value);
@@ -1746,6 +1858,8 @@ THE SOFTWARE.
$checkBox.attr('checked', 'checked');
}
+
+
//This method sets checkbox's value and text according to state of the checkbox
var refreshCheckBoxValueAndText = function () {
var checkboxProps = self._getCheckBoxPropertiesForFieldByState(fieldName, $checkBox.is(':checked'));
@@ -1800,7 +1914,7 @@ THE SOFTWARE.
return $containerDiv;
},
-
+
/* Fills a dropdown list with given options.
*************************************************************************/
_fillDropDownListWithOptions: function ($select, options, value) {
@@ -1811,6 +1925,15 @@ THE SOFTWARE.
.appendTo($select);
}
},
+ /* get selected item from given options
+ *************************************************************************/
+ _getOptionsSelectedItem: function (options, value) {
+ for (var i = 0; i < options.length; i++) {
+ if (options[i].Value == value )
+ return options[i].DisplayText ;
+ }
+ return null;
+ },
/* Creates depended values object from given form.
*************************************************************************/
@@ -1860,6 +1983,10 @@ THE SOFTWARE.
.html(option.DisplayText)
.appendTo($radioButtonDiv);
+ if (source = 'view'){
+ $radioButton.attr('disabled', 'disabled');
+ }
+
if (field.setOnTextClick != false) {
$textSpan
.addClass('jtable-option-text-clickable')
@@ -1937,7 +2064,7 @@ THE SOFTWARE.
}
var field = self.options.fields[fieldName];
-
+
//check if this combobox depends on others
if (!field.dependsOn) {
return;
@@ -2045,8 +2172,8 @@ THE SOFTWARE.
});
})(jQuery);
-
-
+
+
/************************************************************************
* CREATE RECORD extension for jTable *
*************************************************************************/
@@ -2110,7 +2237,7 @@ THE SOFTWARE.
autoOpen: false,
show: self.options.dialogShowEffect,
hide: self.options.dialogHideEffect,
- width: 'auto',
+ width: self.options.formDialogWidth ? self.options.formDialogWidth : 'auto',
minWidth: '300',
modal: true,
title: self.options.messages.addNewRecord,
@@ -2274,7 +2401,10 @@ THE SOFTWARE.
//Create add new record form
var $addRecordForm = $('');
-
+ var ColumnCount=self.options.createFormColumns ? self.options.createFormColumns : 1;
+ var CurrentColumnCount=0;
+ var $CreateFormTable = $('
').appendTo($addRecordForm);
+ var $RowContainer = $('
').appendTo($CreateFormTable);
//Create input elements
for (var i = 0; i < self._fieldList.length; i++) {
@@ -2296,10 +2426,16 @@ THE SOFTWARE.
continue;
}
- //Create a container div for this input field and add to form
- var $fieldContainer = $('')
+ //Create a container table cell for this input field and add to form
+ var $fieldContainer = $('
').appendTo($CreateFormTable);
+ CurrentColumnCount=0;
+ }
//Create a label for input
$fieldContainer.append(self._createInputLabelForRecordField(fieldName));
@@ -2395,8 +2531,8 @@ THE SOFTWARE.
});
})(jQuery);
-
-
+
+
/************************************************************************
* EDIT RECORD extension for jTable *
*************************************************************************/
@@ -2464,7 +2600,7 @@ THE SOFTWARE.
autoOpen: false,
show: self.options.dialogShowEffect,
hide: self.options.dialogHideEffect,
- width: 'auto',
+ width: self.options.formDialogWidth ? self.options.formDialogWidth : 'auto',
minWidth: '300',
modal: true,
title: self.options.messages.editRecord,
@@ -2657,7 +2793,10 @@ THE SOFTWARE.
//Create edit form
var $editForm = $('');
-
+ var ColumnCount=self.options.editFormColumns ? self.options.editFormColumns : 1;
+ var CurrentColumnCount=0;
+ var $EditFormTable = $('
').appendTo($editForm);
+ var $RowContainer = $('
').appendTo($EditFormTable);
//Create input fields
for (var i = 0; i < self._fieldList.length; i++) {
@@ -2688,7 +2827,15 @@ THE SOFTWARE.
}
//Create a container div for this input field and add to form
- var $fieldContainer = $('').appendTo($editForm);
+ var $fieldContainer = $('
').appendTo($EditFormTable);
+ CurrentColumnCount=0;
+ }
//Create a label for input
$fieldContainer.append(self._createInputLabelForRecordField(fieldName));
@@ -2849,8 +2996,236 @@ THE SOFTWARE.
});
})(jQuery);
-
-
+
+
+/************************************************************************
+ * VIEW RECORD extension for jTable *
+ *************************************************************************/
+(function ($) {
+
+ //Reference to base object members
+ var base = {
+ _create: $.hik.jtable.prototype._create,
+ _addColumnsToHeaderRow: $.hik.jtable.prototype._addColumnsToHeaderRow,
+ _addCellsToRowUsingRecord: $.hik.jtable.prototype._addCellsToRowUsingRecord
+ };
+
+ //extension members
+ $.extend(true, $.hik.jtable.prototype, {
+
+ /************************************************************************
+ * DEFAULT OPTIONS / EVENTS *
+ *************************************************************************/
+ options: {
+
+ //Events
+ recordUpdated: function (event, data) { },
+ rowUpdated: function (event, data) { },
+
+ //Localization
+ messages: {
+ viewRecord: 'View'
+ }
+ },
+
+ /************************************************************************
+ * PRIVATE FIELDS *
+ *************************************************************************/
+
+ _$viewDiv: null, //Reference to the viewing dialog div (jQuery object)
+ _$viewingRow: null, //Reference to currently viewing row (jQuery object)
+
+ /************************************************************************
+ * CONSTRUCTOR AND INITIALIZATION METHODS *
+ *************************************************************************/
+
+ /* Overrides base method to do viewing-specific constructions.
+ *************************************************************************/
+ _create: function () {
+ base._create.apply(this, arguments);
+
+ if (!this.options.recordPreview) {
+ return;
+ }
+
+ this._createViewDialogDiv();
+ },
+
+ /* Creates and prepares preview dialog div
+ *************************************************************************/
+ _createViewDialogDiv: function () {
+ var self = this;
+
+ //Create a div for dialog and add to container element
+ self._$viewDiv = $('')
+ .appendTo(self._$mainContainer);
+
+ //Prepare dialog
+ self._$viewDiv.dialog({
+ autoOpen: false,
+ show: self.options.dialogShowEffect,
+ hide: self.options.dialogHideEffect,
+ width: 'auto',
+ minWidth: '300',
+ modal: true,
+ title: self.options.messages.viewRecord,
+ buttons:
+ [{ //close button
+ text: self.options.messages.close,
+ click: function () {
+ self._$viewDiv.dialog('close');
+ }
+ }],
+ close: function () {
+ var $viewForm = self._$viewDiv.find('form:first');
+ self._trigger("formClosed", null, { form: $viewForm, formType: 'edit', row: self._$viewingRow });
+ $viewForm.remove();
+ }
+ });
+ },
+
+
+
+ /************************************************************************
+ * PUBLIC METHODS *
+ *************************************************************************/
+
+
+ /************************************************************************
+ * OVERRIDED METHODS *
+ *************************************************************************/
+
+ /* Overrides base method to add a 'view coomand column cell' to header row.
+ *************************************************************************/
+ _addColumnsToHeaderRow: function ($tr) {
+ base._addColumnsToHeaderRow.apply(this, arguments);
+ if (self.options.recordPreview == true) {
+ $tr.append(this._createEmptyCommandHeader());
+ }
+ },
+
+ /* Overrides base method to add a 'edit command cell' to a row.
+ *************************************************************************/
+ _addCellsToRowUsingRecord: function ($row) {
+ var self = this;
+ base._addCellsToRowUsingRecord.apply(this, arguments);
+
+
+ // Add View command cell if the viewable option is sef to true
+ if (self.options.recordPreview == true ) {
+ var $span = $('').html(self.options.messages.viewRecord);
+ var $button = $('')
+ .addClass('jtable-command-button jtable-view-command-button')
+ .append($span)
+ .click(function (e) {
+ e.preventDefault();
+ e.stopPropagation();
+ self._showViewForm($row);
+ });
+ $('
')
+ .addClass('jtable-command-column')
+ .append($button)
+ .appendTo($row);
+ }
+
+
+
+ },
+
+
+ /************************************************************************
+ * PRIVATE METHODS *
+ *************************************************************************/
+
+ /* Shows view form for a row.
+ *************************************************************************/
+ _showViewForm: function ($tableRow) {
+ var self = this;
+ var record = $tableRow.data('record');
+
+ //Create view form
+ var $ViewForm = $('');
+ var ColumnCount=self.options.viewFormColumns ? self.options.viewFormColumns : 1;
+ var CurrentColumnCount=0;
+ var $ViewFormTable = $('
').appendTo($ViewForm);
+ var $RowContainer = $('
').appendTo($ViewFormTable);
+ //Create input fields
+ for (var i = 0; i < self._fieldList.length; i++) {
+
+ var fieldName = self._fieldList[i];
+ var field = self.options.fields[fieldName];
+ var fieldValue = record[fieldName];
+
+
+ //Do not create element for non-viewable fields
+ if (field.view == false) {
+ continue;
+ }
+
+
+
+ //Create a container div for this input field and add to form
+ var $fieldContainer = $('