Sample 1:
jQuery code snippet:
$.validator.addMethod("life", function(value, element) { // create "life" validator method
return this.optional(element) || /^\d+|-1$/.test(value);
});
var sam_1_dual_table = $("#sample-tabs-sam-1-dual-table").cms_dual_table({ // create cms_dual_table object
editable:[
{ type: [0], target: [3] }, // type 0 - source elFinder file manager, target 2 (id) set editable
{
type: [0], // type 0 - source elFinder file manager
target: [6], // target 6 (life) set editable
onsubmit: function(settings, td){ // jeditable plugin onsubmit callback function
var input = $(td).find('input')[0]; // get jeditable input
input.name = "nameofinput"; // set jeditable input name="nameofinput"
$(this).validate({ // validate form
rules: {
'nameofinput': { // jeditable input
"life": true // check with "life" validator method
}
},
messages: {
'nameofinput': { // // jeditable input
"life": "Please enter valid cache lifetime number" // message if error
}
}
});
return ($(this).valid()); // return validation result
}
},
{
type: [0], // type 0 - source elFinder file manager
target: [5], // target 5(caching) set editable
data: {
type:"select", // set input type select
data: {'':'','caching':'caching','nocache':'nocache','inline':'inline', 'selected': ''} // set select options list
}
}
]
});
var t = [ // left side table initialization data array
["0","sample1","sample_1.file","caching","3600"], // 1-st row: type, id, file, cache life
["0","sample2","sample_2.file","nocache",""] //2-cnd row: type, id, file, cache life
];
sam_1_dual_table.cms_dual_table("add",t); // load data into left side table
$(".sample-tabs-sam-1-dual-table-save", sam_1_dual_table).click(function(){ // on click button "Save"
var t = sam_1_dual_table.cms_dual_table("getData"); // get data array from target dataTable() object
alert("Save JSON data: " + JSON.stringify(t)); // convert to JSON and alert data array
});
$(".sample-tabs-sam-1-dual-table-clear", sam_1_dual_table).click(function(){ // on click button "Clear"
sam_1_dual_table.cms_dual_table("clear"); // clear target dataTable() object
});
HTML code snippet:
<div id="sample-tabs-sam-1-dual-table">
<table class="sample-jquery-dual-table" style="width:100%">
<tr class="sample-jquery-dual-table-table">
<td>
<div class="cms_docs_title">Files list</div>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="cms-doc-files cms-dual-table-selected display">
<thead>
<tr>
<th></th>
<th style="vertical-align:bottom">No</th>
<th style="vertical-align:bottom"></th>
<th style="vertical-align:bottom">ID<sup>1</sup></th>
<th style="vertical-align:bottom">File</th>
<th style="vertical-align:bottom">Cache<sup>2</sup></th>
<th style="vertical-align:bottom">Life<sup>3</sup></th>
</tr>
</thead>
</table>
<p style="font-size:10px; font-weight:bold; font-style:italic; margin:0px; margin-top:10px">Note 1: Click to enter ID</p>
<p style="font-size:10px; font-weight:bold; font-style:italic; margin:0px">Note 2: Click to enter Cache: "caching", "nocache", "inline"</p>
<p style="font-size:10px; font-weight:bold; font-style:italic; margin:0px">Note 3: Click to enter Life (-1 means unlimited cache life time)</p>
<p style="font-size:10px; font-weight:bold; font-style:italic; margin:0px">Note 4: Drag and drop to change file order</p>
<input type="button" class="sample-tabs-sam-1-dual-table-save cms-form-submit" style="margin-top:10px" value="Save" title='Save'>
<input type="button" class="sample-tabs-sam-1-dual-table-clear cms-form-submit" style="margin-top:10px" value="Clear" title='Clear'>
</td>
</tr>
<tr class="sample-jquery-dual-table-buttons">
<td>
<table>
<tr><td><div class="cms-selectbox-button-add"><a href="#cms-dual-table-button-add" title="Add"></a></div></td></tr>
<tr><td><div class="cms-selectbox-button-rem"><a href="#cms-dual-table-button-rem" title="Remove"></a></div></td></tr>
<tr><td><div class="cms-selectbox-button-add-all"><a href="#cms-dual-table-button-add-all" title="Add all"></a></div></td></tr>
<tr><td><div class="cms-selectbox-button-rem-all"><a href="#cms-dual-table-button-rem-all" title="Remove all"></a></div></td></tr>
</table>
</td>
</tr>
<tr class="sample-jquery-dual-table-elfinder">
<td><div class="cms-dual-table-elfinder"></div></td>
</tr>
</table>
</div>
Sample 2:
jQuery code snippet:
var sam_2_dual_table = $("#sample-tabs-sam-2-dual-table").cms_dual_table({ // create cms_dual_table object
api: '/cms/files/guide/jquery/api/js/lst', // RESTful api URL address for dataTable Ajax source,
editable:[{type: [1], target: [4]}], // editable is 4-th position element in left side table when type: 1 - external source
copy: [
{type: [0,1,2], src: "title", to: 3}, // types: 0 - file manager, 1 - external, 2 - system list
// src: "title" - source is current tab title (in this sample: "Site", "External", "System")
// to: 3 - copy src to target (left side table) row 3-th position
{type: [0,1,2], src: "item", from: 3, to: 4} // types: 0 - file manager, 1 - external, 2 - system list
// src: "item" - source is right side table row
// from: 3, to: 4 - copy 3-th position element from right side table to 4-th position of left side table
]
})
var t = [ // left side table initialization data array
["2",'jquery', '/cms/srv/js/jquery-1.10.2.min.js'], // 1-st row: type, id, file
["2",'jquery-migrate', '/cms/srv/js/jquery-migrate-1.2.1.min.js'], //2-cnd row: type, id, file
["1",'', 'http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js'], //3-rd row: type, id, file
["0",'', 'sample.js'], //4-th row: type, id, file
];
sam_2_dual_table.cms_dual_table("add",t); // load data into left side table
$(".sample-tabs-sam-2-dual-table-save", sam_2_dual_table).click(function(){ // on click button "Save"
var t = sam_2_dual_table.cms_dual_table("getData"); // get data array from target dataTable() object
alert("Save JSON data: " + JSON.stringify(t)); // convert to JSON and alert data array
});
$(".sample-tabs-sam-2-dual-table-clear", sam_2_dual_table).click(function(){ // on click button "Clear"
sam_2_dual_table.cms_dual_table("clear"); // clear target dataTable() object
});
HTML code snippet:
<div id="sample-tabs-sam-2-dual-table">
<table class="sample-jquery-dual-table" style="width:100%">
<tr class="sample-jquery-dual-table-table">
<td>
<div class="cms_docs_title">Files list</div>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="cms-doc-files cms-dual-table-selected display">
<thead>
<tr>
<th></th>
<th style="vertical-align:bottom">No</th>
<th style="vertical-align:bottom"></th>
<th style="vertical-align:bottom">Type</th>
<th style="vertical-align:bottom">JScript File<sup>1</sup></th>
</tr>
</thead>
</table>
<p style="font-size:10px; font-weight:bold; font-style:italic; margin-bottom:0px">Note 1: Click to edit external JScript file URL</p>
<p style="font-size:10px; font-weight:bold; font-style:italic; margin-top:0px">Note 2: Drag and drop to change file order</p>
<input type="button" class="sample-tabs-sam-2-dual-table-save cms-form-submit" style="margin-top:10px" value="Save" title='Save'>
<input type="button" class="sample-tabs-sam-2-dual-table-clear cms-form-submit" style="margin-top:10px" value="Clear" title='Clear'>
</td>
</tr>
<tr class="sample-jquery-dual-table-buttons">
<td>
<table>
<tr><td><div class="cms-selectbox-button-add"><a href="#cms-dual-table-button-add" title="Add"></a></div></td></tr>
<tr><td><div class="cms-selectbox-button-rem"><a href="#cms-dual-table-button-rem" title="Remove"></a></div></td></tr>
<tr><td><div class="cms-selectbox-button-add-all"><a href="#cms-dual-table-button-add-all" title="Add all"></a></div></td></tr>
<tr><td><div class="cms-selectbox-button-rem-all"><a href="#cms-dual-table-button-rem-all" title="Remove all"></a></div></td></tr>
</table>
</td>
</tr>
<tr class="sample-jquery-dual-table-elfinder">
<td>
<div class="cms-dual-table-tabs">
<ul>
<li><a href="#cms-dual-table-loc" title='Select file in site file system'>Site</a></li>
<li><a href="#cms-dual-table-ext" title='Enter URL to external file'>External</a></li>
<li><a href="#cms-dual-table-sys" title='Select file from list defined in system configuration'>System</a></li>
</ul>
<div class="cms-dual-table-loc">
<div class="cms-dual-table-elfinder"></div>
</div>
<div class="cms-dual-table-ext">
<div style="white-space:nowrap">
Enter URL: <input class="cms-dual-table-input" type="text" style="width: 150px" value="http://" title='Enter URL to external file'>
</div>
</div>
<div class="cms-dual-table-sys">
<div class="cms_docs_title">System JScript Files</div>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="cms-doc-files cms-dual-table-list display">
<thead>
<tr>
<th></th>
<th style="vertical-align:bottom">No</th>
<th style="vertical-align:bottom">ID</th>
<th style="vertical-align:bottom">JScript File</th>
</tr>
</thead>
</table>
<div style="height:20px"></div>
</div>
</div>
</td>
</tr>
</table>
</div>
API URL: "/cms/files/guide/jquery/api/js/lst" returns JSON data:
{"aaData":[["<input type=\"checkbox\" \/>",1,"jquery","\/cms\/srv\/js\/jquery-1.10.2.min.js"],["<input type=\"checkbox\" \/>",2,"jquery-migrate","\/cms\/srv\/js\/jquery-migrate-1.2.1.min.js"],["<input type=\"checkbox\" \/>",3,"superfish","\/cms\/srv\/lib\/superfish-1.7.4\/js\/superfish.min.js"],["<input type=\"checkbox\" \/>",4,"jquery-ui","\/cms\/srv\/lib\/jquery-ui-1.10.3.custom\/js\/jquery-ui-1.10.3.custom.min.js"],["<input type=\"checkbox\" \/>",5,"cookie","\/cms\/srv\/js\/jquery.cookie.1.3.1.js"],["<input type=\"checkbox\" \/>",6,"dynatree","\/cms\/srv\/lib\/dynatree-1.2.5\/dist\/jquery.dynatree.min.js"],["<input type=\"checkbox\" \/>",7,"datatables","\/cms\/srv\/lib\/DataTables-1.9.4\/media\/js\/jquery.dataTables.min.js"],["<input type=\"checkbox\" \/>",8,"datatables-rowreordering","\/cms\/srv\/js\/jquery.dataTables.rowReordering.js"],["<input type=\"checkbox\" \/>",9,"validate","\/cms\/srv\/lib\/jquery-validation-master\/jquery.validate.js"],["<input type=\"checkbox\" \/>",10,"validate-add","\/cms\/srv\/lib\/jquery-validation-master\/additional-methods.js"],["<input type=\"checkbox\" \/>",11,"form","\/cms\/srv\/js\/jquery.form.3.32.0.js"]]}
API URL page XML definition in pages.xml file:
<doc><url>/js/lst</url><method>GET</method><fnc>sample_class::jsList</fnc></doc>
Full subsite (based on KUSoftas CMS) configuration and PHP code of sample RESTful API can be found in folder: /cms/files/guide/jquery/api (see using CMS tool "Files": http://www.kusoftas.com/cms/srv/admin/doc)
Sample 3:
jQuery code snippet:
var validateEmpty = function(settings, td){ // validate empty on left side table cell editing
var input = $(td).find('input')[0]; // editable input
input.name = "nameofinput"; // editable input name
$(this).validate({ // form validate
rules: {
'nameofinput': { // input name
"required": true // check if not empty
}
},
messages: {
'nameofinput': { // error message for input name
"required": "Please enter data" // error message
}
}
});
return $(this).valid(); // return validation results
}
var sam_3_dual_table = $("#sample-tabs-sam-3-dual-table").cms_dual_table({ // create cms_dual_table object
editable:[{type: [1], target: [3,4,5], onsubmit: validateEmpty}],
// type: 1 - external (form fields in this case)
// target: 3,4,5 - copy form fields into target row positions
// onsubmit: validateEmpty - execute validation function validateEmpty on jeditable input submit
copy: [
{type: [1], src: "item", from: 3, to: 3, length: 3, unique: 1}
// type: 1 - external (form fields in this case)
// src: "item" - source is right side form inputs
// to: 3 - copy form fields from right to left side table starting with 3-rd position of left side table row
// unique: 1 - only unique data (concatenate all fields when checking) can be copied
// check: 0 - do not check data on right side form are valid URL (suitable when there are form fields)
]
});
var t = [ // left side table initialization data array
["1","id1","label1","file.path1"], // 1-st row: type, id, label, file
["1","id2","label2","file.path2"] //2-cnd row: type, id, label, file
];
sam_3_dual_table.cms_dual_table("add", t, "id"); // load data into left side table ("id" - means insert ID instead of type name = tab id
$(".sample-tabs-sam-3-dual-table-save", sam_3_dual_table).click(function(){ // on click button "Save"
var t = sam_3_dual_table.cms_dual_table("getData"); // get data array from target dataTable() object
alert("Save JSON data: " + JSON.stringify(t)); // convert to JSON and alert data array
});
$(".sample-tabs-sam-3-dual-table-clear", sam_3_dual_table).click(function(){ // on click button "Clear"
sam_3_dual_table.cms_dual_table("clear"); // clear target dataTable() object
});
HTML code snippet:
<div id="sample-tabs-sam-3-dual-table">
<table class="sample-jquery-dual-table" style="width:100%">
<tr class="sample-jquery-dual-table-table">
<td>
<div class="cms_docs_title">Files list</div>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="cms-doc-files cms-dual-table-selected display">
<thead>
<tr>
<th></th>
<th style="vertical-align:bottom">No</th>
<th style="vertical-align:bottom"></th>
<th style="vertical-align:bottom">ID<sup>1</sup></th>
<th style="vertical-align:bottom">Label</th>
<th style="vertical-align:bottom">Data list file path<sup>2</sup></th>
</tr>
</thead>
</table>
<p style="font-size:10px; font-weight:bold; font-style:italic; margin-bottom:0px">Note 1: Click to edit list ID</p>
<p style="font-size:10px; font-weight:bold; font-style:italic; margin-top:0px; margin-bottom:0px">Note 2: Click to edit data list file path</p>
<p style="font-size:10px; font-weight:bold; font-style:italic; margin-top:0px">Note 3: Drag and drop to change list order</p>
<input type="button" class="sample-tabs-sam-3-dual-table-save cms-form-submit" style="margin-top:10px" value="Save" title='Save'>
<input type="button" class="sample-tabs-sam-3-dual-table-clear cms-form-submit" style="margin-top:10px" value="Clear" title='Clear'>
</td>
</tr>
<tr class="sample-jquery-dual-table-buttons">
<td>
<table>
<tr><td><div class="cms-selectbox-button-add"><a href="#cms-dual-table-button-add" title="Add"></a></div></td></tr>
<tr><td><div class="cms-selectbox-button-rem"><a href="#cms-dual-table-button-rem" title="Remove"></a></div></td></tr>
<tr><td><div class="cms-selectbox-button-add-all"><a href="#cms-dual-table-button-add-all" title="Add all"></a></div></td></tr>
<tr><td><div class="cms-selectbox-button-rem-all"><a href="#cms-dual-table-button-rem-all" title="Remove all"></a></div></td></tr>
</table>
</td>
</tr>
<tr class="sample-jquery-dual-table-elfinder">
<td>
<div class="cms-dual-table-tabs">
<ul>
<li><a href="#cms-dual-table-ext" title='Enter file id, label and path'>Enter file data</a></li>
</ul>
<div class="cms-dual-table-ext">
<div style="white-space:nowrap">
<table>
<tr>
<td class="cms-form-td">ID: </td>
<td class="cms-form-td"><input class="cms-dual-table-input cms-form-input" type="text" style="width:150px" value="" title='Enter file ID'></td>
</tr>
<tr>
<td class="cms-form-td">Label: </td>
<td class="cms-form-td"><input class="cms-dual-table-input cms-form-input" type="text" style="width:150px" value="" title='Enter label'></td>
</tr>
<tr>
<td class="cms-form-td">Path: </td>
<td class="cms-form-td"><input class="cms-dual-table-input cms-form-input" type="text" style="width:150px" value="" title='Enter file path'></td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
</table>
</div>
.cms_dual_table()
Option | Method | Callback |
---|---|---|
editable | dataTable | beforeButtonsCallback |
copy | elfinder | afterButtonsCallback |
reordering | getData | |
defaultValue | clear | |
elfinder | add | |
selected | load | |
list | ||
cms_path | ||
uniqueID |
.cms_dual_table( [settings] )
Returns: cms_dual_table()
|
|||||||||||||||||||
|
For jQuery UI based elements (dataTable, elRTE, elFinder, dialog) styling you can use jQuery UI Theming
cms_dual_table plugin has its own additional elements for styling and control:
Plugin cms_dual_table depends on following jQuery packages: