";
+ this.toolbar.get('column-on-off').html = col_html;
+ },
+
+ columnOnOff: function (el, event, field, value) {
+ // event before
+ var eventData = this.trigger({ phase: 'before', target: this.name, type: 'columnOnOff', checkbox: el, field: field, originalEvent: event });
+ if (eventData.isCancelled === true) return false;
+ // regular processing
+ var obj = this;
+ // collapse expanded rows
+ for (var r in this.records) {
+ if (this.records[r].expanded === true) this.records[r].expanded = false
+ }
+ // show/hide
+ var hide = true;
+ if (field == 'line-numbers') {
+ this.show.lineNumbers = !this.show.lineNumbers;
+ this.refresh();
+ } else if (field == 'skip') {
+ if (!w2utils.isInt(value)) value = 0;
+ obj.skip(value);
+ } else if (field == 'resize') {
+ // restore sizes
+ for (var c in this.columns) {
+ if (typeof this.columns[c].sizeOriginal != 'undefined') {
+ this.columns[c].size = this.columns[c].sizeOriginal;
+ }
+ }
+ this.initResize();
+ this.resize();
+ } else {
+ var col = this.getColumn(field);
+ if (col.hidden) {
+ $(el).prop('checked', true);
+ this.showColumn(col.field);
+ } else {
+ $(el).prop('checked', false);
+ this.hideColumn(col.field);
+ }
+ hide = false;
+ }
+ this.initColumnOnOff();
+ if (hide) {
+ setTimeout(function () {
+ $().w2overlay();
+ obj.toolbar.uncheck('column-on-off');
+ }, 100);
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ initToolbar: function () {
+ // -- if toolbar is true
+ if (typeof this.toolbar['render'] == 'undefined') {
+ var tmp_items = this.toolbar.items;
+ this.toolbar.items = [];
+ this.toolbar = $().w2toolbar($.extend(true, {}, this.toolbar, { name: this.name +'_toolbar', owner: this }));
+
+ // =============================================
+ // ------ Toolbar Generic buttons
+
+ if (this.show.toolbarReload) {
+ this.toolbar.items.push($.extend(true, {}, this.buttons['reload']));
+ }
+ if (this.show.toolbarColumns) {
+ this.toolbar.items.push($.extend(true, {}, this.buttons['columns']));
+ this.initColumnOnOff();
+ }
+ if (this.show.toolbarReload || this.show.toolbarColumn) {
+ this.toolbar.items.push({ type: 'break', id: 'break0' });
+ }
+ if (this.show.toolbarSearch) {
+ var html =
+ '
'+
+ '
'+
+ '
'+ this.buttons['search'].html +'
'+
+ '
'+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
';
+ this.toolbar.items.push({ type: 'html', id: 'search', html: html });
+ if (this.multiSearch && this.searches.length > 0) {
+ this.toolbar.items.push($.extend(true, {}, this.buttons['search-go']));
+ }
+ }
+ if (this.show.toolbarSearch && (this.show.toolbarAdd || this.show.toolbarEdit || this.show.toolbarDelete || this.show.toolbarSave)) {
+ this.toolbar.items.push({ type: 'break', id: 'break1' });
+ }
+ if (this.show.toolbarAdd) {
+ this.toolbar.items.push($.extend(true, {}, this.buttons['add']));
+ }
+ if (this.show.toolbarEdit) {
+ this.toolbar.items.push($.extend(true, {}, this.buttons['edit']));
+ }
+ if (this.show.toolbarDelete) {
+ this.toolbar.items.push($.extend(true, {}, this.buttons['delete']));
+ }
+ if (this.show.toolbarSave) {
+ if (this.show.toolbarAdd || this.show.toolbarDelete || this.show.toolbarEdit) {
+ this.toolbar.items.push({ type: 'break', id: 'break2' });
+ }
+ this.toolbar.items.push($.extend(true, {}, this.buttons['save']));
+ }
+ // add original buttons
+ for (var i in tmp_items) this.toolbar.items.push(tmp_items[i]);
+
+ // =============================================
+ // ------ Toolbar onClick processing
+
+ var obj = this;
+ this.toolbar.on('click', function (event) {
+ var eventData = obj.trigger({ phase: 'before', type: 'toolbar', target: event.target, originalEvent: event });
+ if (eventData.isCancelled === true) return false;
+ var id = event.target;
+ switch (id) {
+ case 'reload':
+ var eventData2 = obj.trigger({ phase: 'before', type: 'reload', target: obj.name });
+ if (eventData2.isCancelled === true) return false;
+ var url = (typeof obj.url != 'object' ? obj.url : obj.url.get);
+ if (url) {
+ obj.clear(true);
+ } else {
+ obj.last.scrollTop = 0;
+ obj.last.scrollLeft = 0;
+ obj.last.range_start= null;
+ obj.last.range_end = null;
+ }
+ obj.reload();
+ obj.trigger($.extend(eventData2, { phase: 'after' }));
+ break;
+ case 'column-on-off':
+ for (var c in obj.columns) {
+ if (obj.columns[c].hidden) {
+ $("#grid_"+ obj.name +"_column_"+ c + "_check").prop("checked", false);
+ } else {
+ $("#grid_"+ obj.name +"_column_"+ c + "_check").prop('checked', true);
+ }
+ }
+ obj.initResize();
+ obj.resize();
+ break;
+ case 'search-advanced':
+ var tb = this;
+ var it = this.get(id);
+ if (it.checked) {
+ obj.searchClose();
+ setTimeout(function () { tb.uncheck(id); }, 1);
+ } else {
+ obj.searchOpen();
+ event.originalEvent.stopPropagation();
+ function tmp_close() { tb.uncheck(id); $(document).off('click', 'body', tmp_close); }
+ $(document).on('click', 'body', tmp_close);
+ }
+ break;
+ case 'add':
+ // events
+ var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'add', recid: null });
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ break;
+ case 'edit':
+ var sel = obj.getSelection();
+ var recid = null;
+ if (sel.length == 1) recid = sel[0];
+ // events
+ var eventData = obj.trigger({ phase: 'before', target: obj.name, type: 'edit', recid: recid });
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ break;
+ case 'delete':
+ obj.delete();
+ break;
+ case 'save':
+ obj.save();
+ break;
+ }
+ // no default action
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ });
+ }
+ return;
+ },
+
+ initSearches: function () {
+ var obj = this;
+ // init searches
+ for (var s in this.searches) {
+ var search = this.searches[s];
+ var sdata = this.getSearchData(search.field);
+ // init types
+ switch (String(search.type).toLowerCase()) {
+ case 'alphaNumeric':
+ case 'text':
+ $('#grid_'+ this.name +'_operator_'+s).val('begins with');
+ break;
+
+ case 'int':
+ case 'float':
+ case 'hex':
+ case 'money':
+ case 'date':
+ $('#grid_'+ this.name +'_field_'+s).w2field('clear').w2field(search.type);
+ $('#grid_'+ this.name +'_field2_'+s).w2field('clear').w2field(search.type);
+ break;
+
+ case 'list':
+ // build options
+ var options = '';
+ for (var i in search.items) {
+ if ($.isPlainObject(search.items[i])) {
+ var val = search.items[i].id;
+ var txt = search.items[i].text;
+ if (typeof val == 'undefined' && typeof search.items[i].value != 'undefined') val = search.items[i].value;
+ if (typeof txt == 'undefined' && typeof search.items[i].caption != 'undefined') txt = search.items[i].caption;
+ if (val == null) val = '';
+ options += '';
+ } else {
+ options += '';
+ }
+ }
+ $('#grid_'+ this.name +'_field_'+s).html(options);
+ break;
+ }
+ if (sdata != null) {
+ $('#grid_'+ this.name +'_operator_'+ s).val(sdata.operator).trigger('change');
+ if (!$.isArray(sdata.value)) {
+ if (typeof sdata.value != 'udefined') $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change');
+ } else {
+ if (sdata.operator == 'in') {
+ $('#grid_'+ this.name +'_field_'+ s).val(sdata.value).trigger('change');
+ } else {
+ $('#grid_'+ this.name +'_field_'+ s).val(sdata.value[0]).trigger('change');
+ $('#grid_'+ this.name +'_field2_'+ s).val(sdata.value[1]).trigger('change');
+ }
+ }
+ }
+ }
+ // add on change event
+ $('#w2ui-overlay .w2ui-grid-searches *[rel=search]').on('keypress', function (evnt) {
+ if (evnt.keyCode == 13) { obj.search(); }
+ });
+ },
+
+ initResize: function () {
+ var obj = this;
+ //if (obj.resizing === true) return;
+ $(this.box).find('.w2ui-resizer')
+ .off('click')
+ .on('click', function (event) {
+ if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;
+ if (event.preventDefault) event.preventDefault();
+ })
+ .off('mousedown')
+ .on('mousedown', function (event) {
+ if (!event) event = window.event;
+ if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); }
+ obj.resizing = true;
+ obj.last.tmp = {
+ x : event.screenX,
+ y : event.screenY,
+ gx : event.screenX,
+ gy : event.screenY,
+ col : parseInt($(this).attr('name'))
+ };
+ if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;
+ if (event.preventDefault) event.preventDefault();
+ // fix sizes
+ for (var c in obj.columns) {
+ if (typeof obj.columns[c].sizeOriginal == 'undefined') obj.columns[c].sizeOriginal = obj.columns[c].size;
+ obj.columns[c].size = obj.columns[c].sizeCalculated;
+ }
+ var eventData = { phase: 'before', type: 'columnResize', target: obj.name, column: obj.last.tmp.col, field: obj.columns[obj.last.tmp.col].field };
+ eventData = obj.trigger($.extend(eventData, { resizeBy: 0, originalEvent: event }));
+ // set move event
+ var mouseMove = function (event) {
+ if (obj.resizing != true) return;
+ if (!event) event = window.event;
+ // event before
+ eventData = obj.trigger($.extend(eventData, { resizeBy: (event.screenX - obj.last.tmp.gx), originalEvent: event }));
+ if (eventData.isCancelled === true) { eventData.isCancelled = false; return; }
+ // default action
+ obj.last.tmp.x = (event.screenX - obj.last.tmp.x);
+ obj.last.tmp.y = (event.screenY - obj.last.tmp.y);
+ obj.columns[obj.last.tmp.col].size = (parseInt(obj.columns[obj.last.tmp.col].size) + obj.last.tmp.x) + 'px';
+ obj.resizeRecords();
+ // reset
+ obj.last.tmp.x = event.screenX;
+ obj.last.tmp.y = event.screenY;
+ }
+ var mouseUp = function (event) {
+ delete obj.resizing;
+ $(document).off('mousemove', 'body');
+ $(document).off('mouseup', 'body');
+ obj.resizeRecords();
+ // event before
+ obj.trigger($.extend(eventData, { phase: 'after', originalEvent: event }));
+ }
+ $(document).on('mousemove', 'body', mouseMove);
+ $(document).on('mouseup', 'body', mouseUp);
+ })
+ .each(function (index, el) {
+ var td = $(el).parent();
+ $(el).css({
+ "height" : '25px',
+ "margin-left" : (td.width() - 3) + 'px'
+ })
+ });
+ },
+
+ resizeBoxes: function () {
+ // elements
+ var main = $(this.box).find('> div');
+ var header = $('#grid_'+ this.name +'_header');
+ var toolbar = $('#grid_'+ this.name +'_toolbar');
+ var summary = $('#grid_'+ this.name +'_summary');
+ var footer = $('#grid_'+ this.name +'_footer');
+ var body = $('#grid_'+ this.name +'_body');
+ var columns = $('#grid_'+ this.name +'_columns');
+ var records = $('#grid_'+ this.name +'_records');
+
+ if (this.show.header) {
+ header.css({
+ top: '0px',
+ left: '0px',
+ right: '0px'
+ });
+ }
+
+ if (this.show.toolbar) {
+ toolbar.css({
+ top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) ) + 'px',
+ left: '0px',
+ right: '0px'
+ });
+ }
+ if (this.show.footer) {
+ footer.css({
+ bottom: '0px',
+ left: '0px',
+ right: '0px'
+ });
+ }
+ if (this.summary.length > 0) {
+ summary.css({
+ bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) ) + 'px',
+ left: '0px',
+ right: '0px'
+ });
+ }
+ body.css({
+ top: ( 0 + (this.show.header ? w2utils.getSize(header, 'height') : 0) + (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0) ) + 'px',
+ bottom: ( 0 + (this.show.footer ? w2utils.getSize(footer, 'height') : 0) + (this.summary.length > 0 ? w2utils.getSize(summary, 'height') : 0) ) + 'px',
+ left: '0px',
+ right: '0px'
+ });
+ },
+
+ resizeRecords: function () {
+ var obj = this;
+ // remove empty records
+ $(this.box).find('.w2ui-empty-record').remove();
+ // -- Calculate Column size in PX
+ var box = $(this.box);
+ var grid = $(this.box).find('> div');
+ var header = $('#grid_'+ this.name +'_header');
+ var toolbar = $('#grid_'+ this.name +'_toolbar');
+ var summary = $('#grid_'+ this.name +'_summary');
+ var footer = $('#grid_'+ this.name +'_footer');
+ var body = $('#grid_'+ this.name +'_body');
+ var columns = $('#grid_'+ this.name +'_columns');
+ var records = $('#grid_'+ this.name +'_records');
+
+ // body might be expanded by data
+ if (!this.fixedBody) {
+ // allow it to render records, then resize
+ setTimeout(function () {
+ var calculatedHeight = w2utils.getSize(columns, 'height')
+ + w2utils.getSize($('#grid_'+ obj.name +'_records table'), 'height');
+ obj.height = calculatedHeight
+ + w2utils.getSize(grid, '+height')
+ + (obj.show.header ? w2utils.getSize(header, 'height') : 0)
+ + (obj.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0)
+ + (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0)
+ + (obj.show.footer ? w2utils.getSize(footer, 'height') : 0);
+ grid.css('height', obj.height);
+ body.css('height', calculatedHeight);
+ box.css('height', w2utils.getSize(grid, 'height') + w2utils.getSize(box, '+height'));
+ }, 1);
+ } else {
+ // fixed body height
+ var calculatedHeight = grid.height()
+ - (this.show.header ? w2utils.getSize(header, 'height') : 0)
+ - (this.show.toolbar ? w2utils.getSize(toolbar, 'height') : 0)
+ - (summary.css('display') != 'none' ? w2utils.getSize(summary, 'height') : 0)
+ - (this.show.footer ? w2utils.getSize(footer, 'height') : 0);
+ body.css('height', calculatedHeight);
+ }
+
+ // check overflow
+ var bodyOverflowX = false;
+ var bodyOverflowY = false;
+ if (body.width() < $(records).find('>table').width()) bodyOverflowX = true;
+ if (body.height() - columns.height() < $(records).find('>table').height() + (bodyOverflowX ? w2utils.scrollBarSize() : 0)) bodyOverflowY = true;
+ if (!this.fixedBody) { bodyOverflowY = false; bodyOverflowX = false; }
+ if (bodyOverflowX || bodyOverflowY) {
+ columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show();
+ records.css({
+ top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px',
+ "-webkit-overflow-scrolling": "touch",
+ "overflow-x": (bodyOverflowX ? 'auto' : 'hidden'),
+ "overflow-y": (bodyOverflowY ? 'auto' : 'hidden') });
+ } else {
+ columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').hide();
+ records.css({
+ top: ((this.columnGroups.length > 0 && this.show.columns ? 1 : 0) + w2utils.getSize(columns, 'height')) +'px',
+ overflow: 'hidden'
+ });
+ if (records.length > 0) { this.last.scrollTop = 0; this.last.scrollLeft = 0; } // if no scrollbars, always show top
+ }
+ if (this.show.emptyRecords && !bodyOverflowY) {
+ var max = Math.floor(records.height() / this.recordHeight) + 1;
+ if (this.fixedBody) {
+ for (var di = this.buffered; di <= max; di++) {
+ var html = '';
+ html += '
';
+ if (this.show.lineNumbers) html += '
';
+ if (this.show.selectColumn) html += '
';
+ if (this.show.expandColumn) html += '
';
+ var j = 0;
+ while (true && this.columns.length > 0) {
+ var col = this.columns[j];
+ if (col.hidden) { j++; if (typeof this.columns[j] == 'undefined') break; else continue; }
+ html += '
';
+ j++;
+ if (typeof this.columns[j] == 'undefined') break;
+ }
+ html += '
';
+ html += '
';
+ $('#grid_'+ this.name +'_records > table').append(html);
+ }
+ }
+ }
+ if (body.length > 0) {
+ var width_max = parseInt(body.width())
+ - (bodyOverflowY ? w2utils.scrollBarSize() : 0)
+ - (this.show.lineNumbers ? 34 : 0)
+ - (this.show.selectColumn ? 26 : 0)
+ - (this.show.expandColumn ? 26 : 0);
+ var width_box = width_max;
+ var percent = 0;
+ // gridMinWidth processiong
+ var restart = false;
+ for (var i=0; i width_box && col.hidden !== true) {
+ col.hidden = true;
+ restart = true;
+ }
+ if (col.gridMinWidth < width_box && col.hidden === true) {
+ col.hidden = false;
+ restart = true;
+ }
+ }
+ }
+ if (restart === true) {
+ this.refresh();
+ return;
+ }
+ // assign PX column s
+ for (var i=0; i 0) {
+ for (var i=0; i parseInt(col.max)) col.sizeCalculated = col.max + 'px';
+ width_cols += parseInt(col.sizeCalculated);
+ }
+ var width_diff = parseInt(width_box) - parseInt(width_cols);
+ if (width_diff > 0 && percent > 0) {
+ var i = 0;
+ while (true) {
+ var col = this.columns[i];
+ if (typeof col == 'undefined') { i = 0; continue; }
+ if (col.hidden || col.sizeType == 'px') { i++; continue; }
+ col.sizeCalculated = (parseInt(col.sizeCalculated) + 1) + 'px';
+ width_diff--;
+ if (width_diff == 0) break;
+ i++;
+ }
+ } else if (width_diff > 0) {
+ columns.find('> table > tbody > tr:nth-child(1) td.w2ui-head-last').css('width', w2utils.scrollBarSize()).show();
+ }
+ // resize columns
+ columns.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) {
+ var ind = $(el).attr('col');
+ if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated);
+ // last column
+ if ($(el).hasClass('w2ui-head-last')) {
+ $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px');
+ }
+ });
+ // if there are column groups - hide first row (needed for sizing)
+ if (columns.find('> table > tbody > tr').length == 3) {
+ columns.find('> table > tbody > tr:nth-child(1) td').html('').css({
+ 'height' : '0px',
+ 'border' : '0px',
+ 'padding' : '0px',
+ 'margin' : '0px'
+ });
+ }
+ // resize records
+ records.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) {
+ var ind = $(el).attr('col');
+ if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated);
+ // last column
+ if ($(el).hasClass('w2ui-grid-data-last')) {
+ $(el).css('width', (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px');
+ }
+ });
+ // resize summary
+ summary.find('> table > tbody > tr:nth-child(1) td').each(function (index, el) {
+ var ind = $(el).attr('col');
+ if (typeof ind != 'undefined' && obj.columns[ind]) $(el).css('width', obj.columns[ind].sizeCalculated);
+ // last column
+ if ($(el).hasClass('w2ui-grid-data-last')) {
+ $(el).css('width', w2utils.scrollBarSize() + (width_diff > 0 && percent == 0 ? width_diff : 0) + 'px');
+ }
+ });
+ this.initResize();
+ this.refreshRanges();
+ // apply last scroll if any
+ if (this.last.scrollTop != '' && records.length > 0) {
+ columns.prop('scrollLeft', this.last.scrollLeft);
+ records.prop('scrollTop', this.last.scrollTop);
+ records.prop('scrollLeft', this.last.scrollLeft);
+ }
+ },
+
+ getSearchesHTML: function () {
+ var html = '
';
+ var showBtn = false;
+ for (var i = 0; i < this.searches.length; i++) {
+ var s = this.searches[i];
+ if (s.hidden) continue;
+ var btn = '';
+ if (showBtn == false) {
+ btn = '';
+ showBtn = true;
+ }
+ if (typeof s.inTag == 'undefined') s.inTag = '';
+ if (typeof s.outTag == 'undefined') s.outTag = '';
+ if (typeof s.type == 'undefined') s.type = 'text';
+ if (s.type == 'text') {
+ var operator = '';
+ }
+ if (s.type == 'int' || s.type == 'float' || s.type == 'date') {
+ var operator = '';
+ }
+ if (s.type == 'list') {
+ var operator = 'is ';
+ }
+ html += '
'+
+ '
'+ btn +'
' +
+ '
'+ s.caption +'
' +
+ '
'+ operator +'
'+
+ '
';
+
+ switch (s.type) {
+ case 'alphaNumeric':
+ case 'text':
+ html += '';
+ break;
+
+ case 'int':
+ case 'float':
+ case 'hex':
+ case 'money':
+ case 'date':
+ html += ''+
+ ''+
+ ' - '+
+ '';
+ break;
+
+ case 'list':
+ html += '';
+ break;
+
+ }
+ html += s.outTag +
+ '
' +
+ '
';
+ }
+ html += '
'+
+ '
'+
+ '
'+
+ ' '+
+ ' '+
+ '
'+
+ '
'+
+ '
';
+ return html;
+ },
+
+ getColumnsHTML: function () {
+ var obj = this;
+ var html = '';
+ if (this.show.columnHeaders) {
+ if (this.columnGroups.length > 0) {
+ html = getColumns(true) + getGroups() + getColumns(false);
+ } else {
+ html = getColumns(true);
+ }
+ }
+ return html;
+
+ function getGroups () {
+ var html = '
';
+ // add empty group at the end
+ if (obj.columnGroups[obj.columnGroups.length-1].caption != '') obj.columnGroups.push({ caption: '' });
+
+ if (obj.show.lineNumbers) {
+ html += '
'+
+ '
'+
+ '
';
+ }
+ if (obj.show.selectColumn) {
+ html += '
'+
+ '
'+
+ '
';
+ }
+ if (obj.show.expandColumn) {
+ html += '
'+
+ '
'+
+ '
';
+ }
+ var ii = 0;
+ for (var i=0; i';
+ }
+ html += '
';
+ return html;
+ }
+ },
+
+ getRecordsHTML: function () {
+ // larget number works better with chrome, smaller with FF.
+ if (this.buffered > 300) this.show_extra = 30; else this.show_extra = 300;
+ var records = $('#grid_'+ this.name +'_records');
+ var limit = Math.floor(records.height() / this.recordHeight) + this.show_extra + 1;
+ if (!this.fixedBody) limit = this.buffered;
+ // always need first record for resizing purposes
+ var html = '
' + this.getRecordHTML(-1, 0);
+ // first empty row with height
+ html += '
'+
+ '
'+
+ '
';
+ for (var i = 0; i < limit; i++) {
+ html += this.getRecordHTML(i, i+1);
+ }
+ html += '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
';
+ this.last.range_start = 0;
+ this.last.range_end = limit;
+ return html;
+ },
+
+ getSummaryHTML: function () {
+ if (this.summary.length == 0) return;
+ var html = '
';
+ for (var i = 0; i < this.summary.length; i++) {
+ html += this.getRecordHTML(i, i+1, true);
+ }
+ html += '
';
+ return html;
+ },
+
+ scroll: function (event) {
+ var time = (new Date()).getTime();
+ var obj = this;
+ var records = $('#grid_'+ this.name +'_records');
+ if (this.records.length == 0 || records.length == 0 || records.height() == 0) return;
+ if (this.buffered > 300) this.show_extra = 30; else this.show_extra = 300;
+ // need this to enable scrolling when this.limit < then a screen can fit
+ if (records.height() < this.buffered * this.recordHeight && records.css('overflow-y') == 'hidden') {
+ if (this.total > 0) this.refresh();
+ return;
+ }
+ // update footer
+ var t1 = Math.floor(records[0].scrollTop / this.recordHeight + 1);
+ var t2 = Math.floor(records[0].scrollTop / this.recordHeight + 1) + Math.round(records.height() / this.recordHeight);
+ if (t1 > this.buffered) t1 = this.buffered;
+ if (t2 > this.buffered) t2 = this.buffered;
+ var url = (typeof this.url != 'object' ? this.url : this.url.get);
+ $('#grid_'+ this.name + '_footer .w2ui-footer-right').html(w2utils.formatNumber(this.offset + t1) + '-' + w2utils.formatNumber(this.offset + t2) + ' ' + w2utils.lang('of') + ' ' + w2utils.formatNumber(this.total) +
+ (url ? ' ('+ w2utils.lang('buffered') + ' '+ w2utils.formatNumber(this.buffered) + (this.offset > 0 ? ', skip ' + w2utils.formatNumber(this.offset) : '') + ')' : '')
+ );
+ // only for local data source, else no extra records loaded
+ if (!url && (!this.fixedBody || this.total <= 300)) return;
+ // regular processing
+ var start = Math.floor(records[0].scrollTop / this.recordHeight) - this.show_extra;
+ var end = start + Math.floor(records.height() / this.recordHeight) + this.show_extra * 2 + 1;
+ // var div = start - this.last.range_start;
+ if (start < 1) start = 1;
+ if (end > this.total) end = this.total;
+ var tr1 = records.find('#grid_'+ this.name +'_rec_top');
+ var tr2 = records.find('#grid_'+ this.name +'_rec_bottom');
+ // if row is expanded
+ if (String(tr1.next().prop('id')).indexOf('_expanded_row') != -1) tr1.next().remove();
+ if (String(tr2.prev().prop('id')).indexOf('_expanded_row') != -1) tr2.prev().remove();
+ var first = parseInt(tr1.next().attr('line'));
+ var last = parseInt(tr2.prev().attr('line'));
+ //$('#log').html('buffer: '+ this.buffered +' start-end: ' + start + '-'+ end + ' ===> first-last: ' + first + '-' + last);
+ if (first < start || first == 1 || this.last.pull_refresh) { // scroll down
+ //console.log('end', end, 'last', last, 'show_extre', this.show_extra, this.last.pull_refresh);
+ if (end <= last + this.show_extra - 2 && end != this.total) return;
+ this.last.pull_refresh = false;
+ // remove from top
+ while (true) {
+ var tmp = records.find('#grid_'+ this.name +'_rec_top').next();
+ if (tmp.attr('line') == 'bottom') break;
+ if (parseInt(tmp.attr('line')) < start) tmp.remove(); else break;
+ }
+ // add at bottom
+ var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev();
+ var rec_start = tmp.attr('line');
+ if (rec_start == 'top') rec_start = start;
+ for (var i = parseInt(rec_start) + 1; i <= end; i++) {
+ if (!this.records[i-1]) continue;
+ if (this.records[i-1].expanded === true) this.records[i-1].expanded = false;
+ tr2.before(this.getRecordHTML(i-1, i));
+ }
+ markSearch();
+ setTimeout(function() { obj.refreshRanges(); }, 0);
+ } else { // scroll up
+ if (start >= first - this.show_extra + 2 && start > 1) return;
+ // remove from bottom
+ while (true) {
+ var tmp = records.find('#grid_'+ this.name +'_rec_bottom').prev();
+ if (tmp.attr('line') == 'top') break;
+ if (parseInt(tmp.attr('line')) > end) tmp.remove(); else break;
+ }
+ // add at top
+ var tmp = records.find('#grid_'+ this.name +'_rec_top').next();
+ var rec_start = tmp.attr('line');
+ if (rec_start == 'bottom') rec_start = end;
+ for (var i = parseInt(rec_start) - 1; i >= start; i--) {
+ if (!this.records[i-1]) continue;
+ if (this.records[i-1].expanded === true) this.records[i-1].expanded = false;
+ tr1.after(this.getRecordHTML(i-1, i));
+ }
+ markSearch();
+ setTimeout(function() { obj.refreshRanges(); }, 0);
+ }
+ // first/last row size
+ var h1 = (start - 1) * obj.recordHeight;
+ var h2 = (this.buffered - end) * obj.recordHeight;
+ if (h2 < 0) h2 = 0;
+ tr1.css('height', h1 + 'px');
+ tr2.css('height', h2 + 'px');
+ obj.last.range_start = start;
+ obj.last.range_end = end;
+ // load more if needed
+ var s = Math.floor(records[0].scrollTop / this.recordHeight);
+ var e = s + Math.floor(records.height() / this.recordHeight);
+ if (e + 10 > this.buffered && this.last.pull_more !== true && this.buffered < this.total - this.offset) {
+ if (this.autoLoad === true) {
+ this.last.pull_more = true;
+ this.last.xhr_offset += this.limit;
+ this.request('get-records');
+ } else {
+ var more = $('#grid_'+ this.name +'_rec_more');
+ if (more.css('display') == 'none') {
+ more.show()
+ .on('click', function () {
+ $(this).find('td').html('
';
+ }
+ }
+ } else {
+ if (!this.show.recordTitles) {
+ var data = '
'+ data +'
';
+ } else {
+ // title overwrite
+ var title = String(data).replace(/"/g, "''");
+ if (typeof col.title != 'undefined') {
+ if (typeof col.title == 'function') title = col.title.call(this, record, ind, col_ind);
+ if (typeof col.title == 'string') title = col.title;
+ }
+ var data = '
'+ data +'
';
+ }
+ }
+ if (data == null || typeof data == 'undefined') data = '';
+ return data;
+ },
+
+ getFooterHTML: function () {
+ return '
'+
+ ' '+
+ ' '+
+ ' '+
+ '
';
+ },
+
+ status: function (msg) {
+ if (typeof msg != 'undefined') {
+ $('#grid_'+ this.name +'_footer').find('.w2ui-footer-left').html(msg);
+ } else {
+ // show number of selected
+ var msgLeft = '';
+ var sel = this.getSelection();
+ if (sel.length > 0) {
+ msgLeft = String(sel.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") + ' ' + w2utils.lang('selected');
+ var tmp = sel[0];
+ if (typeof tmp == 'object') tmp = tmp.recid + ', '+ w2utils.lang('Column') +': '+ tmp.column;
+ if (sel.length == 1) msgLeft = w2utils.lang('Record ID') + ': '+ tmp + ' ';
+ }
+ $('#grid_'+ this.name +'_footer .w2ui-footer-left').html(msgLeft);
+ // toolbar
+ if (sel.length == 1) this.toolbar.enable('edit'); else this.toolbar.disable('edit');
+ if (sel.length >= 1) this.toolbar.enable('delete'); else this.toolbar.disable('delete');
+ }
+ },
+
+ lock: function (msg, showSpinner) {
+ var box = $(this.box).find('> div:first-child');
+ setTimeout(function () { w2utils.lock(box, msg, showSpinner); }, 10);
+ },
+
+ unlock: function () {
+ var box = this.box;
+ setTimeout(function () { w2utils.unlock(box); }, 25); // needed timer so if server fast, it will not flash
+ },
+
+ parseField: function (obj, field) {
+ var val = '';
+ try { // need this to make sure no error in fields
+ val = obj;
+ var tmp = String(field).split('.');
+ for (var i in tmp) {
+ val = val[tmp[i]];
+ }
+ } catch (event) {
+ val = '';
+ }
+ return val;
+ }
+ }
+
+ $.extend(w2grid.prototype, w2utils.event);
+ w2obj.grid = w2grid;
+})();
+/************************************************************************
+* Library: Web 2.0 UI for jQuery (using prototypical inheritance)
+* - Following objects defined
+* - w2layout - layout widget
+* - $().w2layout - jQuery wrapper
+* - Dependencies: jQuery, w2utils, w2toolbar, w2tabs
+*
+* == NICE TO HAVE ==
+* - onResize for the panel
+* - problem with layout.html (see in 1.3)
+* - add panel title
+*
+************************************************************************/
+
+(function () {
+ var w2layout = function (options) {
+ this.box = null // DOM Element that holds the element
+ this.name = null; // unique name for w2ui
+ this.panels = [];
+ this.tmp = {};
+
+ this.padding = 1; // panel padding
+ this.resizer = 4; // resizer width or height
+ this.style = '';
+
+ this.onShow = null;
+ this.onHide = null;
+ this.onResizing = null;
+ this.onRender = null;
+ this.onRefresh = null;
+ this.onResize = null;
+ this.onDestroy = null
+
+ $.extend(true, this, w2obj.layout, options);
+ };
+
+ // ====================================================
+ // -- Registers as a jQuery plugin
+
+ $.fn.w2layout = function(method) {
+ if (typeof method === 'object' || !method ) {
+ // check required parameters
+ if (!method || typeof method.name == 'undefined') {
+ console.log('ERROR: The parameter "name" is required but not supplied in $().w2layout().');
+ return;
+ }
+ if (typeof w2ui[method.name] != 'undefined') {
+ console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+ method.name +').');
+ return;
+ }
+ if (!w2utils.isAlphaNumeric(method.name)) {
+ console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');
+ return;
+ }
+ var panels = method.panels;
+ var object = new w2layout(method);
+ $.extend(object, { handlers: [], panels: [] });
+ // add defined panels panels
+ for (var p in panels) {
+ object.panels[p] = $.extend(true, {}, w2layout.prototype.panel, panels[p]);
+ if ($.isPlainObject(object.panels[p].tabs) || $.isArray(object.panels[p].tabs)) initTabs(object, panels[p].type);
+ if ($.isPlainObject(object.panels[p].toolbar) || $.isArray(object.panels[p].toolbar)) initToolbar(object, panels[p].type);
+ }
+ // add all other panels
+ for (var p in { 'top':'', 'left':'', 'main':'', 'preview':'', 'right':'', 'bottom':'' }) {
+ if (object.get(p) != null) continue;
+ object.panels[p] = $.extend(true, {}, w2layout.prototype.panel, { type: p, hidden: true, size: 50 });
+ }
+
+ if ($(this).length > 0) {
+ object.render($(this)[0]);
+ }
+ w2ui[object.name] = object;
+ return object;
+
+ } else if (w2ui[$(this).attr('name')]) {
+ var obj = w2ui[$(this).attr('name')];
+ obj[method].apply(obj, Array.prototype.slice.call(arguments, 1));
+ return this;
+ } else {
+ console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2layout' );
+ }
+
+ function initTabs(object, panel, tabs) {
+ var pan = object.get(panel);
+ if (pan != null && typeof tabs == 'undefined') tabs = pan.tabs;
+ if (pan == null || tabs == null) return false;
+ // instanciate tabs
+ if ($.isArray(tabs)) tabs = { tabs: tabs };
+ $().w2destroy(object.name + '_' + panel + '_tabs'); // destroy if existed
+ pan.tabs = $().w2tabs($.extend({}, tabs, { owner: object, name: object.name + '_' + panel + '_tabs' }));
+ pan.show.tabs = true;
+ return true;
+ }
+
+ function initToolbar(object, panel, toolbar) {
+ var pan = object.get(panel);
+ if (pan != null && typeof toolbar == 'undefined') toolbar = pan.toolbar;
+ if (pan == null || toolbar == null) return false;
+ // instanciate toolbar
+ if ($.isArray(toolbar)) toolbar = { items: toolbar };
+ $().w2destroy(object.name + '_' + panel + '_toolbar'); // destroy if existed
+ pan.toolbar = $().w2toolbar($.extend({}, toolbar, { owner: object, name: object.name + '_' + panel + '_toolbar' }));
+ pan.show.toolbar = true;
+ return true;
+ }
+ };
+
+ // ====================================================
+ // -- Implementation of core functionality
+
+ w2layout.prototype = {
+ // default setting for a panel
+ panel: {
+ type : null, // left, right, top, bottom
+ size : 100, // width or height depending on panel name
+ minSize : 20,
+ hidden : false,
+ resizable : false,
+ overflow : 'auto',
+ style : '',
+ content : '', // can be String or Object with .render(box) method
+ tabs : null,
+ toolbar : null,
+ width : null, // read only
+ height : null, // read only
+ show : {
+ toolbar : false,
+ tabs : false
+ },
+ onRefresh : null,
+ onShow : null,
+ onHide : null
+ },
+
+ // alias for content
+ html: function (panel, data, transition) {
+ return this.content(panel, data, transition);
+ },
+
+ content: function (panel, data, transition) {
+ var obj = this;
+ var p = this.get(panel);
+ if (panel == 'css') {
+ $('#layout_'+ obj.name +'_panel_css').html('');
+ return true;
+ }
+ if (p == null) return false;
+ if ($('#layout_'+ this.name + '_panel2_'+ p.type).length > 0) return false;
+ $('#layout_'+ this.name + '_panel_'+ p.type).scrollTop(0);
+ if (data == null || typeof data == 'undefined') {
+ return p.content;
+ } else {
+ if (data instanceof jQuery) {
+ console.log('ERROR: You can not pass jQuery object to w2layout.content() method');
+ return false;
+ }
+ // remove foreign classes and styles
+ var tmp = $('#'+ 'layout_'+ this.name + '_panel_'+ panel + ' > .w2ui-panel-content');
+ var panelTop = $(tmp).position().top;
+ tmp.attr('class', 'w2ui-panel-content');
+ if (tmp.length > 0 && typeof p.style != 'undefined') tmp[0].style.cssText = p.style;
+ if (p.content == '') {
+ p.content = data;
+ if (!p.hidden) this.refresh(panel);
+ } else {
+ p.content = data;
+ if (!p.hidden) {
+ if (transition != null && transition != '' && typeof transition != 'undefined') {
+ // apply transition
+ var nm = 'layout_'+ this.name + '_panel_'+ p.type;
+ var div1 = $('#'+ nm + ' > .w2ui-panel-content');
+ div1.after('');
+ var div2 = $('#'+ nm + ' > .w2ui-panel-content.new-panel');
+ div1.css('top', panelTop);
+ div2.css('top', panelTop);
+ if (typeof data == 'object') {
+ data.box = div2[0]; // do not do .render(box);
+ data.render();
+ } else {
+ div2.html(data);
+ }
+ w2utils.transition(div1[0], div2[0], transition, function () {
+ div1.remove();
+ div2.removeClass('new-panel');
+ div2.css('overflow', p.overflow);
+ // IE Hack
+ if (window.navigator.userAgent.indexOf('MSIE')) setTimeout(function () { obj.resize(); }, 100);
+ });
+ } else {
+ if (!p.hidden) this.refresh(panel);
+ }
+ }
+ }
+ }
+ // IE Hack
+ if (window.navigator.userAgent.indexOf('MSIE')) setTimeout(function () { obj.resize(); }, 100);
+ return true;
+ },
+
+ load: function (panel, url, transition, onLoad) {
+ var obj = this;
+ if (panel == 'css') {
+ $.get(url, function (data, status, xhr) {
+ obj.content(panel, xhr.responseText);
+ if (onLoad) onLoad();
+ });
+ return true;
+ }
+ if (this.get(panel) != null) {
+ $.get(url, function (data, status, xhr) {
+ obj.content(panel, xhr.responseText, transition);
+ if (onLoad) onLoad();
+ // IE Hack
+ if (window.navigator.userAgent.indexOf('MSIE')) setTimeout(function () { obj.resize(); }, 100);
+ });
+ return true;
+ }
+ return false;
+ },
+
+ sizeTo: function (panel, size) {
+ var obj = this;
+ var pan = obj.get(panel);
+ if (pan == null) return false;
+ // resize
+ $(obj.box).find(' > div .w2ui-panel').css({
+ '-webkit-transition': '.35s',
+ '-moz-transition' : '.35s',
+ '-ms-transition' : '.35s',
+ '-o-transition' : '.35s'
+ });
+ setTimeout(function () {
+ obj.set(panel, { size: size });
+ }, 1);
+ // clean
+ setTimeout(function () {
+ $(obj.box).find(' > div .w2ui-panel').css({
+ '-webkit-transition': '0s',
+ '-moz-transition' : '0s',
+ '-ms-transition' : '0s',
+ '-o-transition' : '0s'
+ });
+ obj.resize();
+ }, 500);
+ return true;
+ },
+
+ show: function (panel, immediate) {
+ var obj = this;
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'show', target: panel, object: this.get(panel), immediate: immediate });
+ if (eventData.isCancelled === true) return false;
+
+ var p = obj.get(panel);
+ if (p == null) return false;
+ p.hidden = false;
+ if (immediate === true) {
+ $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '1' });
+ if (p.resizabled) $('#layout_'+ obj.name +'_resizer_'+panel).show();
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ obj.resize();
+ } else {
+ if (p.resizabled) $('#layout_'+ obj.name +'_resizer_'+panel).show();
+ // resize
+ $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' });
+ $(obj.box).find(' > div .w2ui-panel').css({
+ '-webkit-transition': '.2s',
+ '-moz-transition' : '.2s',
+ '-ms-transition' : '.2s',
+ '-o-transition' : '.2s'
+ });
+ setTimeout(function () { obj.resize(); }, 1);
+ // show
+ setTimeout(function() {
+ $('#layout_'+ obj.name +'_panel_'+ panel).css({ 'opacity': '1' });
+ }, 250);
+ // clean
+ setTimeout(function () {
+ $(obj.box).find(' > div .w2ui-panel').css({
+ '-webkit-transition': '0s',
+ '-moz-transition' : '0s',
+ '-ms-transition' : '0s',
+ '-o-transition' : '0s'
+ });
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ obj.resize();
+ }, 500);
+ }
+ return true;
+ },
+
+ hide: function (panel, immediate) {
+ var obj = this;
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'hide', target: panel, object: this.get(panel), immediate: immediate });
+ if (eventData.isCancelled === true) return false;
+
+ var p = obj.get(panel);
+ if (p == null) return false;
+ p.hidden = true;
+ if (immediate === true) {
+ $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' });
+ $('#layout_'+ obj.name +'_resizer_'+panel).hide();
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ obj.resize();
+ } else {
+ $('#layout_'+ obj.name +'_resizer_'+panel).hide();
+ // hide
+ $(obj.box).find(' > div .w2ui-panel').css({
+ '-webkit-transition': '.2s',
+ '-moz-transition' : '.2s',
+ '-ms-transition' : '.2s',
+ '-o-transition' : '.2s'
+ });
+ $('#layout_'+ obj.name +'_panel_'+panel).css({ 'opacity': '0' });
+ setTimeout(function () { obj.resize(); }, 1);
+ // clean
+ setTimeout(function () {
+ $(obj.box).find(' > div .w2ui-panel').css({
+ '-webkit-transition': '0s',
+ '-moz-transition' : '0s',
+ '-ms-transition' : '0s',
+ '-o-transition' : '0s'
+ });
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ obj.resize();
+ }, 500);
+ }
+ return true;
+ },
+
+ toggle: function (panel, immediate) {
+ var p = this.get(panel);
+ if (p == null) return false;
+ if (p.hidden) return this.show(panel, immediate); else return this.hide(panel, immediate);
+ },
+
+ set: function (panel, options) {
+ var obj = this.get(panel, true);
+ if (obj == null) return false;
+ $.extend(this.panels[obj], options);
+ this.refresh(panel);
+ this.resize(); // resize is needed when panel size is changed
+ return true;
+ },
+
+ get: function (panel, returnIndex) {
+ var obj = null;
+ for (var p in this.panels) {
+ if (this.panels[p].type == panel) {
+ if (returnIndex === true) return p; else return this.panels[p];
+ }
+ }
+ return null;
+ },
+
+ el: function (panel) {
+ var el = $('#layout_'+ this.name +'_panel_'+ panel +' .w2ui-panel-content');
+ if (el.length != 1) return null;
+ return el[0];
+ },
+
+ hideToolbar: function (panel) {
+ var pan = this.get(panel);
+ if (!pan) return;
+ pan.show.toolbar = false;
+ $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-toolbar').hide();
+ this.resize();
+ },
+
+ showToolbar: function (panel) {
+ var pan = this.get(panel);
+ if (!pan) return;
+ pan.show.toolbar = true;
+ $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-toolbar').show();
+ this.resize();
+ },
+
+ toggleToolbar: function (panel) {
+ var pan = this.get(panel);
+ if (!pan) return;
+ if (pan.show.toolbar) this.hideToolbar(panel); else this.showToolbar(panel);
+ },
+
+ hideTabs: function (panel) {
+ var pan = this.get(panel);
+ if (!pan) return;
+ pan.show.tabs = false;
+ $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-tabs').hide();
+ this.resize();
+ },
+
+ showTabs: function (panel) {
+ var pan = this.get(panel);
+ if (!pan) return;
+ pan.show.tabs = true;
+ $('#layout_'+ this.name +'_panel_'+ panel +' > .w2ui-panel-tabs').show();
+ this.resize();
+ },
+
+ toggleTabs: function (panel) {
+ var pan = this.get(panel);
+ if (!pan) return;
+ if (pan.show.tabs) this.hideTabs(panel); else this.showTabs(panel);
+ },
+
+ render: function (box) {
+ var obj = this;
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ var time = (new Date()).getTime();
+ // event before
+ var eventData = obj.trigger({ phase: 'before', type: 'render', target: obj.name, box: box });
+ if (eventData.isCancelled === true) return false;
+
+ if (typeof box != 'undefined' && box != null) {
+ if ($(obj.box).find('#layout_'+ obj.name +'_panel_main').length > 0) {
+ $(obj.box)
+ .removeAttr('name')
+ .removeClass('w2ui-layout')
+ .html('');
+ }
+ obj.box = box;
+ }
+ if (!obj.box) return false;
+ $(obj.box)
+ .attr('name', obj.name)
+ .addClass('w2ui-layout')
+ .html('');
+ if ($(obj.box).length > 0) $(obj.box)[0].style.cssText += obj.style;
+ // create all panels
+ var tmp = ['top', 'left', 'main', 'preview', 'right', 'bottom'];
+ for (var t in tmp) {
+ var pan = obj.get(tmp[t]);
+ var html = '
'+
+ ' '+
+ ' '+
+ ' '+
+ '
'+
+ '';
+ $(obj.box).find(' > div').append(html);
+ // tabs are rendered in refresh()
+ }
+ $(obj.box).find(' > div')
+ .append(' drag
+ if (obj.tmp.resizing == 'left' && (obj.get('left').minSize - obj.tmp.resize.div_x > obj.get('left').width)) {
+ obj.tmp.resize.div_x = obj.get('left').minSize - obj.get('left').width;
+ }
+ if (obj.tmp.resize.type == 'left' && (obj.get('main').minSize + obj.tmp.resize.div_x > obj.get('main').width)) {
+ obj.tmp.resize.div_x = obj.get('main').width - obj.get('main').minSize;
+ }
+ // right panel -> drag
+ if (obj.tmp.resize.type == 'right' && (obj.get('right').minSize + obj.tmp.resize.div_x > obj.get('right').width)) {
+ obj.tmp.resize.div_x = obj.get('right').width - obj.get('right').minSize;
+ }
+ if (obj.tmp.resize.type == 'right' && (obj.get('main').minSize - obj.tmp.resize.div_x > obj.get('main').width)) {
+ obj.tmp.resize.div_x = obj.get('main').minSize - obj.get('main').width;
+ }
+ // top panel -> drag
+ if (obj.tmp.resize.type == 'top' && (obj.get('top').minSize - obj.tmp.resize.div_y > obj.get('top').height)) {
+ obj.tmp.resize.div_y = obj.get('top').minSize - obj.get('top').height;
+ }
+ if (obj.tmp.resize.type == 'top' && (obj.get('main').minSize + obj.tmp.resize.div_y > obj.get('main').height)) {
+ obj.tmp.resize.div_y = obj.get('main').height - obj.get('main').minSize;
+ }
+ // bottom panel -> drag
+ if (obj.tmp.resize.type == 'bottom' && (obj.get('bottom').minSize + obj.tmp.resize.div_y > obj.get('bottom').height)) {
+ obj.tmp.resize.div_y = obj.get('bottom').height - obj.get('bottom').minSize;
+ }
+ if (obj.tmp.resize.type == 'bottom' && (obj.get('main').minSize - obj.tmp.resize.div_y > obj.get('main').height)) {
+ obj.tmp.resize.div_y = obj.get('main').minSize - obj.get('main').height;
+ }
+ // preview panel -> drag
+ if (obj.tmp.resize.type == 'preview' && (obj.get('preview').minSize + obj.tmp.resize.div_y > obj.get('preview').height)) {
+ obj.tmp.resize.div_y = obj.get('preview').height - obj.get('preview').minSize;
+ }
+ if (obj.tmp.resize.type == 'preview' && (obj.get('main').minSize - obj.tmp.resize.div_y > obj.get('main').height)) {
+ obj.tmp.resize.div_y = obj.get('main').minSize - obj.get('main').height;
+ }
+ switch(obj.tmp.resize.type) {
+ case 'top':
+ case 'preview':
+ case 'bottom':
+ obj.tmp.resize.div_x = 0;
+ if (p.length > 0) p[0].style.top = (obj.tmp.resize.value + obj.tmp.resize.div_y) + 'px';
+ break;
+ case 'left':
+ case 'right':
+ obj.tmp.resize.div_y = 0;
+ if (p.length > 0) p[0].style.left = (obj.tmp.resize.value + obj.tmp.resize.div_x) + 'px';
+ break;
+ }
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ }
+ },
+
+ refresh: function (panel) {
+ var obj = this;
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ if (typeof panel == 'undefined') panel = null;
+ var time = (new Date()).getTime();
+ // event before
+ var eventData = obj.trigger({ phase: 'before', type: 'refresh', target: (typeof panel != 'undefined' ? panel : obj.name), object: obj.get(panel) });
+ if (eventData.isCancelled === true) return;
+
+ // obj.unlock(panel);
+ if (panel != null && typeof panel != 'undefined') {
+ var p = obj.get(panel);
+ if (p == null) return;
+ // apply properties to the panel
+ var el = $('#layout_'+ obj.name +'_panel_'+ panel).css({ display: p.hidden ? 'none' : 'block' });
+ el = el.find('.w2ui-panel-content');
+ if (el.length > 0) el.css('overflow', p.overflow)[0].style.cssText += ';' + p.style;
+ if (p.resizable === true) {
+ $('#layout_'+ this.name +'_resizer_'+ panel).show();
+ } else {
+ $('#layout_'+ this.name +'_resizer_'+ panel).hide();
+ }
+ // insert content
+ if (typeof p.content == 'object' && p.content.render) {
+ p.content.box = $('#layout_'+ obj.name + '_panel_'+ p.type +' > .w2ui-panel-content')[0];
+ p.content.render(); // do not do .render(box);
+ } else {
+ $('#layout_'+ obj.name + '_panel_'+ p.type +' > .w2ui-panel-content').html(p.content);
+ }
+ // if there are tabs and/or toolbar - render it
+ var tmp = $(obj.box).find('#layout_'+ obj.name + '_panel_'+ p.type +' .w2ui-panel-tabs');
+ if (p.show.tabs) {
+ if (tmp.find('[name='+ p.tabs.name +']').length == 0 && p.tabs != null) tmp.w2render(p.tabs); else p.tabs.refresh();
+ } else {
+ tmp.html('').removeClass('w2ui-tabs').hide();
+ }
+ var tmp = $(obj.box).find('#layout_'+ obj.name + '_panel_'+ p.type +' .w2ui-panel-toolbar');
+ if (p.show.toolbar) {
+ if (tmp.find('[name='+ p.toolbar.name +']').length == 0 && p.toolbar != null) tmp.w2render(p.toolbar); else p.toolbar.refresh();
+ } else {
+ tmp.html('').removeClass('w2ui-toolbar').hide();
+ }
+ } else {
+ if ($('#layout_' +obj.name +'_panel_main').length <= 0) {
+ obj.render();
+ return;
+ }
+ obj.resize();
+ // refresh all of them
+ for (var p in this.panels) { obj.refresh(this.panels[p].type); }
+ }
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ return (new Date()).getTime() - time;
+ },
+
+ resize: function () {
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ if (!this.box) return false;
+ var time = (new Date()).getTime();
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name, panel: this.tmp.resizing });
+ if (eventData.isCancelled === true) return false;
+ if (this.padding < 0) this.padding = 0;
+
+ // layout itself
+ var width = parseInt($(this.box).width());
+ var height = parseInt($(this.box).height());
+ $(this.box).find(' > div').css({
+ width : width + 'px',
+ height : height + 'px'
+ });
+ var obj = this;
+ // panels
+ var pmain = this.get('main');
+ var pprev = this.get('preview');
+ var pleft = this.get('left');
+ var pright = this.get('right');
+ var ptop = this.get('top');
+ var pbottom = this.get('bottom');
+ var smain = true; // main always on
+ var sprev = (pprev != null && pprev.hidden != true ? true : false);
+ var sleft = (pleft != null && pleft.hidden != true ? true : false);
+ var sright = (pright != null && pright.hidden != true ? true : false);
+ var stop = (ptop != null && ptop.hidden != true ? true : false);
+ var sbottom = (pbottom != null && pbottom.hidden != true ? true : false);
+ // calculate %
+ for (var p in { 'top':'', 'left':'', 'right':'', 'bottom':'', 'preview':'' }) {
+ var tmp = this.get(p);
+ var str = String(tmp.size);
+ if (tmp && str.substr(str.length-1) == '%') {
+ var tmph = height;
+ if (tmp.type == 'preview') {
+ tmph = tmph
+ - (ptop && !ptop.hidden ? ptop.sizeCalculated : 0)
+ - (pbottom && !pbottom.hidden ? pbottom.sizeCalculated : 0);
+ }
+ tmp.sizeCalculated = parseInt((tmp.type == 'left' || tmp.type == 'right' ? width : tmph) * parseFloat(tmp.size) / 100);
+ } else {
+ tmp.sizeCalculated = parseInt(tmp.size);
+ }
+ if (tmp.sizeCalculated < parseInt(tmp.minSize)) tmp.sizeCalculated = parseInt(tmp.minSize);
+ }
+ // top if any
+ if (ptop != null && ptop.hidden != true) {
+ var l = 0;
+ var t = 0;
+ var w = width;
+ var h = ptop.sizeCalculated;
+ $('#layout_'+ this.name +'_panel_top').css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px'
+ }).show();
+ ptop.width = w;
+ ptop.height = h;
+ // resizer
+ if (ptop.resizable) {
+ t = ptop.sizeCalculated - (this.padding == 0 ? this.resizer : 0);
+ h = (this.resizer > this.padding ? this.resizer : this.padding);
+ $('#layout_'+ this.name +'_resizer_top').show().css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px',
+ 'cursor': 'ns-resize'
+ }).bind('mousedown', function (event) {
+ w2ui[obj.name].tmp.events.resizeStart('top', event);
+ return false;
+ });
+ }
+ } else {
+ $('#layout_'+ this.name +'_panel_top').hide();
+ }
+ // left if any
+ if (pleft != null && pleft.hidden != true) {
+ var l = 0;
+ var t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0);
+ var w = pleft.sizeCalculated;
+ var h = height - (stop ? ptop.sizeCalculated + this.padding : 0) -
+ (sbottom ? pbottom.sizeCalculated + this.padding : 0);
+ var e = $('#layout_'+ this.name +'_panel_left');
+ if (window.navigator.userAgent.indexOf('MSIE') > 0 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack
+ $('#layout_'+ this.name +'_panel_left').css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px'
+ }).show();
+ pleft.width = w;
+ pleft.height = h;
+ // resizer
+ if (pleft.resizable) {
+ l = pleft.sizeCalculated - (this.padding == 0 ? this.resizer : 0);
+ w = (this.resizer > this.padding ? this.resizer : this.padding);
+ $('#layout_'+ this.name +'_resizer_left').show().css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px',
+ 'cursor': 'ew-resize'
+ }).bind('mousedown', function (event) {
+ w2ui[obj.name].tmp.events.resizeStart('left', event);
+ return false;
+ });
+ }
+ } else {
+ $('#layout_'+ this.name +'_panel_left').hide();
+ $('#layout_'+ this.name +'_resizer_left').hide();
+ }
+ // right if any
+ if (pright != null && pright.hidden != true) {
+ var l = width - pright.sizeCalculated;
+ var t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0);
+ var w = pright.sizeCalculated;
+ var h = height - (stop ? ptop.sizeCalculated + this.padding : 0) -
+ (sbottom ? pbottom.sizeCalculated + this.padding : 0);
+ $('#layout_'+ this.name +'_panel_right').css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px'
+ }).show();
+ pright.width = w;
+ pright.height = h;
+ // resizer
+ if (pright.resizable) {
+ l = l - this.padding;
+ w = (this.resizer > this.padding ? this.resizer : this.padding);
+ $('#layout_'+ this.name +'_resizer_right').show().css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px',
+ 'cursor': 'ew-resize'
+ }).bind('mousedown', function (event) {
+ w2ui[obj.name].tmp.events.resizeStart('right', event);
+ return false;
+ });
+ }
+ } else {
+ $('#layout_'+ this.name +'_panel_right').hide();
+ }
+ // bottom if any
+ if (pbottom != null && pbottom.hidden != true) {
+ var l = 0;
+ var t = height - pbottom.sizeCalculated;
+ var w = width;
+ var h = pbottom.sizeCalculated;
+ $('#layout_'+ this.name +'_panel_bottom').css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px'
+ }).show();
+ pbottom.width = w;
+ pbottom.height = h;
+ // resizer
+ if (pbottom.resizable) {
+ t = t - (this.padding == 0 ? 0 : this.padding);
+ h = (this.resizer > this.padding ? this.resizer : this.padding);
+ $('#layout_'+ this.name +'_resizer_bottom').show().css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px',
+ 'cursor': 'ns-resize'
+ }).bind('mousedown', function (event) {
+ w2ui[obj.name].tmp.events.resizeStart('bottom', event);
+ return false;
+ });
+ }
+ } else {
+ $('#layout_'+ this.name +'_panel_bottom').hide();
+ }
+ // main - always there
+ var l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0);
+ var t = 0 + (stop ? ptop.sizeCalculated + this.padding : 0);
+ var w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) -
+ (sright ? pright.sizeCalculated + this.padding: 0);
+ var h = height - (stop ? ptop.sizeCalculated + this.padding : 0) -
+ (sbottom ? pbottom.sizeCalculated + this.padding : 0) -
+ (sprev ? pprev.sizeCalculated + this.padding : 0);
+ var e = $('#layout_'+ this.name +'_panel_main');
+ if (window.navigator.userAgent.indexOf('MSIE') > 0 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack
+ $('#layout_'+ this.name +'_panel_main').css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px'
+ });
+ pmain.width = w;
+ pmain.height = h;
+
+ // preview if any
+ if (pprev != null && pprev.hidden != true) {
+ var l = 0 + (sleft ? pleft.sizeCalculated + this.padding : 0);
+ var t = height - (sbottom ? pbottom.sizeCalculated + this.padding : 0) - pprev.sizeCalculated;
+ var w = width - (sleft ? pleft.sizeCalculated + this.padding : 0) -
+ (sright ? pright.sizeCalculated + this.padding : 0);
+ var h = pprev.sizeCalculated;
+ var e = $('#layout_'+ this.name +'_panel_preview');
+ if (window.navigator.userAgent.indexOf('MSIE') > 0 && e.length > 0 && e[0].clientHeight < e[0].scrollHeight) w += 17; // IE hack
+ $('#layout_'+ this.name +'_panel_preview').css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px'
+ }).show();
+ pprev.width = w;
+ pprev.height = h;
+ // resizer
+ if (pprev.resizable) {
+ t = t - (this.padding == 0 ? 0 : this.padding);
+ h = (this.resizer > this.padding ? this.resizer : this.padding);
+ $('#layout_'+ this.name +'_resizer_preview').show().css({
+ 'display': 'block',
+ 'left': l + 'px',
+ 'top': t + 'px',
+ 'width': w + 'px',
+ 'height': h + 'px',
+ 'cursor': 'ns-resize'
+ }).bind('mousedown', function (event) {
+ w2ui[obj.name].tmp.events.resizeStart('preview', event);
+ return false;
+ });
+ }
+ } else {
+ $('#layout_'+ this.name +'_panel_preview').hide();
+ }
+
+ // display tabs and toolbar if needed
+ for (var p in { 'top':'', 'left':'', 'main':'', 'preview':'', 'right':'', 'bottom':'' }) {
+ var pan = this.get(p);
+ var tmp = '#layout_'+ this.name +'_panel_'+ p +' > .w2ui-panel-';
+ var height = 0;
+ if (pan.show.tabs) {
+ if (pan.tabs != null && w2ui[this.name +'_'+ p +'_tabs']) w2ui[this.name +'_'+ p +'_tabs'].resize();
+ height += w2utils.getSize($(tmp + 'tabs').css({ display: 'block' }), 'height');
+ }
+ if (pan.show.toolbar) {
+ if (pan.toolbar != null && w2ui[this.name +'_'+ p +'_toolbar']) w2ui[this.name +'_'+ p +'_toolbar'].resize();
+ height += w2utils.getSize($(tmp + 'toolbar').css({ top: height + 'px', display: 'block' }), 'height');
+ }
+ $(tmp + 'content').css({ display: 'block' }).css({ top: height + 'px' });
+ }
+ // send resize to all objects
+ var obj = this;
+ clearTimeout(this._resize_timer);
+ this._resize_timer = setTimeout(function () {
+ for (var e in w2ui) {
+ if (typeof w2ui[e].resize == 'function') {
+ // sent to all none-layouts
+ if (w2ui[e].panels == 'undefined') w2ui[e].resize();
+ // only send to nested layouts
+ var parent = $(w2ui[e].box).parents('.w2ui-layout');
+ if (parent.length > 0 && parent.attr('name') == obj.name) w2ui[e].resize();
+ }
+ }
+ }, 100);
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ return (new Date()).getTime() - time;
+ },
+
+ destroy: function () {
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name });
+ if (eventData.isCancelled === true) return false;
+ if (typeof w2ui[this.name] == 'undefined') return false;
+ // clean up
+ if ($(this.box).find('#layout_'+ this.name +'_panel_main').length > 0) {
+ $(this.box)
+ .removeAttr('name')
+ .removeClass('w2ui-layout')
+ .html('');
+ }
+ delete w2ui[this.name];
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+
+ if (this.tmp.events && this.tmp.events.resize) $(window).off('resize', this.tmp.events.resize);
+ if (this.tmp.events && this.tmp.events.mousemove) $(document).off('mousemove', this.tmp.events.mousemove);
+ if (this.tmp.events && this.tmp.events.mouseup) $(document).off('mouseup', this.tmp.events.mouseup);
+
+ return true;
+ },
+
+ lock: function (panel, msg, showSpinner) {
+ if ($.inArray(String(panel), ['left', 'right', 'top', 'bottom', 'preview', 'main']) == -1) {
+ console.log('ERROR: First parameter needs to be the a valid panel name.');
+ return;
+ }
+ var nm = '#layout_'+ this.name + '_panel_' + panel;
+ w2utils.lock(nm, msg, showSpinner);
+ },
+
+ unlock: function (panel) {
+ if ($.inArray(String(panel), ['left', 'right', 'top', 'bottom', 'preview', 'main']) == -1) {
+ console.log('ERROR: First parameter needs to be the a valid panel name.');
+ return;
+ }
+ var nm = '#layout_'+ this.name + '_panel_' + panel;
+ w2utils.unlock(nm);
+ }
+ }
+
+ $.extend(w2layout.prototype, w2utils.event);
+ w2obj.layout = w2layout;
+})();
+/************************************************************************
+* Library: Web 2.0 UI for jQuery (using prototypical inheritance)
+* - Following objects defined
+* - w2popup - popup widget
+* - $().w2popup - jQuery wrapper
+* - Dependencies: jQuery, w2utils
+*
+* == NICE TO HAVE ==
+* - when maximized, align the slide down message
+* - bug: after transfer to another content, message does not work
+* - transition should include title, body and buttons, not just body
+* - add lock method() to lock popup content
+*
+************************************************************************/
+
+var w2popup = {};
+
+(function () {
+
+ // ====================================================
+ // -- Registers as a jQuery plugin
+
+ $.fn.w2popup = function(method, options) {
+ if (typeof method == 'undefined') {
+ options = {};
+ method = 'open';
+ }
+ if ($.isPlainObject(method)) {
+ options = method;
+ method = 'open';
+ }
+ method = method.toLowerCase();
+ if (method == 'load' && typeof options == 'string') options = { url: options };
+ if (method == 'open' && typeof options.url != 'undefined') method = 'load';
+ if (typeof options == 'undefined') options = {};
+ // load options from markup
+ var dlgOptions = {};
+ if ($(this).length > 0 ) {
+ if ($(this).find('div[rel=title], div[rel=body], div[rel=buttons]').length > 0) {
+ if ($(this).find('div[rel=title]').length > 0) {
+ dlgOptions['title'] = $(this).find('div[rel=title]').html();
+ }
+ if ($(this).find('div[rel=body]').length > 0) {
+ dlgOptions['body'] = $(this).find('div[rel=body]').html();
+ dlgOptions['style'] = $(this).find('div[rel=body]')[0].style.cssText;
+ }
+ if ($(this).find('div[rel=buttons]').length > 0) {
+ dlgOptions['buttons'] = $(this).find('div[rel=buttons]').html();
+ }
+ } else {
+ dlgOptions['title'] = ' ';
+ dlgOptions['body'] = $(this).html();
+ }
+ if (parseInt($(this).css('width')) != 0) dlgOptions['width'] = parseInt($(this).css('width'));
+ if (parseInt($(this).css('height')) != 0) dlgOptions['height'] = parseInt($(this).css('height'));
+ }
+ // show popup
+ return w2popup[method]($.extend({}, dlgOptions, options));
+ };
+
+ // ====================================================
+ // -- Implementation of core functionality (SINGELTON)
+
+ w2popup = {
+ defaults: {
+ title : '',
+ body : '',
+ buttons : '',
+ style : '',
+ color : '#000',
+ opacity : 0.4,
+ speed : 0.3,
+ modal : false,
+ maximized : false,
+ keyboard : true, // will close popup on esc if not modal
+ width : 500,
+ height : 300,
+ showClose : true,
+ showMax : false,
+ transition : null
+ },
+ handlers : [],
+ onOpen : null,
+ onClose : null,
+ onMax : null,
+ onMin : null,
+ onKeydown : null,
+
+ open: function (options) {
+ var obj = this;
+ // get old options and merge them
+ var old_options = $('#w2ui-popup').data('options');
+ var options = $.extend({}, this.defaults, { body : '' }, old_options, options);
+ // if new - reset event handlers
+ if ($('#w2ui-popup').length == 0) {
+ w2popup.handlers = [];
+ w2popup.onMax = null;
+ w2popup.onMin = null;
+ w2popup.onOpen = null;
+ w2popup.onClose = null;
+ w2popup.onKeydown = null;
+ }
+ if (options.onOpen) w2popup.onOpen = options.onOpen;
+ if (options.onClose) w2popup.onClose = options.onClose;
+ if (options.onMax) w2popup.onMax = options.onMax;
+ if (options.onMin) w2popup.onMin = options.onMin;
+ if (options.onKeydown) w2popup.onKeydown = options.onKeydown;
+
+ if (window.innerHeight == undefined) {
+ var width = document.documentElement.offsetWidth;
+ var height = document.documentElement.offsetHeight;
+ if (w2utils.engine == 'IE7') { width += 21; height += 4; }
+ } else {
+ var width = window.innerWidth;
+ var height = window.innerHeight;
+ }
+ if (parseInt(width) - 10 < parseInt(options.width)) options.width = parseInt(width) - 10;
+ if (parseInt(height) - 10 < parseInt(options.height)) options.height = parseInt(height) - 10;
+ var top = ((parseInt(height) - parseInt(options.height)) / 2) * 0.6;
+ var left = (parseInt(width) - parseInt(options.width)) / 2;
+ // check if message is already displayed
+ if ($('#w2ui-popup').length == 0) {
+ // trigger event
+ var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: false });
+ if (eventData.isCancelled === true) return;
+ // output message
+ w2popup.lockScreen(options);
+ var msg = '
';
+ li.data('file', file)
+ .on('click', function (event) {
+ if (typeof settings.onItemClick == 'function') {
+ var ret = settings.onItemClick.call(obj, $(this).data('file'));
+ if (ret === false) return;
+ }
+ if (!$(event.target).hasClass('file-delete')) event.stopPropagation();
+ })
+ .on('dblclick', function (event) {
+ if (typeof settings.onItemDblClick == 'function') {
+ var ret = settings.onItemDblClick.call(obj, $(this).data('file'));
+ if (ret === false) return;
+ }
+ event.stopPropagation();
+ if (document.selection) document.selection.empty(); else document.defaultView.getSelection().removeAllRanges();
+ })
+ .on('mouseover', function (event) {
+ if (typeof settings.onItemOver == 'function') {
+ var ret = settings.onItemOver.call(obj, $(this).data('file'));
+ if (ret === false) return;
+ }
+ var file = $(this).data('file');
+ $(this).w2overlay(
+ previewHTML.replace('##FILE##', (file.content ? 'data:'+ file.type +';base64,'+ file.content : '')),
+ { top: -4 }
+ );
+ })
+ .on('mouseout', function () {
+ if (typeof settings.onItemOut == 'function') {
+ var ret = settings.onItemOut.call(obj, $(this).data('file'));
+ if (ret === false) return;
+ }
+ $(this).w2overlay();
+ });
+ }
+ }
+ this.refresh();
+ break;
+
+ case 'slider':
+ // for future reference
+ break;
+
+ default:
+ console.log('ERROR: w2field does not recognize "'+ options.type + '" field type.');
+ break;
+ }
+ });
+ },
+
+ // ******************************************************
+ // -- Implementation
+
+ addType: function (type, handler) {
+ w2field.customTypes[String(type).toLowerCase()] = handler;
+ },
+
+ cleanItems: function (items) {
+ var newItems = [];
+ for (var i in items) {
+ var id = '';
+ var text = '';
+ var opt = items[i];
+ if (opt == null) continue;
+ if ($.isPlainObject(items)) {
+ id = i;
+ text = opt;
+ } else {
+ if (typeof opt == 'object') {
+ if (typeof opt.id != 'undefined') id = opt.id;
+ if (typeof opt.value != 'undefined') id = opt.value;
+ if (typeof opt.txt != 'undefined') text = opt.txt;
+ if (typeof opt.text != 'undefined') text = opt.text;
+ }
+ if (typeof opt == 'string') {
+ if (String(opt) == '') continue;
+ id = opt;
+ text = opt;
+ opt = {};
+ }
+ }
+ if (w2utils.isInt(id)) id = parseInt(id);
+ if (w2utils.isFloat(id)) id = parseFloat(id);
+ newItems.push($.extend({}, opt, { id: id, text: text }));
+ }
+ return newItems;
+ },
+
+ // ******************************************************
+ // -- Upload
+
+ upload_init: function () {
+ var obj = this; // this -> input element
+ var settings = $(this).data('settings');
+ // create drop area if needed
+ var el = $(obj).prev();
+ if (el.length > 0 && el[0].tagName == 'DIV' && el.hasClass('w2ui-upload')) el.remove();
+ // rebuild it
+ var margin = 'margin-top: ' + $(obj).css('margin-top') + '; ' +
+ 'margin-bottom: ' + $(obj).css('margin-bottom') + '; ' +
+ 'margin-left: ' + $(obj).css('margin-left') + '; ' +
+ 'margin-right: ' + $(obj).css('margin-right') + '; '+
+ 'width: ' + (w2utils.getSize(obj, 'width')
+ - parseInt($(obj).css('margin-left'))
+ - parseInt($(obj).css('margin-right'))) + 'px; '+
+ 'height: ' + (w2utils.getSize(obj, 'height')
+ - parseInt($(obj).css('margin-top'))
+ - parseInt($(obj).css('margin-bottom'))) + 'px; ';
+ var html =
+ '
'+
+ ' '+ settings.hint +''+
+ '
'+
+ ' '+
+ '
';
+ $(obj)
+ .css({
+ 'display1' : 'none',
+ 'border-color' : 'transparent'
+ })
+ .before(html);
+ $(obj).data('div', $(obj).prev()[0]);
+ var div = $(obj).data('div');
+ // if user selects files through input control
+ $(div).find('.file-input')
+ .off('change')
+ .on('change', function () {
+ if (typeof this.files !== "undefined") {
+ for (var i = 0, l = this.files.length; i < l; i++) {
+ w2field.upload_add.call(obj, this.files[i]);
+ }
+ }
+ });
+
+ // if user clicks drop zone
+ $(div)
+ .off('click')
+ .on('click', function (event) {
+ $(div).w2tag();
+ if (event.target.tagName == 'LI' || $(event.target).hasClass('file-size')) {
+ return;
+ }
+ if ($(event.target).hasClass('file-delete')) {
+ w2field.upload_remove.call(obj, event.target.parentNode);
+ return;
+ }
+ if (event.target.tagName != 'INPUT') {
+ var settings = $(obj).data('settings');
+ var selected = $(obj).data('selected');
+ var cnt = 0;
+ for (var s in selected) { cnt++; }
+ if (cnt < settings.max || settings.max == 0) $(div).find('.file-input').click();
+ }
+ })
+ .off('dragenter')
+ .on('dragenter', function (event) {
+ $(div).addClass('dragover');
+ })
+ .off('dragleave')
+ .on('dragleave', function (event) {
+ $(div).removeClass('dragover');
+ })
+ .off('drop')
+ .on('drop', function (event) {
+ $(div).removeClass('dragover');
+ var files = event.originalEvent.dataTransfer.files;
+ for (var i=0, l=files.length; i input element
+ var div = $(obj).data('div');
+ var settings = $(obj).data('settings');
+ var selected = $(obj).data('selected');
+ var newItem = {
+ name : file.name,
+ type : file.type,
+ modified : file.lastModifiedDate,
+ size : file.size,
+ content : null
+ };
+ var size = 0;
+ var cnt = 0;
+ for (var s in selected) { size += selected[s].size; cnt++; }
+ // check params
+ if (settings.maxFileSize != 0 && newItem.size > settings.maxFileSize) {
+ var err = 'Maximum file size is '+ w2utils.size(settings.maxFileSize);
+ $(div).w2tag(err);
+ console.log('ERROR: '+ err);
+ return;
+ }
+ if (settings.maxSize != 0 && size + newItem.size > settings.maxSize) {
+ var err = 'Maximum total size is '+ w2utils.size(settings.maxFileSize);
+ $(div).w2tag(err);
+ console.log('ERROR: '+ err);
+ return;
+ }
+ if (settings.max != 0 && cnt >= settings.max) {
+ var err = 'Maximum number of files is '+ settings.max;
+ $(div).w2tag(err);
+ console.log('ERROR: '+ err);
+ return;
+ }
+ if (typeof settings.onAdd == 'function') {
+ var ret = settings.onAdd.call(obj, newItem);
+ if (ret === false) return;
+ }
+ selected.push(newItem);
+ // read file as base64
+ if (typeof FileReader !== "undefined" && settings.base64 === true) {
+ var reader = new FileReader();
+ // need a closure
+ reader.onload = (function () {
+ return function (event) {
+ var fl = event.target.result;
+ var ind = fl.indexOf(',');
+ newItem.content = fl.substr(ind+1);
+ obj.refresh();
+ $(obj).trigger('change');
+ };
+ })();
+ reader.readAsDataURL(file);
+ } else {
+ obj.refresh();
+ $(obj).trigger('change');
+ }
+ },
+
+ upload_remove: function (li) {
+ var obj = this; // this -> input element
+ var div = $(obj).data('div');
+ var settings = $(obj).data('settings');
+ var selected = $(obj).data('selected');
+ var file = $(li).data('file');
+ // run event
+ if (typeof settings.onRemove == 'function') {
+ var ret = settings.onRemove.call(obj, file);
+ if (ret === false) return false;
+ }
+ // remove from selected
+ for (var i = selected.length - 1; i >= 0; i--) {
+ if (selected[i].name == file.name && selected[i].size == file.size) {
+ selected.splice(i, 1);
+ }
+ }
+ $(li).fadeOut('fast');
+ setTimeout(function () {
+ $(li).remove();
+ // if all files remoted
+ if (selected.length == 0) {
+ $(div).prepend(''+ settings.hint +'');
+ }
+ obj.refresh();
+ $(obj).trigger('change');
+ }, 300);
+ },
+
+ // ******************************************************
+ // -- Enum
+
+ list_render: function (search) {
+ var obj = this;
+ var div = $('#w2ui-global-items');
+ var settings = $(this).data('settings');
+ var items = settings.items;
+ var selected = $(this).data('selected');
+ if (div.length == 0) return; // if it is hidden
+
+ // build overall html
+ if (typeof search == 'undefined') {
+ var html = '';
+ html += '';
+ div.html(html);
+ search = '';
+ }
+ $(this).data('last_search', search);
+ if (typeof $(obj).data('last_index') == 'undefined' || $(obj).data('last_index') == null) $(obj).data('last_index', 0);
+
+ // pull items from url
+ if (typeof settings.last_total == 'undefined') settings.last_total = -1;
+ if (typeof settings.last_search_len == 'undefined') settings.last_search_len = 0;
+ if (typeof settings.last_search_match == 'undefined') settings.last_search_match = -1;
+ if (settings.url != '' && (
+ (items.length == 0 && settings.last_total != 0)
+ || (search.length > settings.last_search_len && settings.last_total > settings.maxCache)
+ || (search.length < settings.last_search_match && search.length != settings.last_search_len)
+ )
+ ) {
+ var match = false;
+ if (settings.last_total < settings.maxCache) match = true;
+ $.ajax({
+ type : 'GET',
+ dataType : 'text',
+ url : settings.url,
+ data : {
+ search : search,
+ max : settings.maxCache
+ },
+ complete: function (xhr, status) {
+ settings.last_total = 0;
+ if (status == 'success') {
+ var data = $.parseJSON(xhr.responseText);
+ if (match == false && data.total < settings.maxCache) { settings.last_search_match = search.length; }
+ settings.last_search_len = search.length;
+ settings.last_total = data.total
+ settings.items = data.items;
+ w2field.list_render.call(obj, search);
+ }
+ }
+ });
+ }
+
+ // build items
+ var i = 0;
+ var ihtml = '
';
+ // get ids of all selected items
+ var ids = [];
+ for (var a in selected) ids.push(w2utils.isInt(selected[a].id) ? parseInt(selected[a].id) : String(selected[a].id))
+ // build list
+ var group = '';
+ for (var a in items) {
+ var id = items[a].id;
+ var txt = items[a].text;
+ // if already selected
+ if ($.inArray(w2utils.isInt(id) ? parseInt(id) : String(id), ids) != -1 && settings.showAll !== true) continue;
+ // check match with search
+ var txt1 = String(search).toLowerCase();
+ var txt2 = txt.toLowerCase();
+ var match = (txt1.length <= txt2.length && txt2.substr(0, txt1.length) == txt1);
+ if (settings.match.toLowerCase() == 'contains' && txt2.indexOf(txt1) != -1) match = true;
+ if (match) {
+ if (typeof settings['render'] == 'function') {
+ txt = settings['render'](items[a], selected);
+ }
+ if (txt !== false) {
+ // render group if needed
+ if (typeof items[a].group != 'undefined' && items[a].group != group) {
+ group = items[a].group;
+ ihtml += '
'+ group +'
';
+ }
+ // render item
+ ihtml += '\n
'+
+ txt +'
';
+ if (i == $(obj).data('last_index')) $(obj).data('last_item', items[a]);
+ i++;
+ }
+ }
+ }
+ ihtml += '
';
+ if (i == 0) {
+ ihtml = '
'+ w2utils.lang('No items found') +'
';
+ var noItems = true;
+ }
+ div.find('.w2ui-items-list').html(ihtml);
+ $(this).data('last_max', i-1);
+
+ // scroll selected into view
+ if (div.find('li.selected').length > 0) div.find('li.selected')[0].scrollIntoView(false);
+
+ // if menu goes off screen - add scrollbar
+ div.css({ '-webkit-transition': '0s', height : 'auto' });
+ var max_height = parseInt($(document).height()) - parseInt(div.offset().top) - 8;
+ if (parseInt(div.height()) > max_height) {
+ div.css({
+ height : (max_height - 5) + 'px',
+ overflow: 'show'
+ });
+ $(div).find('.w2ui-items-list').css({
+ height : (max_height - 15) + 'px',
+ overflow: 'auto'
+ });
+ }
+
+ // add events
+ $(div)
+ .off('mousedown')
+ .on('mousedown', function (event) {
+ var target = event.target;
+ if (target.tagName != "LI") target = $(target).parents('li');
+ var id = $(target).attr('index');
+ if (!id) return;
+ var item = settings.items[id];
+ if (typeof id == 'undefined') { if (event.preventDefault) event.preventDefault(); else return false; }
+ obj.add(item);
+ $(obj).data('last_index', 0);
+ obj.refresh();
+ w2field.list_render.call(obj, '');
+ }
+ );
+ $(obj).prev().find('li > input')
+ .val(search)
+ .css('max-width', ($(div).width() - 25) + 'px')
+ .width(((search.length + 2) * 6) + 'px')
+ .focus()
+ .on('click', function (event) {
+ if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;
+ })
+ .off('keyup')
+ .on('keyup', function (event) {
+ var inp = this;
+ setTimeout(function () {
+ var curr = $(obj).data('last_index');
+ switch (event.keyCode) {
+ case 38: // up
+ curr--;
+ if (curr < 0) curr = 0;
+ $(obj).data('last_index', curr);
+ if (event.preventDefault) event.preventDefault();
+ break;
+ case 40: // down
+ curr++;
+ if (curr > $(obj).data('last_max')) curr = $(obj).data('last_max');
+ $(obj).data('last_index', curr);
+ if (event.preventDefault) event.preventDefault();
+ break;
+ case 13: // enter
+ if (typeof $(obj).data('last_item') == 'undefined' || $(obj).data('last_item') == null || noItems === true) break;
+ var selected = $(obj).data('selected');
+ obj.add($(obj).data('last_item'));
+ // select next
+ if (curr > $(obj).data('last_max') - 1) curr = $(obj).data('last_max')-1;
+ $(obj).data('last_index', curr);
+ $(obj).data('last_item', null);
+ // refrech
+ $(inp).val('');
+ obj.refresh();
+ if (event.preventDefault) event.preventDefault();
+ break;
+ case 8: // backspace
+ if (String(inp.value) == '') {
+ if (typeof $(obj).data('last_del') == 'undefined' || $(obj).data('last_del') == null) {
+ // mark for deletion
+ var selected = $(obj).data('selected');
+ if (!$.isArray(selected)) selected = [];
+ $(obj).data('last_del', selected.length-1);
+ // refrech
+ obj.refresh();
+ } else {
+ // delete marked one
+ var selected = $(obj).data('selected');
+ obj.remove(selected.length - 1);
+ }
+ }
+ break;
+ default:
+ $(obj).data('last_index', 0);
+ $(obj).data('last_del', null);
+ break;
+ }
+ // adjust height
+ obj.resize();
+
+ // refresh menu
+ if (!(event.keyCode == 8 && String(inp.value) == '')) {
+ $(obj).prev().find('li').css('opacity', '1');
+ $(obj).data('last_del', null);
+ }
+ if ($.inArray(event.keyCode, [16,91,37,39]) == -1) { // command and shift keys and arrows
+ w2field.list_render.call(obj, inp.value);
+ }
+ }, 10);
+ })
+ },
+
+ // ******************************************************
+ // -- Calendar
+
+ calendar_get: function (date, options) {
+ var td = new Date();
+ var today = (Number(td.getMonth())+1) + '/' + td.getDate() + '/' + (String(td.getYear()).length > 3 ? td.getYear() : td.getYear() + 1900);
+ if (String(date) == '' || String(date) == 'undefined') date = w2utils.formatDate(today, options.format);
+ if (!w2utils.isDate(date, options.format)) date = w2utils.formatDate(today, options.format);
+ // format date
+ var tmp = date.replace(/-/g, '/').replace(/\./g, '/').toLowerCase().split('/');
+ var tmp2 = options.format.replace(/-/g, '/').replace(/\./g, '/').toLowerCase();
+ var dt = new Date();
+ if (tmp2 == 'mm/dd/yyyy') dt = new Date(tmp[0] + '/' + tmp[1] + '/' + tmp[2]);
+ if (tmp2 == 'm/d/yyyy') dt = new Date(tmp[0] + '/' + tmp[1] + '/' + tmp[2]);
+ if (tmp2 == 'dd/mm/yyyy') dt = new Date(tmp[1] + '/' + tmp[0] + '/' + tmp[2]);
+ if (tmp2 == 'd/m/yyyy') dt = new Date(tmp[1] + '/' + tmp[0] + '/' + tmp[2]);
+ if (tmp2 == 'yyyy/dd/mm') dt = new Date(tmp[2] + '/' + tmp[1] + '/' + tmp[0]);
+ if (tmp2 == 'yyyy/d/m') dt = new Date(tmp[2] + '/' + tmp[1] + '/' + tmp[0]);
+ if (tmp2 == 'yyyy/mm/dd') dt = new Date(tmp[1] + '/' + tmp[2] + '/' + tmp[0]);
+ if (tmp2 == 'yyyy/m/d') dt = new Date(tmp[1] + '/' + tmp[2] + '/' + tmp[0]);
+ if (tmp2 == 'mm/dd/yy') dt = new Date(tmp[0] + '/' + tmp[1] + '/' + (parseInt(tmp[2]) + 1900));
+ if (tmp2 == 'm/d/yy') dt = new Date(tmp[0] + '/' + tmp[1] + '/' + (parseInt(tmp[2]) + 1900));
+ if (tmp2 == 'dd/mm/yy') dt = new Date(tmp[1] + '/' + tmp[0] + '/' + (parseInt(tmp[2]) + 1900));
+ if (tmp2 == 'd/m/yy') dt = new Date(tmp[1] + '/' + tmp[0] + '/' + (parseInt(tmp[2]) + 1900));
+ if (tmp2 == 'yy/dd/mm') dt = new Date(tmp[2] + '/' + tmp[1] + '/' + (parseInt(tmp[0]) + 1900));
+ if (tmp2 == 'yy/d/m') dt = new Date(tmp[2] + '/' + tmp[1] + '/' + (parseInt(tmp[0]) + 1900));
+ if (tmp2 == 'yy/mm/dd') dt = new Date(tmp[1] + '/' + tmp[2] + '/' + (parseInt(tmp[0]) + 1900));
+ if (tmp2 == 'yy/m/d') dt = new Date(tmp[1] + '/' + tmp[2] + '/' + (parseInt(tmp[0]) + 1900));
+ var html = '
");var obj=this;var div=$("#w2ui-overlay div");div.css(options.css).html(html);if(typeof options["class"]!="undefined")div.addClass(options["class"]);if(typeof options.top=="undefined")options.top=0;if(typeof options.left=="undefined")options.left=0;if(typeof options.width=="undefined")options.width=100;if(typeof options.height=="undefined")options.height=0;var bc=div.css("background-color");var div=$("#w2ui-overlay");if(typeof bc!="undefined"&&bc!="rgba(0, 0, 0, 0)"&&bc!="transparent")div.css("background-color",bc);div.css({display:"none",left:$(obj).offset().left+options.left+"px",top:$(obj).offset().top+w2utils.getSize($(obj),"height")+3+options.top+"px","min-width":options.width?options.width:"auto","min-height":options.height?options.height:"auto"}).fadeIn("fast").data("position",$(obj).offset().left+"x"+($(obj).offset().top+obj.offsetHeight)).on("click",function(event){if(event.stopPropagation)event.stopPropagation();else event.cancelBubble=true});function hide(){var result;if(typeof options.onHide=="function")result=options.onHide();if(result===false)return;$("#w2ui-overlay").remove();$(document).off("click",hide)}setTimeout(fixSize,0);return $(this);function fixSize(){$(document).on("click",hide);if($("#w2ui-overlay > div").length>0){var h=$("#w2ui-overlay > div").height();var w=$("#w2ui-overlay> div").width();var max=window.innerHeight-$("#w2ui-overlay > div").offset().top-7;if(h>max)$("#w2ui-overlay> div").height(max).width(w+w2utils.scrollBarSize()).css({"overflow-y":"auto"});w=$("#w2ui-overlay> div").width();max=window.innerWidth-$("#w2ui-overlay > div").offset().left-7;if(w>max)$("#w2ui-overlay> div").width(max).css({"overflow-x":"auto"});if(typeof options.onShow=="function")options.onShow()}}};$.fn.w2menu=function(menu,options){if(typeof options.select=="undefined"&&typeof options.onSelect=="function")options.select=options.onSelect;if(typeof options.select!="function"){console.log("ERROR: options.select is required to be a function, not "+typeof options.select+" in $().w2menu(menu, options)");return $(this)}if(!$.isArray(menu)){console.log("ERROR: first parameter should be an array of objects or strings in $().w2menu(menu, options)");
+return $(this)}$.fn.w2menuHandler=function(event,index){options.select(menu[index],event,index)};return $(this).w2overlay(getMenuHTML(),options);function getMenuHTML(){var menu_html='
';for(var f=0;f';if(mitem.icon)img='
';menu_html+="
"+img+"
"+mitem.text+"
"+"
"}menu_html+="
";return menu_html}}})();(function(){var w2grid=function(options){this.name=null;this.box=null;this.header="";this.url="";this.columns=[];this.columnGroups=[];this.records=[];this.summary=[];this.searches=[];this.searchData=[];this.sortData=[];this.postData={};this.toolbar={};this.show={header:false,toolbar:false,footer:false,columnHeaders:true,lineNumbers:false,expandColumn:false,selectColumn:false,emptyRecords:true,toolbarReload:true,toolbarColumns:true,toolbarSearch:true,toolbarAdd:false,toolbarEdit:false,toolbarDelete:false,toolbarSave:false,selectionBorder:true,recordTitles:true};this.autoLoad=true;this.fixedBody=true;this.recordHeight=24;this.keyboard=true;this.selectType="row";this.multiSearch=true;this.multiSelect=true;this.multiSort=true;this.markSearchResults=true;this.total=0;this.buffered=0;this.limit=100;this.offset=0;this.style="";this.ranges=[];this.onAdd=null;this.onEdit=null;this.onRequest=null;this.onLoad=null;this.onDelete=null;this.onDeleted=null;this.onSave=null;this.onSaved=null;this.onSelect=null;this.onUnselect=null;this.onClick=null;this.onDblClick=null;this.onColumnClick=null;this.onColumnResize=null;this.onSort=null;this.onSearch=null;this.onChange=null;this.onExpand=null;this.onCollapse=null;this.onError=null;this.onKeydown=null;this.onToolbar=null;this.onColumnOnOff=null;this.onCopy=null;this.onPaste=null;this.onSelectionExtend=null;this.onEditField=null;this.onRender=null;this.onRefresh=null;this.onReload=null;this.onResize=null;this.onDestroy=null;this.last={field:"all",caption:w2utils.lang("All Fields"),logic:"OR",search:"",searchIds:[],multi:false,scrollTop:0,scrollLeft:0,selected:[],sortData:null,sortCount:0,xhr:null,range_start:null,range_end:null,sel_ind:null,sel_col:null,sel_type:null};this.isIOS=navigator.userAgent.toLowerCase().indexOf("iphone")!=-1||navigator.userAgent.toLowerCase().indexOf("ipod")!=-1||navigator.userAgent.toLowerCase().indexOf("ipad")!=-1?true:false;$.extend(true,this,w2obj.grid,options)};$.fn.w2grid=function(method){if(typeof method==="object"||!method){if(!method||typeof method.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2grid().');return}if(typeof w2ui[method.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+method.name+").");return}if(!w2utils.isAlphaNumeric(method.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}var columns=method.columns;var columnGroups=method.columnGroups;var records=method.records;var searches=method.searches;var searchData=method.searchData;var sortData=method.sortData;var postData=method.postData;var toolbar=method.toolbar;var object=new w2grid(method);$.extend(object,{postData:{},records:[],columns:[],searches:[],toolbar:{},sortData:[],searchData:[],handlers:[]});if(object.onExpand!=null)object.show.expandColumn=true;$.extend(true,object.toolbar,toolbar);for(var p in columns)object.columns[p]=$.extend(true,{},columns[p]);for(var p in columnGroups)object.columnGroups[p]=$.extend(true,{},columnGroups[p]);for(var p in searches)object.searches[p]=$.extend(true,{},searches[p]);for(var p in searchData)object.searchData[p]=$.extend(true,{},searchData[p]);for(var p in sortData)object.sortData[p]=$.extend(true,{},sortData[p]);object.postData=$.extend(true,{},postData);for(var r in records){if(records[r].recid==null||typeof records[r].recid=="undefined"){console.log("ERROR: Cannot add records without recid. (obj: "+object.name+")");return}object.records[r]=$.extend(true,{},records[r])}if(object.records.length>0)object.buffered=object.records.length;for(var c in object.columns){var col=object.columns[c];if(typeof col.searchable=="undefined"||object.getSearch(col.field)!=null)continue;var stype=col.searchable;var attr="";if(col.searchable===true){stype="text";attr='size="20"'}object.addSearch({field:col.field,caption:col.caption,type:stype,attr:attr})}object.initToolbar();if($(this).length!=0){object.render($(this)[0])}w2ui[object.name]=object;return object}else if(w2ui[$(this).attr("name")]){var obj=w2ui[$(this).attr("name")];obj[method].apply(obj,Array.prototype.slice.call(arguments,1));return this}else{console.log("ERROR: Method "+method+" does not exist on jQuery.w2grid")}};w2grid.prototype={msgDelete:"Are you sure you want to delete selected records?",msgNotJSON:"Returned data is not in valid JSON format.",msgRefresh:"Refreshing...",buttons:{reload:{type:"button",id:"reload",img:"icon-reload",hint:"Reload data in the list"},columns:{type:"drop",id:"column-on-off",img:"icon-columns",hint:"Show/hide columns",arrow:false,html:""},search:{type:"html",id:"search",html:'"},"search-go":{type:"check",id:"search-advanced",caption:"Search...",hint:"Open Search Fields"},add:{type:"button",id:"add",caption:"Add New",hint:"Add new record",img:"icon-add"},edit:{type:"button",id:"edit",caption:"Edit",hint:"Edit selected record",img:"icon-edit",disabled:true},"delete":{type:"button",id:"delete",caption:"Delete",hint:"Delete selected records",img:"icon-delete",disabled:true},save:{type:"button",id:"save",caption:"Save",hint:"Save changed records",img:"icon-save"}},add:function(record){if(!$.isArray(record))record=[record];var added=0;for(var o in record){if(record[o].recid==null||typeof record[o].recid=="undefined"){console.log("ERROR: Cannot add record without recid. (obj: "+this.name+")");continue}this.records.push(record[o]);added++}this.buffered=this.records.length;var url=typeof this.url!="object"?this.url:this.url.get;if(!url){this.localSort();this.localSearch()}this.refresh();return added},find:function(obj,returnIndex){if(typeof obj=="undefined"||obj==null)obj={};var recs=[];for(var i=0;i0&&!url)for(var s in this.last.searchIds)if(this.last.searchIds[s]==ind)ind=s;$(tr).replaceWith(this.getRecordHTML(ind,line))}}}return true},get:function(recid,returnIndex){for(var i=0;i=0;r--){if(this.records[r].recid==arguments[a]){this.records.splice(r,1);removed++}}}var url=typeof this.url!="object"?this.url:this.url.get;if(!url){this.buffered=this.records.length;this.localSort();this.localSearch()}this.refresh();return removed},addColumn:function(before,columns){var added=0;if(arguments.length==1){columns=before;before=this.columns.length}else{if(typeof before=="string")before=this.getColumn(before,true);if(before===null)before=this.columns.length}if(!$.isArray(columns))columns=[columns];for(var o in columns){this.columns.splice(before,0,columns[o]);before++;added++}this.initColumnOnOff();this.refresh();return added},removeColumn:function(){var removed=0;for(var a=0;a=0;r--){if(this.columns[r].field==arguments[a]){this.columns.splice(r,1);removed++}}}this.initColumnOnOff();this.refresh();return removed},getColumn:function(field,returnIndex){for(var i=0;i=0;r--){if(this.columns[r].field==arguments[a]){this.columns[r].hidden=!this.columns[r].hidden;effected++}}}this.refresh();return effected},showColumn:function(){var shown=0;for(var a=0;a=0;r--){if(this.columns[r].field==arguments[a]&&this.columns[r].hidden!==false){this.columns[r].hidden=false;shown++}}}this.refresh();return shown},hideColumn:function(){var hidden=0;for(var a=0;a=0;r--){if(this.columns[r].field==arguments[a]&&this.columns[r].hidden!==true){this.columns[r].hidden=true;hidden++}}}this.refresh();return hidden},addSearch:function(before,search){var added=0;if(arguments.length==1){search=before;before=this.searches.length}else{if(typeof before=="string")before=this.getSearch(before,true);if(before===null)before=this.searches.length}if(!$.isArray(search))search=[search];for(var o in search){this.searches.splice(before,0,search[o]);before++;added++}this.searchClose();return added},removeSearch:function(){var removed=0;for(var a=0;a=0;r--){if(this.searches[r].field==arguments[a]){this.searches.splice(r,1);removed++}}}this.searchClose();return removed},getSearch:function(field,returnIndex){for(var i=0;i=0;r--){if(this.searches[r].field==arguments[a]){this.searches[r].hidden=!this.searches[r].hidden;effected++}}}this.searchClose();return effected},showSearch:function(){var shown=0;for(var a=0;a=0;r--){if(this.searches[r].field==arguments[a]&&this.searches[r].hidden!==false){this.searches[r].hidden=false;shown++}}}this.searchClose();return shown},hideSearch:function(){var hidden=0;for(var a=0;a=0;r--){if(this.searches[r].field==arguments[a]&&this.searches[r].hidden!==true){this.searches[r].hidden=true;hidden++}}}this.searchClose();return hidden},getSearchData:function(field){for(var s in this.searchData){if(this.searchData[s].field==field)return this.searchData[s]}return null},localSort:function(silent){var url=typeof this.url!="object"?this.url:this.url.get;if(url){console.log("ERROR: grid.localSort can only be used on local data source, grid.url should be empty.");return}if($.isEmptyObject(this.sortData))return;var time=(new Date).getTime();var obj=this;this.records.sort(function(a,b){var ret=0;for(var s in obj.sortData){var aa=a[obj.sortData[s].field];var bb=b[obj.sortData[s].field];if(String(obj.sortData[s].field).indexOf(".")!=-1){aa=obj.parseField(a,obj.sortData[s].field);bb=obj.parseField(b,obj.sortData[s].field)}if(typeof aa=="string")aa=$.trim(aa.toLowerCase());if(typeof bb=="string")bb=$.trim(bb.toLowerCase());if(aa>bb)ret=obj.sortData[s].direction=="asc"?1:-1;if(aa0&&!url){this.total=0;for(var r in this.records){var rec=this.records[r];var fl=0;for(var s in this.searchData){var sdata=this.searchData[s];var search=this.getSearch(sdata.field);if(sdata==null)continue;if(search==null)search={field:sdata.field,type:sdata.type};var val1=String(obj.parseField(rec,search.field)).toLowerCase();if(typeof sdata.value!="undefined"){if(!$.isArray(sdata.value)){var val2=String(sdata.value).toLowerCase()}else{var val2=sdata.value[0];var val3=sdata.value[1]}}switch(sdata.operator){case"is":if(rec[search.field]==sdata.value)fl++;if(search.type=="date"){var tmp=new Date(Number(val1));val1=new Date(tmp.getFullYear(),tmp.getMonth(),tmp.getDate()).getTime();val2=Number(val2);var val3=Number(val1)+864e5;if(val2>=val1&&val2<=val3)fl++}break;case"between":if(search.type=="int"&&parseInt(rec[search.field])>=parseInt(val2)&&parseInt(rec[search.field])<=parseInt(val3))fl++;if(search.type=="float"&&parseFloat(rec[search.field])>=parseFloat(val2)&&parseFloat(rec[search.field])<=parseFloat(val3))fl++;if(search.type=="date"){var tmp=new Date(Number(val3));val3=new Date(tmp.getFullYear(),tmp.getMonth(),tmp.getDate()).getTime();var val3=Number(val3)+864e5;if(val1>=val2&&val1=0)fl++;break;case"ends with":if(val1.indexOf(val2)==val1.length-val2.length)fl++;break}}if(this.last.logic=="OR"&&fl!=0||this.last.logic=="AND"&&fl==this.searchData.length)this.last.searchIds.push(parseInt(r))}this.total=this.last.searchIds.length}this.buffered=this.total;time=(new Date).getTime()-time;if(silent!==true)setTimeout(function(){obj.status("Search took "+time/1e3+" sec")},10);return time},getRangeData:function(range,extra){var rec1=this.get(range[0].recid,true);var rec2=this.get(range[1].recid,true);var col1=range[0].column;var col2=range[1].column;var res=[];if(col1==col2){for(var r=rec1;r<=rec2;r++){var record=this.records[r];var dt=record[this.columns[col1].field]||null;if(extra!==true){res.push(dt)}else{res.push({data:dt,column:col1,index:r,record:record})}}}else if(rec1==rec2){var record=this.records[rec1];for(var i=col1;i<=col2;i++){var dt=record[this.columns[i].field]||null;if(extra!==true){res.push(dt)}else{res.push({data:dt,column:i,index:rec1,record:record})}}}else{for(var r=rec1;r<=rec2;r++){var record=this.records[r];res.push([]);for(var i=col1;i<=col2;i++){var dt=record[this.columns[i].field];if(extra!==true){res[res.length-1].push(dt)}else{res[res.length-1].push({data:dt,column:i,index:r,record:record})}}}}return res},addRange:function(ranges){var added=0;if(this.selectType=="row")return added;if(!$.isArray(ranges))ranges=[ranges];for(var r in ranges){if(typeof ranges[r]!="object")ranges[r]={name:"selection"};if(ranges[r].name=="selection"){if(this.show.selectionBorder===false)continue;var sel=this.getSelection();if(sel.length==0){this.removeRange(ranges[r].name);continue}else{var first=sel[0];var last=sel[sel.length-1];var td1=$("#grid_"+this.name+"_rec_"+first.recid+" td[col="+first.column+"]");var td2=$("#grid_"+this.name+"_rec_"+last.recid+" td[col="+last.column+"]")}}else{var first=ranges[r].range[0];var last=ranges[r].range[1];var td1=$("#grid_"+this.name+"_rec_"+first.recid+" td[col="+first.column+"]");var td2=$("#grid_"+this.name+"_rec_"+last.recid+" td[col="+last.column+"]")}if(first){var rg={name:ranges[r].name,range:[{recid:first.recid,column:first.column},{recid:last.recid,column:last.column}],style:ranges[r].style||""};var ind=false;for(var t in this.ranges)if(this.ranges[t].name==ranges[r].name){ind=r;break}if(ind!==false){this.ranges[ind]=rg}else{this.ranges.push(rg)}added++}}this.refreshRanges();return added},removeRange:function(){var removed=0;for(var a=0;a=0;r--){if(this.ranges[r].name==name){this.ranges.splice(r,1);removed++}}}return removed},refreshRanges:function(){var obj=this;var time=(new Date).getTime();var rec=$("#grid_"+this.name+"_records");for(var r in this.ranges){var rg=this.ranges[r];var first=rg.range[0];var last=rg.range[1];var td1=$("#grid_"+this.name+"_rec_"+first.recid+" td[col="+first.column+"]");var td2=$("#grid_"+this.name+"_rec_"+last.recid+" td[col="+last.column+"]");if($("#grid_"+this.name+"_"+rg.name).length==0){rec.append('
'+(rg.name=="selection"?'':"")+"
")}else{$("#grid_"+this.name+"_"+rg.name).attr("style",rg.style)}if(td1.length>0&&td2.length>0){$("#grid_"+this.name+"_"+rg.name).css({left:td1.position().left-1+rec.scrollLeft()+"px",top:td1.position().top-1+rec.scrollTop()+"px",width:td2.position().left-td1.position().left+td2.width()+3+"px",height:td2.position().top-td1.position().top+td2.height()+3+"px"})}}$(this.box).find("#grid_"+this.name+"_resizer").off("mousedown").on("mousedown",mouseStart);var eventData={phase:"before",type:"selectionExtend",target:obj.name,originalRange:null,newRange:null};function mouseStart(event){var sel=obj.getSelection();obj.last.move={type:"expand",x:event.screenX,y:event.screenY,divX:0,divY:0,recid:sel[0].recid,column:sel[0].column,originalRange:[{recid:sel[0].recid,column:sel[0].column},{recid:sel[sel.length-1].recid,column:sel[sel.length-1].column}],newRange:[{recid:sel[0].recid,column:sel[0].column},{recid:sel[sel.length-1].recid,column:sel[sel.length-1].column}]};$(document).off("mousemove",mouseMove).on("mousemove",mouseMove);$(document).off("mouseup",mouseStop).on("mouseup",mouseStop)}function mouseMove(event){var mv=obj.last.move;if(!mv||mv.type!="expand")return;mv.divX=event.screenX-mv.x;mv.divY=event.screenY-mv.y;var recid,column;var tmp=event.originalEvent.target;if(tmp.tagName!="TD")tmp=$(tmp).parents("td")[0];if(typeof $(tmp).attr("col")!="undefined")column=parseInt($(tmp).attr("col"));tmp=$(tmp).parents("tr")[0];recid=$(tmp).attr("recid");if(mv.newRange[1].recid==recid&&mv.newRange[1].column==column)return;var prevNewRange=$.extend({},mv.newRange);mv.newRange=[{recid:mv.recid,column:mv.column},{recid:recid,column:column}];eventData=obj.trigger($.extend(eventData,{originalRange:mv.originalRange,newRange:mv.newRange}));if(eventData.isCancelled===true){mv.newRange=prevNewRange;eventData.newRange=prevNewRange;return}else{obj.removeRange("grid-selection-expand");obj.addRange({name:"grid-selection-expand",range:eventData.newRange,style:"background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);"})}}function mouseStop(event){obj.removeRange("grid-selection-expand");delete obj.last.move;$(document).off("mousemove",mouseMove);$(document).off("mouseup",mouseStop);obj.trigger($.extend(eventData,{phase:"after"}))}return(new Date).getTime()-time},select:function(){var selected=0;for(var a=0;a td[col="+col+"]").addClass("w2ui-selected");selected++;if(record.selected){$("#grid_"+this.name+"_rec_"+w2utils.escapeId(recid)).data("selected","yes");$("#grid_"+this.name+"_cell_"+index+"_select_check").prop("checked",true)}}this.trigger($.extend(eventData,{phase:"after"}))}$("#grid_"+this.name+"_check_all").prop("checked",true);if($("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length!=0&&$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length==$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]:checked").length){$("#grid_"+this.name+"_check_all").prop("checked",true)}else{$("#grid_"+this.name+"_check_all").prop("checked",false)}this.status();this.addRange("selection");return selected},unselect:function(){var unselected=0;for(var a=0;a td[col="+col+"]").removeClass("w2ui-selected");unselected++;if(s.length==0){record.selected=false;$("#grid_"+this.name+"_rec_"+w2utils.escapeId(recid)).removeData("selected");$("#grid_"+this.name+"_cell_"+index+"_select_check").prop("checked",false)}}this.trigger($.extend(eventData,{phase:"after"}))}$("#grid_"+this.name+"_check_all").prop("checked",true);if($("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length!=0&&$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length==$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]:checked").length){$("#grid_"+this.name+"_check_all").prop("checked",true)}else{$("#grid_"+this.name+"_check_all").prop("checked",false)}this.status();this.addRange("selection");return unselected},selectAll:function(){if(this.multiSelect===false)return;var eventData=this.trigger({phase:"before",type:"select",target:this.name,all:true});if(eventData.isCancelled===true)return;var cols=[];for(var c in this.columns)cols.push(parseInt(c));var url=typeof this.url!="object"?this.url:this.url.get;if(!url){if(this.searchData.length==0){this.set({selected:true});if(this.selectType=="row"){this.set({selected:true})}else{this.set({selected:true,selectedColumns:cols.slice()})}}else{for(var i=0;i=1)this.toolbar.enable("delete");else this.toolbar.disable("delete");this.addRange("selection");this.trigger($.extend(eventData,{phase:"after"}))},selectNone:function(){var eventData=this.trigger({phase:"before",type:"unselect",target:this.name,all:true});if(eventData.isCancelled===true)return;this.last.selected=[];for(var i in this.records){var rec=this.records[i];if(rec.selected===true){rec.selected=false;var tmp=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(rec.recid));tmp.removeClass("w2ui-selected").removeData("selected");$("#grid_"+this.name+"_cell_"+i+"_select_check").prop("checked",false);if(this.selectType!="row"){var cols=rec.selectedColumns;for(var c in cols)tmp.find(" > td[col="+cols[c]+"]").removeClass("w2ui-selected");rec.selectedColumns=[]}}}this.toolbar.disable("edit","delete");this.removeRange("selection");this.trigger($.extend(eventData,{phase:"after"}))},getSelection:function(returnIndex){if(this.selectType=="row"){var sel=this.find({selected:true},true);var ret=[];for(var s in sel){if(returnIndex===true){ret.push(sel[s])}else{ret.push(this.records[sel[s]].recid)}}return ret}else{var sel=this.find({selected:true},true);var ret=[];for(var s in sel){var rec=this.records[sel[s]];for(var c in rec.selectedColumns){ret.push({recid:rec.recid,index:parseInt(sel[s]),column:rec.selectedColumns[c]})}}return ret}},search:function(field,value){var obj=this;var url=typeof this.url!="object"?this.url:this.url.get;var searchData=[];var last_multi=this.last.multi;var last_logic=this.last.logic;var last_field=this.last.field;var last_search=this.last.search;if(arguments.length==0){last_search="";for(var s in this.searches){var search=this.searches[s];var operator=$("#grid_"+this.name+"_operator_"+s).val();var value1=$("#grid_"+this.name+"_field_"+s).val();var value2=$("#grid_"+this.name+"_field2_"+s).val();if(value1!=""&&value1!=null||typeof value2!="undefined"&&value2!=""){var tmp={field:search.field,type:search.type,operator:operator};if(operator=="between"){$.extend(tmp,{value:[value1,value2]})}else if(operator=="in"){$.extend(tmp,{value:value1.split(",")})}else{$.extend(tmp,{value:value1})}try{if(search.type=="date"&&operator=="between"){tmp.value[0]=w2utils.isDate(value1,w2utils.settings.date_format,true).getTime();tmp.value[1]=w2utils.isDate(value2,w2utils.settings.date_format,true).getTime()}if(search.type=="date"&&operator=="is"){tmp.value=w2utils.isDate(value1,w2utils.settings.date_format,true).getTime()}}catch(e){}searchData.push(tmp)}}if(searchData.length>0&&!url){last_multi=true;last_logic="AND"}else{last_multi=true;last_logic="AND"}}if(typeof field=="string"){last_field=field;last_search=value;last_multi=false;last_logic="OR";if(typeof value!="undefined"){if(field.toLowerCase()=="all"){if(this.searches.length>0){for(var s in this.searches){var search=this.searches[s];if(search.type=="text"||search.type=="int"&&w2utils.isInt(value)||search.type=="float"&&w2utils.isFloat(value)||search.type=="money"&&w2utils.isMoney(value)||search.type=="hex"&&w2utils.isHex(value)||search.type=="date"&&w2utils.isDate(value)||search.type=="alphaNumeric"&&w2utils.isAlphaNumeric(value)){var tmp={field:search.field,type:search.type,operator:search.type=="text"?"contains":"is",value:value};searchData.push(tmp)}if(search.type=="int"&&String(value).indexOf("-")!=-1){var t=String(value).split("-");var tmp={field:search.field,type:search.type,operator:"between",value:[t[0],t[1]]};searchData.push(tmp)}}}else{for(var c in this.columns){var tmp={field:this.columns[c].field,type:"text",operator:"contains",value:value};searchData.push(tmp)}}}else{var search=this.getSearch(field);if(search==null)search={field:field,type:"text"};if(search.field==field)this.last.caption=search.caption;if(value!=""){var op="contains";var val=value;if(w2utils.isInt(value)){op="is";val=value}if(search.type=="int"&&value!=""){if(String(value).indexOf("-")!=-1){var tmp=value.split("-");if(tmp.length==2){op="between";val=[parseInt(tmp[0]),parseInt(tmp[1])]}}if(String(value).indexOf(",")!=-1){var tmp=value.split(",");op="in";val=[];for(var t in tmp)val.push(tmp[t])}}var tmp={field:search.field,type:search.type,operator:op,value:val};searchData.push(tmp)}}}}if($.isArray(field)){var logic="AND";if(typeof value=="string"){logic=value.toUpperCase();if(logic!="OR"&&logic!="AND")logic="AND"}last_search="";last_multi=true;last_logic=logic;for(var f in field){var data=field[f];var search=this.getSearch(data.field);if(search==null)search={type:"text",operator:"contains"};searchData.push($.extend(true,{},search,data))}}var eventData=this.trigger({phase:"before",type:"search",target:this.name,searchData:searchData,searchField:field?field:"multi",searchValue:value?value:"multi"});if(eventData.isCancelled===true)return;this.searchData=eventData.searchData;this.last.field=last_field;this.last.search=last_search;this.last.multi=last_multi;this.last.logic=last_logic;this.last.scrollTop=0;this.last.scrollLeft=0;this.last.selected=[];this.searchClose();this.set({expanded:false});if(url){this.last.xhr_offset=0;this.reload()}else{this.localSearch();this.refresh()}this.trigger($.extend(eventData,{phase:"after"}))},searchOpen:function(){if(!this.box)return;if(this.searches.length==0)return;var obj=this;$("#tb_"+this.name+"_toolbar_item_search-advanced").w2overlay(this.getSearchesHTML(),{left:-10,"class":"w2ui-grid-searches",onShow:function(){if(obj.last.logic=="OR")obj.searchData=[];obj.initSearches();$("#w2ui-overlay .w2ui-grid-searches").data("grid-name",obj.name);var sfields=$("#w2ui-overlay .w2ui-grid-searches *[rel=search]");if(sfields.length>0)sfields[0].focus()}})},searchClose:function(){if(!this.box)return;if(this.searches.length==0)return;if(this.toolbar)this.toolbar.uncheck("search-advanced");if($("#w2ui-overlay .w2ui-grid-searches").length>0)$().w2overlay()},searchShowFields:function(el){if(typeof el=="undefined")el=$("#grid_"+this.name+"_search_all");var html='
';for(var s=-1;s'+'
"+"
"+search.caption+"
"+""
+}html+="
";$(el).w2overlay(html,{left:-15,top:7})},searchReset:function(noRefresh){var eventData=this.trigger({phase:"before",type:"search",target:this.name,searchData:[]});if(eventData.isCancelled===true)return;this.searchData=[];this.last.search="";this.last.logic="OR";if(this.last.multi){if(!this.multiSearch){this.last.field=this.searches[0].field;this.last.caption=this.searches[0].caption}else{this.last.field="all";this.last.caption=w2utils.lang("All Fields")}}this.last.multi=false;this.last.xhr_offset=0;this.last.scrollTop=0;this.last.scrollLeft=0;this.last.selected=[];this.searchClose();if(!noRefresh)this.reload();this.trigger($.extend(eventData,{phase:"after"}))},clear:function(noRefresh){this.offset=0;this.total=0;this.buffered=0;this.records=[];this.summary=[];this.last.scrollTop=0;this.last.scrollLeft=0;this.last.range_start=null;this.last.range_end=null;this.last.xhr_offset=0;if(!noRefresh)this.refresh()},reset:function(noRefresh){this.offset=0;this.last.scrollTop=0;this.last.scrollLeft=0;this.last.selected=[];this.last.range_start=null;this.last.range_end=null;this.last.xhr_offset=0;this.searchReset(noRefresh);if(this.last.sortData!=null)this.sortData=this.last.sortData;this.set({selected:false,expanded:false},true);if(!noRefresh)this.refresh()},skip:function(offset){var url=typeof this.url!="object"?this.url:this.url.get;if(url){this.offset=parseInt(offset);if(this.offset<0||!w2utils.isInt(this.offset))this.offset=0;if(this.offset>this.total)this.offset=this.total-this.limit;this.records=[];this.buffered=0;this.last.xhr_offset=0;this.last.pull_more=true;this.last.scrollTop=0;this.last.scrollLeft=0;$("#grid_"+this.name+"_records").prop("scrollTop",0);this.initColumnOnOff();this.reload()}else{console.log("ERROR: grid.skip() can only be called when you have remote data source.")}},load:function(url,callBack){if(typeof url=="undefined"){console.log('ERROR: You need to provide url argument when calling .load() method of "'+this.name+'" object.');return}this.request("get-records",{},url,callBack)},reload:function(callBack){var url=typeof this.url!="object"?this.url:this.url.get;if(url){if(this.last.xhr_offset>0&&this.last.xhr_offset div");if(edit.type=="enum")console.log("ERROR: Grid's inline editing does not support enum field type.");if(edit.type=="list"||edit.type=="select")console.log("ERROR: Grid's inline editing does not support list/select field type.");if(typeof edit.inTag=="undefined")edit.inTag="";if(typeof edit.outTag=="undefined")edit.outTag="";if(typeof edit.style=="undefined")edit.style="";if(typeof edit.items=="undefined")edit.items=[];var val=rec.changed&&rec.changes[col.field]?w2utils.stripTags(rec.changes[col.field]):w2utils.stripTags(rec[col.field]);if(val==null||typeof val=="undefined")val="";if(typeof value!="undefined"&&value!=null)val=value;var addStyle=typeof col.style!="undefined"?col.style+";":"";if($.inArray(col.render,["number","int","float","money","percent"])!=-1)addStyle+="text-align: right;";el.addClass("w2ui-editable").html('"+edit.outTag);el.find("input").w2field(edit.type,edit).on("blur",function(event){if(obj.parseField(rec,col.field)!=this.value){var eventData2=obj.trigger({phase:"before",type:"change",target:obj.name,input_id:this.id,recid:recid,column:column,value_new:this.value,value_previous:rec.changes?rec.changes[col.field]:obj.parseField(rec,col.field),value_original:obj.parseField(rec,col.field)});if(eventData2.isCancelled===true){}else{rec.changed=true;rec.changes=rec.changes||{};rec.changes[col.field]=eventData2.value_new;obj.trigger($.extend(eventData2,{phase:"after"}))}}else{if(rec.changes)delete rec.changes[col.field];if($.isEmptyObject(rec.changes))delete rec.changes}$(tr).replaceWith(obj.getRecordHTML(index,tr.attr("line")))}).on("keydown",function(event){var cancel=false;switch(event.keyCode){case 9:cancel=true;var next=event.shiftKey?prevCell(column):nextCell(column);if(next!=column){this.blur();setTimeout(function(){if(obj.selectType!="row"){obj.selectNone();obj.select({recid:recid,column:next})}else{obj.editField(recid,next,null,event)}},1)}break;case 13:cancel=true;var next=event.shiftKey?prevRow(index):nextRow(index);if(next!=index){this.blur();setTimeout(function(){if(obj.selectType!="row"){obj.selectNone();obj.select({recid:obj.records[next].recid,column:column})}else{obj.editField(obj.records[next].recid,column,null,event)}},1)}break;case 38:cancel=true;var next=prevRow(index);if(next!=index){this.blur();setTimeout(function(){if(obj.selectType!="row"){obj.selectNone();obj.select({recid:obj.records[next].recid,column:column})}else{obj.editField(obj.records[next].recid,column,null,event)}},1)}break;case 40:cancel=true;var next=nextRow(index);if(next!=index){this.blur();setTimeout(function(){if(obj.selectType!="row"){obj.selectNone();obj.select({recid:obj.records[next].recid,column:column})}else{obj.editField(obj.records[next].recid,column,null,event)}},1)}break;case 27:var old=rec.changed&&rec.changes[col.field]?rec.changes[col.field]:obj.parseField(rec,col.field);this.value=typeof old!="undefined"?old:"";this.blur();setTimeout(function(){obj.select({recid:recid,column:column})},1);break}if(cancel)if(event.preventDefault)event.preventDefault();function nextCell(check){var newCheck=check+1;if(obj.columns.length==newCheck)return check;if(obj.columns[newCheck].hidden)return nextCell(newCheck);return newCheck}function prevCell(check){var newCheck=check-1;if(newCheck<0)return check;if(obj.columns[newCheck].hidden)return prevCell(newCheck);return newCheck}function nextRow(check){var newCheck=check+1;if(obj.records.length==newCheck)return check;return newCheck}function prevRow(check){var newCheck=check-1;if(newCheck<0)return check;return newCheck}});if(typeof value=="undefined"||value==null){el.find("input").focus()}else{el.find("input").val("").focus().val(value)}obj.trigger($.extend(eventData,{phase:"after"}))},"delete":function(force){var obj=this;var eventData=this.trigger({phase:"before",target:this.name,type:"delete",force:force});if(eventData.isCancelled===true)return false;force=eventData.force;var recs=this.getSelection();if(recs.length==0)return;if(this.msgDelete!=""&&!force){w2confirm(obj.msgDelete,w2utils.lang("Delete Confirmation"),function(result){if(result=="Yes")w2ui[obj.name].delete(true)});return}var url=typeof this.url!="object"?this.url:this.url.remove;if(url){this.request("delete-records")}else{if(typeof recs[0]!="object"){this.remove.apply(this,recs)}else{for(var r in recs){var fld=this.columns[recs[r].column].field;var ind=this.get(recs[r].recid,true);if(ind!=null&&fld!="recid"){this.records[ind][fld]="";if(this.records[ind].changed)this.records[ind].changes[fld]=""}}this.refresh()}}this.trigger($.extend(eventData,{phase:"after"}))},click:function(recid,event){var time=(new Date).getTime();var column=null;if(typeof recid=="object"){column=recid.column;recid=recid.recid}if(w2utils.isInt(recid))recid=parseInt(recid);if(typeof event=="undefined")event={};if(time-parseInt(this.last.click_time)<250&&event.type=="click"){this.dblClick(recid,event);return}this.last.click_time=time;if(column==null&&event.target){var tmp=event.target;if(tmp.tagName!="TD")tmp=$(tmp).parents("td")[0];if(typeof $(tmp).attr("col")!="undefined")column=parseInt($(tmp).attr("col"))}var eventData=this.trigger({phase:"before",target:this.name,type:"click",recid:recid,column:column,originalEvent:event});if(eventData.isCancelled===true)return false;var parent=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(recid)).parents("tr");if(parent.length>0&&String(parent.attr("id")).indexOf("expanded_row")!=-1){var grid=parent.parents(".w2ui-grid").attr("name");w2ui[grid].selectNone();parent.parents(".w2ui-grid").find(".w2ui-expanded-row .w2ui-grid").each(function(index,el){var grid=$(el).attr("name");if(w2ui[grid])w2ui[grid].selectNone()})}$(this.box).find(".w2ui-expanded-row .w2ui-grid").each(function(index,el){var grid=$(el).attr("name");if(w2ui[grid])w2ui[grid].selectNone()});var obj=this;var sel=this.getSelection();$("#grid_"+this.name+"_check_all").prop("checked",false);var ind=this.get(recid,true);var record=this.records[ind];var selectColumns=[];obj.last.sel_ind=ind;obj.last.sel_col=column;obj.last.sel_recid=recid;obj.last.sel_type="click";if(event.shiftKey&&sel.length>0){if(sel[0].recid){var start=this.get(sel[0].recid,true);var end=this.get(recid,true);if(column>sel[0].column){var t1=sel[0].column;var t2=column}else{var t1=column;var t2=sel[0].column}for(var c=t1;c<=t2;c++)selectColumns.push(c)}else{var start=this.get(sel[0],true);var end=this.get(recid,true)}var sel_add=[];if(start>end){var tmp=start;start=end;end=tmp}var url=typeof this.url!="object"?this.url:this.url.get;for(var i=start;i<=end;i++){if(this.searchData.length>0&&!url&&$.inArray(i,this.last.searchIds)==-1)continue;if(this.selectType=="row"){sel_add.push(this.records[i].recid)}else{for(var sc in selectColumns)sel_add.push({recid:this.records[i].recid,column:selectColumns[sc]})}}this.select.apply(this,sel_add)}else{if((!event.ctrlKey&&!event.shiftKey&&!event.metaKey||!this.multiSelect)&&!this.showSelectColumn){var flag=record.selected;if(this.selectType!="row"&&$.inArray(column,record.selectedColumns)==-1)flag=false;if(sel.length>300)this.selectNone();else this.unselect.apply(this,sel);if(flag===true){this.unselect({recid:recid,column:column})}else{this.select({recid:recid,column:column})}}else{var flag=record.selected;if(this.selectType!="row"&&$.inArray(column,record.selectedColumns)==-1)flag=false;if(flag===true){this.unselect({recid:recid,column:column})}else{this.select({recid:record.recid,column:column})}setTimeout(function(){if(window.getSelection)window.getSelection().removeAllRanges()},10)}}this.status();obj.last.selected=this.getSelection();obj.initResize();this.trigger($.extend(eventData,{phase:"after"}))},columnClick:function(field,event){var eventData=this.trigger({phase:"before",type:"columnClick",target:this.name,field:field,originalEvent:event});if(eventData.isCancelled===true)return false;this.sort(field,null,event&&(event.ctrlKey||event.metaKey)?true:false);this.trigger($.extend(eventData,{phase:"after"}))},keydown:function(event){var obj=this;if(obj.keyboard!==true)return;var eventData=obj.trigger({phase:"before",type:"keydown",target:obj.name,originalEvent:event});if(eventData.isCancelled===true)return false;var sel=obj.getSelection();if(sel.length==0)return;var records=$("#grid_"+obj.name+"_records");var recid=sel[0];var columns=[];var recid2=sel[sel.length-1];if(typeof recid=="object"){recid=sel[0].recid;columns=[];var ii=0;while(true){if(!sel[ii]||sel[ii].recid!=recid)break;columns.push(sel[ii].column);ii++}recid2=sel[sel.length-1].recid}var ind=obj.get(recid,true);var ind2=obj.get(recid2,true);var rec=obj.get(recid);var recEL=$("#grid_"+obj.name+"_rec_"+w2utils.escapeId(obj.records[ind].recid));var cancel=false;switch(event.keyCode){case 8:case 46:obj.delete();cancel=true;event.stopPropagation();break;case 27:var sel=obj.getSelection();obj.selectNone();if(sel.length>0){if(typeof sel[0]=="object"){obj.select({recid:sel[0].recid,column:sel[0].column})}else{obj.select(sel[0])}}cancel=true;break;case 13:case 32:if(columns.length==0)columns.push(0);obj.editField(recid,columns[0],null,event);cancel=true;break;case 65:if(!event.metaKey&&!event.ctrlKey)break;obj.selectAll();cancel=true;break;case 70:if(!event.metaKey&&!event.ctrlKey)break;$("#grid_"+obj.name+"_search_all").focus();cancel=true;break;case 13:if(this.selectType=="row"){if(recEL.length<=0||obj.show.expandColumn!==true)break;obj.toggle(recid,event);cancel=true}else{if(columns.length==0)columns.push(0);obj.editField(recid,columns[0],null,event);cancel=true}break;case 37:var parent=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(obj.records[ind].recid)).parents("tr");if(parent.length>0&&String(parent.attr("id")).indexOf("expanded_row")!=-1){var recid=parent.prev().attr("recid");var grid=parent.parents(".w2ui-grid").attr("name");obj.selectNone();w2utils.keyboard.active(grid);w2ui[grid].set(recid,{expanded:false});w2ui[grid].collapse(recid);w2ui[grid].click(recid);cancel=true;break}if(this.selectType=="row"){if(recEL.length<=0||rec.expanded!==true)break;obj.set(recid,{expanded:false},true);obj.collapse(recid,event)}else{var prev=prevCell(columns[0]);if(prev!=columns[0]){if(event.shiftKey){if(tmpUnselect())return;var tmp=[];var newSel=[];var unSel=[];if(columns.indexOf(this.last.sel_col)==0&&columns.length>1){for(var i in sel){if(tmp.indexOf(sel[i].recid)==-1)tmp.push(sel[i].recid);unSel.push({recid:sel[i].recid,column:columns[columns.length-1]})}}else{for(var i in sel){if(tmp.indexOf(sel[i].recid)==-1)tmp.push(sel[i].recid);newSel.push({recid:sel[i].recid,column:prev})}}obj.unselect.apply(obj,unSel);obj.select.apply(obj,newSel)}else{obj.click({recid:recid,column:prev},event)}}else{if(!event.shiftKey){for(var s=1;s1){for(var i in sel){if(tmp.indexOf(sel[i].recid)==-1)tmp.push(sel[i].recid);unSel.push({recid:sel[i].recid,column:columns[0]})}}else{for(var i in sel){if(tmp.indexOf(sel[i].recid)==-1)tmp.push(sel[i].recid);newSel.push({recid:sel[i].recid,column:next})}}obj.unselect.apply(obj,unSel);obj.select.apply(obj,newSel)}else{obj.click({recid:recid,column:next},event)}}else{if(!event.shiftKey){for(var s=0;s0&&w2ui[subgrid.attr("name")]){obj.selectNone();var grid=subgrid.attr("name");var recs=w2ui[grid].records;w2utils.keyboard.active(grid);w2ui[grid].click(recs[recs.length-1].recid);cancel=true;break}}if(event.shiftKey){if(tmpUnselect())return;if(obj.selectType=="row"){if(obj.last.sel_ind>prev&&obj.last.sel_ind!=ind2){obj.unselect(obj.records[ind2].recid)}else{obj.select(obj.records[prev].recid)}}else{if(obj.last.sel_ind>prev&&obj.last.sel_ind!=ind2){prev=ind2;var tmp=[];for(var c in columns)tmp.push({recid:obj.records[prev].recid,column:columns[c]});obj.unselect.apply(obj,tmp)}else{var tmp=[];for(var c in columns)tmp.push({recid:obj.records[prev].recid,column:columns[c]});obj.select.apply(obj,tmp)}}}else{obj.selectNone();obj.click({recid:obj.records[prev].recid,column:columns[0]},event)}obj.scrollIntoView(prev);if(event.preventDefault)event.preventDefault()}else{if(!event.shiftKey){for(var s=1;s0&&String(parent.attr("id")).indexOf("expanded_row")!=-1){var recid=parent.prev().attr("recid");var grid=parent.parents(".w2ui-grid").attr("name");obj.selectNone();w2utils.keyboard.active(grid);w2ui[grid].click(recid);cancel=true;break}}break;case 40:if(recEL.length<=0)break;if(obj.records[ind2].expanded){var subgrid=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(obj.records[ind2].recid)+"_expanded_row").find(".w2ui-grid");if(subgrid.length>0&&w2ui[subgrid.attr("name")]){obj.selectNone();var grid=subgrid.attr("name");var recs=w2ui[grid].records;w2utils.keyboard.active(grid);w2ui[grid].click(recs[0].recid);cancel=true;break}}var next=nextRow(ind2);if(next!=null){if(event.shiftKey){if(tmpUnselect())return;if(obj.selectType=="row"){if(this.last.sel_ind0&&String(parent.attr("id")).indexOf("expanded_row")!=-1){var recid=parent.next().attr("recid");var grid=parent.parents(".w2ui-grid").attr("name");obj.selectNone();w2utils.keyboard.active(grid);w2ui[grid].click(recid);cancel=true;break}}break;case 86:if(event.ctrlKey||event.metaKey){$("body").append('');$("#_tmp_copy_data").focus();setTimeout(function(){obj.paste($("#_tmp_copy_data").val());$("#_tmp_copy_data").remove()},50)}break;case 88:if(event.ctrlKey||event.metaKey){setTimeout(function(){obj.delete(true)},100)}case 67:if(event.ctrlKey||event.metaKey){var text=obj.copy();$("body").append('");$("#_tmp_copy_data").focus().select();setTimeout(function(){$("#_tmp_copy_data").remove()},50)}break}var tmp=[187,189];for(var i=48;i<=90;i++)tmp.push(i);if(tmp.indexOf(event.keyCode)!=-1&&!event.ctrlKey&&!event.metaKey&&!cancel){if(columns.length==0)columns.push(0);var tmp=String.fromCharCode(event.keyCode);if(event.keyCode==187)tmp="=";if(event.keyCode==189)tmp="-";if(!event.shiftKey)tmp=tmp.toLowerCase();obj.editField(recid,columns[0],tmp,event);cancel=true}if(cancel){if(event.preventDefault)event.preventDefault()}obj.trigger($.extend(eventData,{phase:"after"}));function nextRow(ind){if(ind+10&&ind0){while(true){if($.inArray(ind,obj.last.searchIds)!=-1||ind>obj.records.length)break;ind++}}return ind}else{return null}}function prevRow(ind){if(ind>0&&obj.last.searchIds.length==0||obj.last.searchIds.length>0&&ind>obj.last.searchIds[0]){ind--;if(obj.last.searchIds.length>0){while(true){if($.inArray(ind,obj.last.searchIds)!=-1||ind<0)break;ind--}}return ind}else{return null}}function nextCell(check){var newCheck=check+1;if(obj.columns.length==newCheck)return check;if(obj.columns[newCheck].hidden)return findNext(newCheck);return newCheck}function prevCell(check){var newCheck=check-1;if(newCheck<0)return check;if(obj.columns[newCheck].hidden)return findPrev(newCheck);return newCheck}function tmpUnselect(){if(obj.last.sel_type!="click")return false;if(obj.selectType!="row"){obj.last.sel_type="key";if(sel.length>1){for(var s in sel){if(sel[s].recid==obj.last.sel_recid&&sel[s].column==obj.last.sel_col){sel.splice(s,1);break}}obj.unselect.apply(obj,sel);return true}return false}else{obj.last.sel_type="key";if(sel.length>1){sel.splice(sel.indexOf(obj.records[obj.last.sel_ind].recid),1);obj.unselect.apply(obj,sel);return true}return false}}},scrollIntoView:function(ind){if(typeof ind=="undefined"){var sel=this.getSelection();if(sel.length==0)return;ind=this.get(sel[0],true)}var records=$("#grid_"+this.name+"_records");if(records.length==0)return;var len=this.last.searchIds.length;if(records.height()>this.recordHeight*(len>0?len:this.records.length))return;if(len>0)ind=this.last.searchIds.indexOf(ind);var t1=Math.floor(records[0].scrollTop/this.recordHeight);var t2=t1+Math.floor(records.height()/this.recordHeight);if(ind==t1)records.animate({scrollTop:records.scrollTop()-records.height()/1.3});if(ind==t2)records.animate({scrollTop:records.scrollTop()+records.height()/1.3});if(indt2)records.animate({scrollTop:(ind-1)*this.recordHeight})},dblClick:function(recid,event){if(window.getSelection)window.getSelection().removeAllRanges();var column=null;if(typeof recid=="object"){column=recid.column;recid=recid.recid}if(typeof event=="undefined")event={};if(column==null&&event.target){var tmp=event.target;if(tmp.tagName!="TD")tmp=$(tmp).parents("td")[0];column=parseInt($(tmp).attr("col"))}var eventData=this.trigger({phase:"before",target:this.name,type:"dblClick",recid:recid,column:column,originalEvent:event});if(eventData.isCancelled===true)return false;this.selectNone();var col=this.columns[column];if(col&&$.isPlainObject(col.editable)){this.editField(recid,column,null,event)}else{this.select({recid:recid,column:column});this.last.selected=this.getSelection()}this.trigger($.extend(eventData,{phase:"after"}))},toggle:function(recid){var rec=this.get(recid);if(rec.expanded===true)return this.collapse(recid);else return this.expand(recid)},expand:function(recid){var rec=this.get(recid);var obj=this;var id=w2utils.escapeId(recid);if($("#grid_"+this.name+"_rec_"+id+"_expanded_row").length>0)return false;if(rec.expanded=="none")return false;var tmp=1+(this.show.selectColumn?1:0);var addClass="";$("#grid_"+this.name+"_rec_"+id).after('
'+(this.show.lineNumbers?'
':"")+'
'+'
'+' '+"
"+"
");var eventData=this.trigger({phase:"before",type:"expand",target:this.name,recid:recid,box_id:"grid_"+this.name+"_rec_"+id+"_expanded",ready:ready});if(eventData.isCancelled===true){$("#grid_"+this.name+"_rec_"+id+"_expanded_row").remove();return false}$("#grid_"+this.name+"_rec_"+id).attr("expanded","yes").addClass("w2ui-expanded");$("#grid_"+this.name+"_rec_"+id+"_expanded_row").show();$("#grid_"+this.name+"_cell_"+this.get(recid,true)+"_expand div").html('');rec.expanded=true;setTimeout(ready,300);function ready(){var div1=$("#grid_"+obj.name+"_rec_"+id+"_expanded");var div2=$("#grid_"+obj.name+"_rec_"+id+"_expanded_row .w2ui-expanded1 > div");if(div1.height()<5)return;div1.css("opacity",1);div2.show().css("opacity",1);$("#grid_"+obj.name+"_cell_"+obj.get(recid,true)+"_expand div").html("-")}this.trigger($.extend(eventData,{phase:"after"}));this.resizeRecords();return true},collapse:function(recid){var rec=this.get(recid);var obj=this;var id=w2utils.escapeId(recid);if($("#grid_"+this.name+"_rec_"+id+"_expanded_row").length==0)return false;var eventData=this.trigger({phase:"before",type:"collapse",target:this.name,recid:recid,box_id:"grid_"+this.name+"_rec_"+id+"_expanded"});if(eventData.isCancelled===true)return false;$("#grid_"+this.name+"_rec_"+id).removeAttr("expanded").removeClass("w2ui-expanded");$("#grid_"+this.name+"_rec_"+id+"_expanded").css("opacity",0);$("#grid_"+this.name+"_cell_"+this.get(recid,true)+"_expand div").html("+");setTimeout(function(){$("#grid_"+obj.name+"_rec_"+id+"_expanded").height("0px");setTimeout(function(){$("#grid_"+obj.name+"_rec_"+id+"_expanded_row").remove();delete rec.expanded;obj.trigger($.extend(eventData,{phase:"after"}));obj.resizeRecords()},300)},200);return true},sort:function(field,direction,multiField){var eventData=this.trigger({phase:"before",type:"sort",target:this.name,field:field,direction:direction,multiField:multiField});if(eventData.isCancelled===true)return false;if(typeof field!="undefined"){var sortIndex=this.sortData.length;for(var s in this.sortData){if(this.sortData[s].field==field){sortIndex=s;break}}if(typeof direction=="undefined"||direction==null){if(typeof this.sortData[sortIndex]=="undefined"){direction="asc"}else{switch(String(this.sortData[sortIndex].direction)){case"asc":direction="desc";break;case"desc":direction="asc";break;default:direction="asc";break}}}if(this.multiSort===false){this.sortData=[];sortIndex=0}if(multiField!=true){this.sortData=[];sortIndex=0}if(typeof this.sortData[sortIndex]=="undefined")this.sortData[sortIndex]={};this.sortData[sortIndex].field=field;this.sortData[sortIndex].direction=direction}else{this.sortData=[]}var url=typeof this.url!="object"?this.url:this.url.get;if(!url){this.localSort();if(this.searchData.length>0)this.localSearch(true);this.trigger($.extend(eventData,{phase:"after"}));this.refresh()}else{this.trigger($.extend(eventData,{phase:"after"}));this.last.xhr_offset=0;this.reload()}},copy:function(){var sel=this.getSelection();if(sel.length==0)return"";var text="";if(typeof sel[0]=="object"){var minCol=sel[0].column;var maxCol=sel[0].column;var recs=[];for(var s in sel){if(sel[s].columnmaxCol)maxCol=sel[s].column;if(recs.indexOf(sel[s].index)==-1)recs.push(sel[s].index)}recs.sort();for(var r in recs){var ind=recs[r];for(var c=minCol;c<=maxCol;c++){var col=this.columns[c];if(col.hidden===true)continue;text+=w2utils.stripTags(this.getCellHTML(ind,c))+" "}text=text.substr(0,text.length-1);text+="\n"}}else{for(var s in sel){var ind=this.get(sel[s],true);for(var c in this.columns){var col=this.columns[c];if(col.hidden===true)continue;text+=w2utils.stripTags(this.getCellHTML(ind,c))+" "}text=text.substr(0,text.length-1);text+="\n"}}text=text.substr(0,text.length-1);var eventData=this.trigger({phase:"before",type:"copy",target:this.name,text:text});if(eventData.isCancelled===true)return"";text=eventData.text;this.trigger($.extend(eventData,{phase:"after"}));return text},paste:function(text){var sel=this.getSelection();var ind=this.get(sel[0].recid,true);var col=sel[0].column;var eventData=this.trigger({phase:"before",type:"paste",target:this.name,text:text,index:ind,column:col});if(eventData.isCancelled===true)return;text=eventData.text;if(this.selectType=="row"||sel.length==0){console.log("ERROR: You can paste only if grid.selectType = 'cell' and when at least one cell selected.");this.trigger($.extend(eventData,{phase:"after"}));return}var newSel=[];var text=text.split("\n");for(var t in text){var tmp=text[t].split(" ");var cnt=0;var rec=this.records[ind];var cols=[];for(var dt in tmp){if(!this.columns[col+cnt])continue;
+var field=this.columns[col+cnt].field;rec.changed=true;rec.changes=rec.changes||{};rec.changes[field]=tmp[dt];cols.push(col+cnt);cnt++}for(var c in cols)newSel.push({recid:rec.recid,column:cols[c]});ind++}this.selectNone();this.select.apply(this,newSel);this.refresh();this.trigger($.extend(eventData,{phase:"after"}))},resize:function(){var obj=this;var time=(new Date).getTime();if(window.getSelection)window.getSelection().removeAllRanges();if(!this.box||$(this.box).attr("name")!=this.name)return;$(this.box).find("> div").css("width",$(this.box).width()).css("height",$(this.box).height());var eventData=this.trigger({phase:"before",type:"resize",target:this.name});if(eventData.isCancelled===true)return false;obj.resizeBoxes();obj.resizeRecords();this.trigger($.extend(eventData,{phase:"after"}));return(new Date).getTime()-time},refresh:function(){var obj=this;var time=(new Date).getTime();var url=typeof this.url!="object"?this.url:this.url.get;if(this.total<=0&&!url&&this.searchData.length==0){this.total=this.records.length;this.buffered=this.total}if(window.getSelection)window.getSelection().removeAllRanges();this.toolbar.disable("edit","delete");if(!this.box)return;var eventData=this.trigger({phase:"before",target:this.name,type:"refresh"});if(eventData.isCancelled===true)return false;if(this.show.header){$("#grid_"+this.name+"_header").html(this.header+" ").show()}else{$("#grid_"+this.name+"_header").hide()}if(this.show.toolbar){if(this.toolbar&&this.toolbar.get("column-on-off")&&this.toolbar.get("column-on-off").checked){}else{$("#grid_"+this.name+"_toolbar").show();if(typeof this.toolbar=="object"){this.toolbar.refresh();var tmp=$("#grid_"+obj.name+"_search_all");tmp.val(this.last.search)}}}else{$("#grid_"+this.name+"_toolbar").hide()}this.searchClose();var searchEl=$("#grid_"+obj.name+"_search_all");if(this.searches.length==0){this.last.field="all"}if(!this.multiSearch&&this.last.field=="all"&&this.searches.length>0){this.last.field=this.searches[0].field;this.last.caption=this.searches[0].caption}for(var s in this.searches){if(this.searches[s].field==this.last.field)this.last.caption=this.searches[s].caption}if(this.last.multi){searchEl.attr("placeholder","["+w2utils.lang("Multiple Fields")+"]")}else{searchEl.attr("placeholder",this.last.caption)}if(this._focus_when_refreshed===true){clearTimeout(obj._focus_timer);obj._focus_timer=setTimeout(function(){if(searchEl.length>0){searchEl[0].focus()}delete obj._focus_when_refreshed;delete obj._focus_timer},600)}var tmp=this.find({summary:true},true);if(tmp.length>0){for(var t in tmp)this.summary.push(this.records[tmp[t]]);for(var t=tmp.length-1;t>=0;t--)this.records.splice(tmp[t],1);this.total=this.total-tmp.length;this.buffered=this.buffered-tmp.length}var bodyHTML="";bodyHTML+='
'+this.getRecordsHTML()+"
"+'
'+"
"+this.getColumnsHTML()+"
"+"
";$("#grid_"+this.name+"_body").html(bodyHTML);if(this.summary.length>0){$("#grid_"+this.name+"_summary").html(this.getSummaryHTML()).show()}else{$("#grid_"+this.name+"_summary").hide()}if(this.show.footer){$("#grid_"+this.name+"_footer").html(this.getFooterHTML()).show()}else{$("#grid_"+this.name+"_footer").hide()}if(this.last.selected.length>0)for(var s in this.last.selected){if(this.get(this.last.selected[s])!=null){this.select(this.get(this.last.selected[s]).recid)}}if(this.searchData.length>0){$("#grid_"+this.name+"_searchClear").show()}else{$("#grid_"+this.name+"_searchClear").hide()}$("#grid_"+this.name+"_check_all").prop("checked",true);if($("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length!=0&&$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]").length==$("#grid_"+this.name+"_records").find(".grid_select_check[type=checkbox]:checked").length){$("#grid_"+this.name+"_check_all").prop("checked",true)}else{$("#grid_"+this.name+"_check_all").prop("checked",false)}this.status();var rows=obj.find({expanded:true},true);for(var r in rows)obj.records[rows[r]].expanded=false;setTimeout(function(){var str=$.trim($("#grid_"+obj.name+"_search_all").val());if(str!="")$(obj.box).find(".w2ui-grid-data > div").w2marker(str)},50);this.trigger($.extend(eventData,{phase:"after"}));obj.resize();obj.addRange("selection");setTimeout(function(){obj.resize();obj.scroll()},1);return(new Date).getTime()-time},render:function(box){var obj=this;var time=(new Date).getTime();if(window.getSelection)window.getSelection().removeAllRanges();if(typeof box!="undefined"&&box!=null){if($(this.box).find("#grid_"+this.name+"_body").length>0){$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html("")}this.box=box}if(!this.box)return;if(this.last.sortData==null)this.last.sortData=this.sortData;var eventData=this.trigger({phase:"before",target:this.name,type:"render",box:box});if(eventData.isCancelled===true)return false;$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-grid").html("
"+' '+' '+' '+' '+' '+"
");if(this.selectType!="row")$(this.box).addClass("w2ui-ss");if($(this.box).length>0)$(this.box)[0].style.cssText+=this.style;this.initToolbar();if(this.toolbar!=null)this.toolbar.render($("#grid_"+this.name+"_toolbar")[0]);$("#grid_"+this.name+"_footer").html(this.getFooterHTML());this.refresh();this.reload();$(this.box).on("mousedown",mouseStart);$(this.box).on("selectstart",function(){return false});this.trigger($.extend(eventData,{phase:"after"}));if($(".w2ui-layout").length==0){this.tmp_resize=function(event){w2ui[obj.name].resize()};$(window).off("resize",this.tmp_resize).on("resize",this.tmp_resize)}return(new Date).getTime()-time;function mouseStart(event){if(obj.last.move&&obj.last.move.type=="expand")return;obj.last.move={x:event.screenX,y:event.screenY,divX:0,divY:0,recid:$(event.target).parents("tr").attr("recid"),column:event.target.tagName=="TD"?$(event.target).attr("col"):$(event.target).parents("td").attr("col"),type:"select",start:true};$(document).on("mousemove",mouseMove);$(document).on("mouseup",mouseStop)}function mouseMove(event){if(!obj.last.move||obj.last.move.type!="select")return;obj.last.move.divX=event.screenX-obj.last.move.x;obj.last.move.divY=event.screenY-obj.last.move.y;if(Math.abs(obj.last.move.divX)<=1&&Math.abs(obj.last.move.divY)<=1)return;if(obj.last.move.start&&obj.last.move.recid){obj.selectNone();obj.last.move.start=false}var newSel=[];var recid=event.target.tagName=="TR"?$(event.target).attr("recid"):$(event.target).parents("tr").attr("recid");if(typeof recid=="undefined")return;var ind1=obj.get(obj.last.move.recid,true);var ind2=obj.get(recid,true);var col1=parseInt(obj.last.move.column);var col2=parseInt(event.target.tagName=="TD"?$(event.target).attr("col"):$(event.target).parents("td").attr("col"));if(ind1>ind2){var tmp=ind1;ind1=ind2;ind2=tmp}var tmp="ind1:"+ind1+",ind2;"+ind2+",col1:"+col1+",col2:"+col2;if(obj.last.move.range==tmp)return;obj.last.move.range=tmp;for(var i=ind1;i<=ind2;i++){if(obj.last.searchIds.length>0&&obj.last.searchIds.indexOf(i)==-1)continue;if(obj.selectType!="row"){if(col1>col2){var tmp=col1;col1=col2;col2=tmp}var tmp=[];for(var c=col1;c<=col2;c++){if(obj.columns[c].hidden)continue;newSel.push({recid:obj.records[i].recid,column:parseInt(c)})}}else{newSel.push(obj.records[i].recid)}}if(obj.selectType!="row"){var sel=obj.getSelection();var tmp=[];for(var ns in newSel){var flag=false;for(var s in sel)if(newSel[ns].recid==sel[s].recid&&newSel[ns].column==sel[s].column)flag=true;if(!flag)tmp.push({recid:newSel[ns].recid,column:newSel[ns].column})}obj.select.apply(obj,tmp);var tmp=[];for(var s in sel){var flag=false;for(var ns in newSel)if(newSel[ns].recid==sel[s].recid&&newSel[ns].column==sel[s].column)flag=true;if(!flag)tmp.push({recid:sel[s].recid,column:sel[s].column})}obj.unselect.apply(obj,tmp)}else{if(obj.multiSelect){var sel=obj.getSelection();for(var ns in newSel)if(sel.indexOf(newSel[ns])==-1)obj.select(newSel[ns]);for(var s in sel)if(newSel.indexOf(sel[s])==-1)obj.unselect(sel[s])}}}function mouseStop(event){if(!obj.last.move||obj.last.move.type!="select")return;delete obj.last.move;$(document).off("mousemove",mouseMove);$(document).off("mouseup",mouseStop)}},destroy:function(){var eventData=this.trigger({phase:"before",target:this.name,type:"destroy"});if(eventData.isCancelled===true)return false;$(window).off("resize",this.tmp_resize);if(typeof this.toolbar=="object"&&this.toolbar.destroy)this.toolbar.destroy();if($(this.box).find("#grid_"+this.name+"_body").length>0){$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html("")}delete w2ui[this.name];this.trigger($.extend(eventData,{phase:"after"}))},initColumnOnOff:function(){if(!this.show.toolbarColumns)return;var obj=this;var col_html='
'+"
";for(var c in this.columns){var col=this.columns[c];col_html+="
";this.toolbar.get("column-on-off").html=col_html},columnOnOff:function(el,event,field,value){var eventData=this.trigger({phase:"before",target:this.name,type:"columnOnOff",checkbox:el,field:field,originalEvent:event});if(eventData.isCancelled===true)return false;var obj=this;for(var r in this.records){if(this.records[r].expanded===true)this.records[r].expanded=false}var hide=true;if(field=="line-numbers"){this.show.lineNumbers=!this.show.lineNumbers;this.refresh()}else if(field=="skip"){if(!w2utils.isInt(value))value=0;obj.skip(value)}else if(field=="resize"){for(var c in this.columns){if(typeof this.columns[c].sizeOriginal!="undefined"){this.columns[c].size=this.columns[c].sizeOriginal}}this.initResize();this.resize()}else{var col=this.getColumn(field);if(col.hidden){$(el).prop("checked",true);this.showColumn(col.field)}else{$(el).prop("checked",false);this.hideColumn(col.field)}hide=false}this.initColumnOnOff();if(hide){setTimeout(function(){$().w2overlay();obj.toolbar.uncheck("column-on-off")},100)}this.trigger($.extend(eventData,{phase:"after"}))},initToolbar:function(){if(typeof this.toolbar["render"]=="undefined"){var tmp_items=this.toolbar.items;this.toolbar.items=[];this.toolbar=$().w2toolbar($.extend(true,{},this.toolbar,{name:this.name+"_toolbar",owner:this}));if(this.show.toolbarReload){this.toolbar.items.push($.extend(true,{},this.buttons["reload"]))}if(this.show.toolbarColumns){this.toolbar.items.push($.extend(true,{},this.buttons["columns"]));this.initColumnOnOff()}if(this.show.toolbarReload||this.show.toolbarColumn){this.toolbar.items.push({type:"break",id:"break0"})}if(this.show.toolbarSearch){var html='
'+'
'+"
"+this.buttons["search"].html+"
"+"
"+' '+"
"+"
"+'
"+"
"+"
"+"
";this.toolbar.items.push({type:"html",id:"search",html:html});if(this.multiSearch&&this.searches.length>0){this.toolbar.items.push($.extend(true,{},this.buttons["search-go"]))}}if(this.show.toolbarSearch&&(this.show.toolbarAdd||this.show.toolbarEdit||this.show.toolbarDelete||this.show.toolbarSave)){this.toolbar.items.push({type:"break",id:"break1"})}if(this.show.toolbarAdd){this.toolbar.items.push($.extend(true,{},this.buttons["add"]))}if(this.show.toolbarEdit){this.toolbar.items.push($.extend(true,{},this.buttons["edit"]))}if(this.show.toolbarDelete){this.toolbar.items.push($.extend(true,{},this.buttons["delete"]))}if(this.show.toolbarSave){if(this.show.toolbarAdd||this.show.toolbarDelete||this.show.toolbarEdit){this.toolbar.items.push({type:"break",id:"break2"})}this.toolbar.items.push($.extend(true,{},this.buttons["save"]))}for(var i in tmp_items)this.toolbar.items.push(tmp_items[i]);var obj=this;this.toolbar.on("click",function(event){var eventData=obj.trigger({phase:"before",type:"toolbar",target:event.target,originalEvent:event});if(eventData.isCancelled===true)return false;var id=event.target;switch(id){case"reload":var eventData2=obj.trigger({phase:"before",type:"reload",target:obj.name});if(eventData2.isCancelled===true)return false;var url=typeof obj.url!="object"?obj.url:obj.url.get;if(url){obj.clear(true)}else{obj.last.scrollTop=0;obj.last.scrollLeft=0;obj.last.range_start=null;obj.last.range_end=null}obj.reload();obj.trigger($.extend(eventData2,{phase:"after"}));break;case"column-on-off":for(var c in obj.columns){if(obj.columns[c].hidden){$("#grid_"+obj.name+"_column_"+c+"_check").prop("checked",false)}else{$("#grid_"+obj.name+"_column_"+c+"_check").prop("checked",true)}}obj.initResize();obj.resize();break;case"search-advanced":var tb=this;var it=this.get(id);if(it.checked){obj.searchClose();setTimeout(function(){tb.uncheck(id)},1)}else{obj.searchOpen();event.originalEvent.stopPropagation();function tmp_close(){tb.uncheck(id);$(document).off("click","body",tmp_close)}$(document).on("click","body",tmp_close)}break;case"add":var eventData=obj.trigger({phase:"before",target:obj.name,type:"add",recid:null});obj.trigger($.extend(eventData,{phase:"after"}));break;case"edit":var sel=obj.getSelection();var recid=null;if(sel.length==1)recid=sel[0];var eventData=obj.trigger({phase:"before",target:obj.name,type:"edit",recid:recid});obj.trigger($.extend(eventData,{phase:"after"}));break;case"delete":obj.delete();break;case"save":obj.save();break}obj.trigger($.extend(eventData,{phase:"after"}))})}return},initSearches:function(){var obj=this;for(var s in this.searches){var search=this.searches[s];var sdata=this.getSearchData(search.field);switch(String(search.type).toLowerCase()){case"alphaNumeric":case"text":$("#grid_"+this.name+"_operator_"+s).val("begins with");break;case"int":case"float":case"hex":case"money":case"date":$("#grid_"+this.name+"_field_"+s).w2field("clear").w2field(search.type);$("#grid_"+this.name+"_field2_"+s).w2field("clear").w2field(search.type);break;case"list":var options='';for(var i in search.items){if($.isPlainObject(search.items[i])){var val=search.items[i].id;var txt=search.items[i].text;if(typeof val=="undefined"&&typeof search.items[i].value!="undefined")val=search.items[i].value;if(typeof txt=="undefined"&&typeof search.items[i].caption!="undefined")txt=search.items[i].caption;if(val==null)val="";options+='"}else{options+='"}}$("#grid_"+this.name+"_field_"+s).html(options);break}if(sdata!=null){$("#grid_"+this.name+"_operator_"+s).val(sdata.operator).trigger("change");if(!$.isArray(sdata.value)){if(typeof sdata.value!="udefined")$("#grid_"+this.name+"_field_"+s).val(sdata.value).trigger("change")}else{if(sdata.operator=="in"){$("#grid_"+this.name+"_field_"+s).val(sdata.value).trigger("change")}else{$("#grid_"+this.name+"_field_"+s).val(sdata.value[0]).trigger("change");$("#grid_"+this.name+"_field2_"+s).val(sdata.value[1]).trigger("change")}}}}$("#w2ui-overlay .w2ui-grid-searches *[rel=search]").on("keypress",function(evnt){if(evnt.keyCode==13){obj.search()}})},initResize:function(){var obj=this;$(this.box).find(".w2ui-resizer").off("click").on("click",function(event){if(event.stopPropagation)event.stopPropagation();else event.cancelBubble=true;if(event.preventDefault)event.preventDefault()}).off("mousedown").on("mousedown",function(event){if(!event)event=window.event;if(!window.addEventListener){window.document.attachEvent("onselectstart",function(){return false})}obj.resizing=true;obj.last.tmp={x:event.screenX,y:event.screenY,gx:event.screenX,gy:event.screenY,col:parseInt($(this).attr("name"))};if(event.stopPropagation)event.stopPropagation();else event.cancelBubble=true;if(event.preventDefault)event.preventDefault();for(var c in obj.columns){if(typeof obj.columns[c].sizeOriginal=="undefined")obj.columns[c].sizeOriginal=obj.columns[c].size;obj.columns[c].size=obj.columns[c].sizeCalculated}var eventData={phase:"before",type:"columnResize",target:obj.name,column:obj.last.tmp.col,field:obj.columns[obj.last.tmp.col].field};eventData=obj.trigger($.extend(eventData,{resizeBy:0,originalEvent:event}));var mouseMove=function(event){if(obj.resizing!=true)return;if(!event)event=window.event;eventData=obj.trigger($.extend(eventData,{resizeBy:event.screenX-obj.last.tmp.gx,originalEvent:event}));if(eventData.isCancelled===true){eventData.isCancelled=false;return}obj.last.tmp.x=event.screenX-obj.last.tmp.x;obj.last.tmp.y=event.screenY-obj.last.tmp.y;obj.columns[obj.last.tmp.col].size=parseInt(obj.columns[obj.last.tmp.col].size)+obj.last.tmp.x+"px";obj.resizeRecords();obj.last.tmp.x=event.screenX;obj.last.tmp.y=event.screenY};var mouseUp=function(event){delete obj.resizing;$(document).off("mousemove","body");$(document).off("mouseup","body");obj.resizeRecords();obj.trigger($.extend(eventData,{phase:"after",originalEvent:event}))};$(document).on("mousemove","body",mouseMove);$(document).on("mouseup","body",mouseUp)}).each(function(index,el){var td=$(el).parent();$(el).css({height:"25px","margin-left":td.width()-3+"px"})})},resizeBoxes:function(){var main=$(this.box).find("> div");var header=$("#grid_"+this.name+"_header");var toolbar=$("#grid_"+this.name+"_toolbar");var summary=$("#grid_"+this.name+"_summary");var footer=$("#grid_"+this.name+"_footer");var body=$("#grid_"+this.name+"_body");var columns=$("#grid_"+this.name+"_columns");var records=$("#grid_"+this.name+"_records");if(this.show.header){header.css({top:"0px",left:"0px",right:"0px"})}if(this.show.toolbar){toolbar.css({top:0+(this.show.header?w2utils.getSize(header,"height"):0)+"px",left:"0px",right:"0px"})}if(this.show.footer){footer.css({bottom:"0px",left:"0px",right:"0px"})}if(this.summary.length>0){summary.css({bottom:0+(this.show.footer?w2utils.getSize(footer,"height"):0)+"px",left:"0px",right:"0px"})}body.css({top:0+(this.show.header?w2utils.getSize(header,"height"):0)+(this.show.toolbar?w2utils.getSize(toolbar,"height"):0)+"px",bottom:0+(this.show.footer?w2utils.getSize(footer,"height"):0)+(this.summary.length>0?w2utils.getSize(summary,"height"):0)+"px",left:"0px",right:"0px"})},resizeRecords:function(){var obj=this;$(this.box).find(".w2ui-empty-record").remove();var box=$(this.box);var grid=$(this.box).find("> div");var header=$("#grid_"+this.name+"_header");var toolbar=$("#grid_"+this.name+"_toolbar");var summary=$("#grid_"+this.name+"_summary");var footer=$("#grid_"+this.name+"_footer");var body=$("#grid_"+this.name+"_body");var columns=$("#grid_"+this.name+"_columns");var records=$("#grid_"+this.name+"_records");if(!this.fixedBody){setTimeout(function(){var calculatedHeight=w2utils.getSize(columns,"height")+w2utils.getSize($("#grid_"+obj.name+"_records table"),"height");obj.height=calculatedHeight+w2utils.getSize(grid,"+height")+(obj.show.header?w2utils.getSize(header,"height"):0)+(obj.show.toolbar?w2utils.getSize(toolbar,"height"):0)+(summary.css("display")!="none"?w2utils.getSize(summary,"height"):0)+(obj.show.footer?w2utils.getSize(footer,"height"):0);grid.css("height",obj.height);body.css("height",calculatedHeight);box.css("height",w2utils.getSize(grid,"height")+w2utils.getSize(box,"+height"))},1)}else{var calculatedHeight=grid.height()-(this.show.header?w2utils.getSize(header,"height"):0)-(this.show.toolbar?w2utils.getSize(toolbar,"height"):0)-(summary.css("display")!="none"?w2utils.getSize(summary,"height"):0)-(this.show.footer?w2utils.getSize(footer,"height"):0);body.css("height",calculatedHeight)}var bodyOverflowX=false;var bodyOverflowY=false;if(body.width()<$(records).find(">table").width())bodyOverflowX=true;if(body.height()-columns.height()<$(records).find(">table").height()+(bodyOverflowX?w2utils.scrollBarSize():0))bodyOverflowY=true;if(!this.fixedBody){bodyOverflowY=false;bodyOverflowX=false}if(bodyOverflowX||bodyOverflowY){columns.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show();records.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(columns,"height")+"px","-webkit-overflow-scrolling":"touch","overflow-x":bodyOverflowX?"auto":"hidden","overflow-y":bodyOverflowY?"auto":"hidden"})}else{columns.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").hide();records.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(columns,"height")+"px",overflow:"hidden"});if(records.length>0){this.last.scrollTop=0;this.last.scrollLeft=0}}if(this.show.emptyRecords&&!bodyOverflowY){var max=Math.floor(records.height()/this.recordHeight)+1;if(this.fixedBody){for(var di=this.buffered;di<=max;di++){var html="";html+='
")}}}if(this.buffered>=this.total-this.offset)$("#grid_"+this.name+"_rec_more").hide();return;function markSearch(){if(obj.markSearchResults===false)return;clearTimeout(obj.last.marker_timer);obj.last.marker_timer=setTimeout(function(){var str=[];for(var s in obj.searchData){var tmp=obj.searchData[s];if($.inArray(tmp.value,str)==-1)str.push(tmp.value)}if(str.length>0)$(obj.box).find(".w2ui-grid-data > div").w2marker(str)},50)}},getRecordHTML:function(ind,lineNum,summary){var rec_html="";if(ind==-1){rec_html+='
';if(this.show.lineNumbers)rec_html+='
';if(this.show.selectColumn)rec_html+='
';if(this.show.expandColumn)rec_html+='
';for(var i in this.columns){if(this.columns[i].hidden)continue;rec_html+='
",buttons:''+'',onOpen:function(event){event.onComplete=function(){$("#w2ui-popup .w2ui-popup-button").on("click",function(event){w2popup.close();if(typeof callBack=="function")callBack(event.target.id)})}},onKeydown:function(event){switch(event.originalEvent.keyCode){case 13:if(typeof callBack=="function")callBack("Yes");w2popup.close();break;case 27:if(typeof callBack=="function")callBack("No");w2popup.close();break}}})}};(function(){var w2tabs=function(options){this.box=null;this.name=null;this.active=null;this.tabs=[];this.right="";this.style="";this.onClick=null;this.onClose=null;this.onRender=null;this.onRefresh=null;this.onResize=null;this.onDestroy=null;$.extend(true,this,w2obj.tabs,options)};$.fn.w2tabs=function(method){if(typeof method==="object"||!method){if(!method||typeof method.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2tabs().');return}if(typeof w2ui[method.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+method.name+").");return}if(!w2utils.isAlphaNumeric(method.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}var tabs=method.tabs;var object=new w2tabs(method);$.extend(object,{tabs:[],handlers:[]});for(var i in tabs){object.tabs[i]=$.extend({},w2tabs.prototype.tab,tabs[i])}if($(this).length!=0){object.render($(this)[0])}w2ui[object.name]=object;return object}else if(w2ui[$(this).attr("name")]){var obj=w2ui[$(this).attr("name")];obj[method].apply(obj,Array.prototype.slice.call(arguments,1));return this}else{console.log("ERROR: Method "+method+" does not exist on jQuery.w2tabs")}};w2tabs.prototype={tab:{id:null,text:"",hidden:false,disabled:false,closable:false,hint:"",onClick:null,onRefresh:null,onClose:null},add:function(tab){return this.insert(null,tab)},insert:function(id,tab){if(!$.isArray(tab))tab=[tab];for(var r in tab){if(String(tab[r].id)=="undefined"){console.log('ERROR: The parameter "id" is required but not supplied. (obj: '+this.name+")");return}var unique=true;for(var i in this.tabs){if(this.tabs[i].id==tab[r].id){unique=false;break}}if(!unique){console.log('ERROR: The parameter "id='+tab[r].id+'" is not unique within the current tabs. (obj: '+this.name+")");return}if(!w2utils.isAlphaNumeric(tab[r].id)){console.log('ERROR: The parameter "id='+tab[r].id+'" must be alpha-numeric + "-_". (obj: '+this.name+")");return}var tab=$.extend({},tab,tab[r]);if(id==null||typeof id=="undefined"){this.tabs.push(tab)}else{var middle=this.get(id,true);this.tabs=this.tabs.slice(0,middle).concat([tab],this.tabs.slice(middle))}this.refresh(tab[r].id)}},remove:function(id){var removed=0;for(var a=0;a
";if(this.get(id,true)!=this.tabs.length&&$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(id,true))].id)).length>0){$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(id,true))].id)).before(html)}else{$(this.box).find("#tabs_"+this.name+"_right").before(html)}var obj=this;setTimeout(function(){var width=$("#_tmp_simple_tab").width();$("#_tmp_tabs").remove();$("#tabs_"+obj.name+"_tab_"+w2utils.escapeId(tab.id)+" > div").css("width",width+"px")},1);setTimeout(function(){obj.insert(id,tab)},200)}};$.extend(w2tabs.prototype,w2utils.event);w2obj.tabs=w2tabs})();(function(){var w2toolbar=function(options){this.box=null,this.name=null,this.items=[],this.right="",this.onClick=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null;$.extend(true,this,w2obj.toolbar,options)};$.fn.w2toolbar=function(method){if(typeof method==="object"||!method){if(!method||typeof method.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2toolbar().');return}if(typeof w2ui[method.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+method.name+").");return}if(!w2utils.isAlphaNumeric(method.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}var items=method.items;var object=new w2toolbar(method);$.extend(object,{items:[],handlers:[]});for(var i in items){object.items[i]=$.extend({},w2toolbar.prototype.item,items[i])}if($(this).length!=0){object.render($(this)[0])}w2ui[object.name]=object;return object}else if(w2ui[$(this).attr("name")]){var obj=w2ui[$(this).attr("name")];obj[method].apply(obj,Array.prototype.slice.call(arguments,1));return this}else{console.log("ERROR: Method "+method+" does not exist on jQuery.w2toolbar")}};w2toolbar.prototype={item:{id:null,type:"button",text:"",html:"",img:null,icon:null,hidden:false,disabled:false,checked:false,arrow:true,hint:"",group:null,items:null,onClick:null},add:function(items){this.insert(null,items)},insert:function(id,items){if(!$.isArray(items))items=[items];for(var o in items){if(typeof items[o].type=="undefined"){console.log('ERROR: The parameter "type" is required but not supplied in w2toolbar.add() method.');return}if($.inArray(String(items[o].type),["button","check","radio","drop","menu","break","html","spacer"])==-1){console.log('ERROR: The parameter "type" should be one of the following [button, check, radio, drop, menu, break, html, spacer] '+"in w2toolbar.add() method.");return}if(typeof items[o].id=="undefined"){console.log('ERROR: The parameter "id" is required but not supplied in w2toolbar.add() method.');return}var unique=true;for(var i=0;i table #tb_"+this.name+"_right").length>0){$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-toolbar").html("")}this.box=box}if(!this.box)return;var html='
");var helper=$(this).next();helper.css({color:$(this).css("color"),"font-family":$(this).css("font-family"),"font-size":$(this).css("font-size"),"padding-top":$(this).css("padding-top"),"padding-bottom":$(this).css("padding-bottom"),"padding-left":"3px","padding-right":$(this).css("padding-right"),"margin-top":parseInt($(this).css("margin-top"))+1+"px","margin-bottom":parseInt($(this).css("margin-bottom"))+1+"px"}).on("click",function(){$(this).prev().focus()});helper.css("margin-left","-"+(helper.width()+parseInt($(this).css("padding-right"))+4)+"px");var pr=helper.width()+parseInt($(this).css("padding-right"))+4;$(this).css("padding-right",pr+"px");helper.find("div").css("background-color","#"+$(obj).val())}break;case"select":case"list":if(this.tagName!="SELECT"){console.log("ERROR: You can only apply $().w2field('list') to a SELECT element");return}var defaults={url:"",items:[],value:null,showNone:true};var obj=this;var settings=$.extend({},defaults,options);$(obj).data("settings",settings);obj.refresh=function(){var settings=$(obj).data("settings");var html="";var items=w2field.cleanItems(settings.items);if(settings.showNone)html='";for(var i in items){if(!settings.showNone&&settings.value==null)settings.value=items[i].id;html+='"}$(obj).html(html);$(obj).val(settings.value);if($(obj).val()!=settings.value)$(obj).change()};if(settings.url!=""){$.ajax({type:"GET",dataType:"text",url:settings.url,complete:function(xhr,status){if(status=="success"){var data=$.parseJSON(xhr.responseText);var settings=$(obj).data("settings");settings.items=w2field.cleanItems(data.items);$(obj).data("settings",settings);obj.refresh()}}})}else{obj.refresh()}break;case"enum":if(this.tagName!="INPUT"){console.log("ERROR: You can only apply $().w2field('enum') to an INPUT element");return}var defaults={url:"",items:[],selected:[],max:0,maxHeight:172,showAll:false,match:"begins with",render:null,maxCache:500,onShow:null,onHide:null,onAdd:null,onRemove:null,onItemOver:null,onItemOut:null,onItemClick:null};var obj=this;var settings=$.extend({},defaults,options);settings.items=w2field.cleanItems(settings.items);settings.selected=w2field.cleanItems(settings.selected);$(this).data("selected",settings.selected);$(this).css({padding:"0px","border-color":"transparent","background-color":"transparent",outline:"none"});this.add=function(item){if($(this).attr("readonly"))return;var selected=$(this).data("selected");var settings=$(this).data("settings");if(typeof settings.onAdd=="function"){var cancel=settings.onAdd(item,settings);if(cancel===false)return}if(!$.isArray(selected))selected=[];if(settings.max!=0&&settings.max<=selected.length){selected.splice(selected.length-1,1)}selected.push(item);$(this).data("last_del",null);$(this).trigger("change")};this.remove=function(index){var settings=$(this).data("settings");if(typeof settings.onRemove=="function"){var cancel=settings.onRemove(index,settings);if(cancel===false)return}if($(this).attr("readonly"))return;$(this).data("selected").splice(index,1);$(this).parent().find("[title=Remove][index="+index+"]").remove();this.refresh();w2field.list_render.call(this);$(this).trigger("change")};this.show=function(){if($(this).attr("readonly"))return;var settings=$(this).data("settings");if($("#w2ui-global-items").length==0){$("body").append('')}else{return}var div=$("#w2ui-global-items");div.css({display:"block",left:$(obj).offset().left+"px",top:$(obj).offset().top+obj.offsetHeight+3+"px"}).width(w2utils.getSize(obj,"width")).data("position",$(obj).offset().left+"x"+($(obj).offset().top+obj.offsetHeight));w2field.list_render.call(obj);var monitor=function(){var div=$("#w2ui-global-items");if($(obj).length==0||$(obj).offset().left==0&&$(obj).offset().top==0){clearInterval($(obj).data("mtimer"));hide();return}if(div.data("position")!=$(obj).offset().left+"x"+($(obj).offset().top+obj.offsetHeight)){div.css({"-webkit-transition":".2s",left:$(obj).offset().left+"px",top:$(obj).offset().top+obj.offsetHeight+3+"px"}).data("position",$(obj).offset().left+"x"+($(obj).offset().top+obj.offsetHeight));setTimeout(function(){w2field.list_render.call(obj,$(obj).data("last_search"))},200)}if(div.length>0)$(obj).data("mtimer",setTimeout(monitor,100))};$(obj).data("mtimer",setTimeout(monitor,100));if(typeof settings.onShow=="function")settings.onShow.call(this,settings)};this.hide=function(){var settings=$(this).data("settings");clearTimeout($(obj).data("mtimer"));$("#w2ui-global-items").remove();if(typeof settings.onHide=="function")settings.onHide.call(this,settings)};this.refresh=function(){var obj=this;$($(this).data("div")).remove();var margin="margin-top: "+$(this).css("margin-top")+"; "+"margin-bottom: "+$(this).css("margin-bottom")+"; "+"margin-left: "+$(this).css("margin-left")+"; "+"margin-right: "+$(this).css("margin-right")+"; "+"width: "+(w2utils.getSize(this,"width")-parseInt($(this).css("margin-left"))-parseInt($(this).css("margin-right")))+"px; ";var html='
'+'
';var selected=$(this).data("selected");for(var s in selected){html+='
'+'
'+selected[s].text+"
"}html+='
'+' '+"
"+"
"+"
";$(this).before(html);var div=$(this).prev()[0];$(this).data("div",div);$(div).find("li").data("mouse","out").on("click",function(event){if($(event.target).hasClass("nomouse"))return;if(event.target.title==w2utils.lang("Remove")){obj.remove($(event.target).attr("index"));return}event.stopPropagation();if(typeof settings.onItemClick=="function")settings.onItemClick.call(this,settings)}).on("mouseover",function(event){var tmp=event.target;if(tmp.tagName!="LI")tmp=tmp.parentNode;if($(tmp).hasClass("nomouse"))return;if($(tmp).data("mouse")=="out"){if(typeof settings.onItemOver=="function")settings.onItemOver.call(this,settings)}$(tmp).data("mouse","over")}).on("mouseout",function(event){var tmp=event.target;if(tmp.tagName!="LI")tmp=tmp.parentNode;if($(tmp).hasClass("nomouse"))return;$(tmp).data("mouse","leaving");setTimeout(function(){if($(tmp).data("mouse")=="leaving"){$(tmp).data("mouse","out");if(typeof settings.onItemOut=="function")settings.onItemOut.call(this,settings)}},0)});$(div).on("click",function(event){$(this).find("input").focus()}).find("input").on("focus",function(event){$(div).css({outline:"auto 5px -webkit-focus-ring-color","outline-offset":"-2px"});obj.show();if(event.stopPropagation)event.stopPropagation();else event.cancelBubble=true}).on("blur",function(event){$(div).css("outline","none");obj.hide();if(event.stopPropagation)event.stopPropagation();else event.cancelBubble=true});obj.resize()};this.resize=function(){var settings=$(this).data("settings");var div=$(this).prev();var cntHeight=$(div).find(">div").height();if(cntHeight<23)cntHeight=23;if(cntHeight>settings.maxHeight)cntHeight=settings.maxHeight;$(div).height(cntHeight+(cntHeight%23==0?0:23-cntHeight%23));if(div.length>0)div[0].scrollTop=1e3;$(this).height(cntHeight)};$(this).data("settings",settings).attr("tabindex",-1);obj.refresh();break;case"upload":if(this.tagName!="INPUT"){console.log("ERROR: You can only apply $().w2field('upload') to an INPUT element");return}var defaults={url:"",base64:true,hint:w2utils.lang("Attach files by dragging and dropping or Click to Select"),max:0,maxSize:0,maxFileSize:0,onAdd:null,onRemove:null,onItemClick:null,onItemDblClick:null,onItemOver:null,onItemOut:null,onProgress:null,onComplete:null};var obj=this;var settings=$.extend({},defaults,options);if(settings.base64===true){if(settings.maxSize==0)settings.maxSize=20*1024*1024;if(settings.maxFileSize==0)settings.maxFileSize=20*1024*1024}var selected=settings.selected;delete settings.selected;if(!$.isArray(selected))selected=[];$(this).data("selected",selected).data("settings",settings).attr("tabindex",-1);w2field.upload_init.call(this);this.refresh=function(){var obj=this;var div=$(this).data("div");var settings=$(this).data("settings");var selected=$(this).data("selected");$(div).find("li").remove();$(div).find("> span:first-child").css("line-height",$(div).height()-w2utils.getSize(div,"+height")-8+"px");for(var s in selected){var file=selected[s];var cnt=$(div).find(".file-list li").length;$(div).find("> span:first-child").remove();$(div).find(".file-list").append('
";return html}});w2obj.field=w2field})(jQuery);(function(){var w2form=function(options){this.name=null;this.header="";this.box=null;this.url="";this.formURL="";this.formHTML="";this.page=0;this.recid=0;this.fields=[];this.actions={};this.record={};this.original={};this.postData={};this.toolbar={};this.tabs={};this.style="";this.focus=0;this.msgNotJSON=w2utils.lang("Return data is not in JSON format.");this.msgRefresh=w2utils.lang("Refreshing...");this.msgSaving=w2utils.lang("Saving...");this.onRequest=null;this.onLoad=null;this.onValidate=null;this.onSubmit=null;this.onSave=null;this.onChange=null;this.onRender=null;this.onRefresh=null;this.onResize=null;this.onDestroy=null;this.onAction=null;this.onToolbar=null;this.onError=null;this.isGenerated=false;this.last={xhr:null};$.extend(true,this,w2obj.form,options)};$.fn.w2form=function(method){if(typeof method==="object"||!method){var obj=this;if(!method||typeof method.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2form().');return}if(typeof w2ui[method.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+method.name+").");return}if(!w2utils.isAlphaNumeric(method.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}var record=method.record;var original=method.original;var fields=method.fields;var toolbar=method.toolbar;var tabs=method.tabs;var object=new w2form(method);$.extend(object,{record:{},original:{},fields:[],tabs:{},toolbar:{},handlers:[]});if($.isArray(tabs)){$.extend(true,object.tabs,{tabs:[]});for(var t in tabs){var tmp=tabs[t];if(typeof tmp=="object")object.tabs.tabs.push(tmp);else object.tabs.tabs.push({id:tmp,caption:tmp})}}else{$.extend(true,object.tabs,tabs)}$.extend(true,object.toolbar,toolbar);for(var p in fields)object.fields[p]=$.extend(true,{},fields[p]);for(var p in record){if($.isPlainObject(record[p])){object.record[p]=$.extend(true,{},record[p])}else{object.record[p]=record[p]}}for(var p in original){if($.isPlainObject(original[p])){object.original[p]=$.extend(true,{},original[p])}else{object.original[p]=original[p]}}if(obj.length>0)object.box=obj[0];if(object.formURL!=""){$.get(object.formURL,function(data){object.formHTML=data;object.isGenerated=true;if($(object.box).length!=0||data.length!=0){$(object.box).html(data);object.render(object.box)}})}else if(object.formHTML!=""){}else if($(this).length!=0&&$.trim($(this).html())!=""){object.formHTML=$(this).html()}else{object.formHTML=object.generateHTML()}w2ui[object.name]=object;if(object.formURL==""){if(String(object.formHTML).indexOf("w2ui-page")==-1){object.formHTML='
'+object.formHTML+"
"}$(object.box).html(object.formHTML);object.isGenerated=true;object.render(object.box)}return object}else if(w2ui[$(this).attr("name")]){var obj=w2ui[$(this).attr("name")];obj[method].apply(obj,Array.prototype.slice.call(arguments,1));return this}else{console.log("ERROR: Method "+method+" does not exist on jQuery.w2form")}};w2form.prototype={get:function(field,returnIndex){for(var f in this.fields){if(this.fields[f].name==field){if(returnIndex===true)return f;else return this.fields[f]}}return null},set:function(field,obj){for(var f in this.fields){if(this.fields[f].name==field){$.extend(this.fields[f],obj);this.refresh();return true}}return false},reload:function(callBack){var url=typeof this.url!="object"?this.url:this.url.get;if(url&&this.recid!=0){this.request(callBack)}else{this.refresh();if(typeof callBack=="function")callBack()}},clear:function(){this.recid=0;this.record={};for(var f in this.fields){var field=this.fields[f]}$().w2tag();this.refresh()},error:function(msg){var obj=this;var eventData=this.trigger({target:this.name,type:"error",message:msg,xhr:this.last.xhr});if(eventData.isCancelled===true){if(typeof callBack=="function")callBack();return false}setTimeout(function(){w2alert(msg,"Error")},1);this.trigger($.extend(eventData,{phase:"after"}))},validate:function(showErrors){if(typeof showErrors=="undefined")showErrors=true;var errors=[];for(var f in this.fields){var field=this.fields[f];if(this.record[field.name]==null)this.record[field.name]="";switch(field.type){case"int":if(this.record[field.name]&&!w2utils.isInt(this.record[field.name])){errors.push({field:field,error:w2utils.lang("Not an integer")})}break;case"float":if(this.record[field.name]&&!w2utils.isFloat(this.record[field.name])){errors.push({field:field,error:w2utils.lang("Not a float")})}break;case"money":if(this.record[field.name]&&!w2utils.isMoney(this.record[field.name])){errors.push({field:field,error:w2utils.lang("Not in money format")})}break;case"color":case"hex":if(this.record[field.name]&&!w2utils.isHex(this.record[field.name])){errors.push({field:field,error:w2utils.lang("Not a hex number")})}break;case"email":if(this.record[field.name]&&!w2utils.isEmail(this.record[field.name])){errors.push({field:field,error:w2utils.lang("Not a valid email")})}break;case"checkbox":if(this.record[field.name]==true)this.record[field.name]=1;else this.record[field.name]=0;break;case"date":if(this.record[field.name]&&!w2utils.isDate(this.record[field.name],field.options.format)){errors.push({field:field,error:w2utils.lang("Not a valid date")+": "+field.options.format})}else{}break;case"select":case"list":break;case"enum":break}var val=this.record[field.name];if(field.required&&(val===""||$.isArray(val)&&val.length==0)){errors.push({field:field,error:w2utils.lang("Required field")})}if(field.equalto&&this.record[field.name]!=this.record[field.equalto]){errors.push({field:field,error:w2utils.lang("Field should be equal to ")+field.equalto})}}var eventData=this.trigger({phase:"before",target:this.name,type:"validate",errors:errors});if(eventData.isCancelled===true)return errors;if(showErrors)for(var e in eventData.errors){var err=eventData.errors[e];$(err.field.el).w2tag(err.error,{"class":"w2ui-error"})}this.trigger($.extend(eventData,{phase:"after"}));return errors},request:function(postData,callBack){var obj=this;if(typeof postData=="function"){callBack=postData;postData=null}if(typeof postData=="undefined"||postData==null)postData={};if(!this.url||typeof this.url=="object"&&!this.url.get)return;if(this.recid==null||typeof this.recid=="undefined")this.recid=0;var params={};params["cmd"]="get-record";params["name"]=this.name;params["recid"]=this.recid;$.extend(params,this.postData);$.extend(params,postData);var eventData=this.trigger({phase:"before",type:"request",target:this.name,url:this.url,postData:params});if(eventData.isCancelled===true){if(typeof callBack=="function")callBack({status:"error",message:"Request aborted."});return false}this.record={};this.original={};this.lock(this.msgRefresh);var url=eventData.url;if(typeof eventData.url=="object"&&eventData.url.get)url=eventData.url.get;if(this.last.xhr)try{this.last.xhr.abort()}catch(e){}this.last.xhr=$.ajax({type:"GET",url:url,data:String($.param(eventData.postData,false)).replace(/%5B/g,"[").replace(/%5D/g,"]"),dataType:"text",complete:function(xhr,status){obj.unlock();var eventData=obj.trigger({phase:"before",target:obj.name,type:"load",xhr:xhr,status:status});if(eventData.isCancelled===true){if(typeof callBack=="function")callBack({status:"error",message:"Request aborted."});return false}var responseText=obj.last.xhr.responseText;if(status!="error"){if(typeof responseText!="undefined"&&responseText!=""){var data;if(typeof responseText=="object"){data=responseText}else{try{eval("data = "+responseText)}catch(e){}}if(typeof data=="undefined"){data={status:"error",message:obj.msgNotJSON,responseText:responseText}}if(data["status"]=="error"){obj.error(data["message"])}else{obj.record=$.extend({},data.record);obj.original=$.extend({},data.record)}}}else{obj.error("AJAX Error "+xhr.status+": "+xhr.statusText)}obj.trigger($.extend(eventData,{phase:"after"}));obj.refresh();if(typeof callBack=="function")callBack(data)}});this.trigger($.extend(eventData,{phase:"after"}))},submit:function(postData,callBack){return this.save(postData,callBack)},save:function(postData,callBack){var obj=this;if(typeof postData=="function"){callBack=postData;postData=null}var errors=obj.validate(true);if(errors.length!==0){obj.goto(errors[0].field.page);return}if(typeof postData=="undefined"||postData==null)postData={};if(!obj.url||typeof obj.url=="object"&&!obj.url.save){console.log("ERROR: Form cannot be saved because no url is defined.");return}obj.lock(obj.msgSaving+' ');setTimeout(function(){var params={};params["cmd"]="save-record";params["name"]=obj.name;params["recid"]=obj.recid;$.extend(params,obj.postData);$.extend(params,postData);params.record=$.extend(true,{},obj.record);for(var f in obj.fields){var field=obj.fields[f];switch(String(field.type).toLowerCase()){case"date":var dt=params.record[field.name];var tmp=field.options.format.toLowerCase().replace("-","/").replace(".","/");if(["dd/mm/yyyy","d/m/yyyy","dd/mm/yy","d/m/yy"].indexOf(tmp)!=-1){var tmp=dt.replace(/-/g,"/").replace(/\./g,"/").split("/");var dt=new Date(tmp[2],tmp[1]-1,tmp[0])}params.record[field.name]=w2utils.formatDate(dt,"yyyy-mm-dd");break}}var eventData=obj.trigger({phase:"before",type:"submit",target:obj.name,url:obj.url,postData:params});if(eventData.isCancelled===true){if(typeof callBack=="function")callBack({status:"error",message:"Saving aborted."});return false}var url=eventData.url;if(typeof eventData.url=="object"&&eventData.url.save)url=eventData.url.save;if(obj.last.xhr)try{obj.last.xhr.abort()}catch(e){}obj.last.xhr=$.ajax({type:w2utils.settings.RESTfull?obj.recid==0?"POST":"PUT":"POST",url:url,data:String($.param(eventData.postData,false)).replace(/%5B/g,"[").replace(/%5D/g,"]"),dataType:"text",xhr:function(){var xhr=new window.XMLHttpRequest;xhr.upload.addEventListener("progress",function(evt){if(evt.lengthComputable){var percent=Math.round(evt.loaded/evt.total*100);$("#"+obj.name+"_progress").text(""+percent+"%")}},false);return xhr},complete:function(xhr,status){obj.unlock();var eventData=obj.trigger({phase:"before",target:obj.name,type:"save",xhr:xhr,status:status});if(eventData.isCancelled===true){if(typeof callBack=="function")callBack({status:"error",message:"Saving aborted."});return false}var responseText=xhr.responseText;if(status!="error"){if(typeof responseText!="undefined"&&responseText!=""){var data;if(typeof responseText=="object"){data=responseText}else{try{eval("data = "+responseText)}catch(e){}}if(typeof data=="undefined"){data={status:"error",message:obj.msgNotJSON,responseText:responseText}}if(data["status"]=="error"){obj.error(data["message"])}else{obj.original=$.extend({},obj.record)}}}else{obj.error("AJAX Error "+xhr.status+": "+xhr.statusText)}obj.trigger($.extend(eventData,{phase:"after"}));obj.refresh();if(typeof callBack=="function")callBack(data)}});obj.trigger($.extend(eventData,{phase:"after"}))},50)},lock:function(msg,showSpinner){var box=$(this.box).find("> div:first-child");w2utils.lock(box,msg,showSpinner)},unlock:function(){var obj=this;setTimeout(function(){w2utils.unlock(obj.box)},25)},"goto":function(page){if(typeof page!="undefined")this.page=page;if($(this.box).data("auto-size")===true)$(this.box).height(0);this.refresh()},generateHTML:function(){var pages=[];for(var f in this.fields){var html="";var field=this.fields[f];if(typeof field.html=="undefined")field.html={};field.html=$.extend(true,{caption:"",span:6,attr:"",text:"",page:0},field.html);if(field.html.caption=="")field.html.caption=field.name;var input='";if(field.type=="list")input='";if(field.type=="checkbox")input='";if(field.type=="textarea")input='";html+='\n
';for(var a in this.actions){buttons+='\n '}buttons+="\n
"}return pages.join("")+buttons},action:function(action,event){var eventData=this.trigger({phase:"before",target:action,type:"action",originalEvent:event});if(eventData.isCancelled===true)return false;if(typeof this.actions[action]=="function"){this.actions[action].call(this,event)}this.trigger($.extend(eventData,{phase:"after"}))},resize:function(){var obj=this;var eventData=this.trigger({phase:"before",target:this.name,type:"resize"});if(eventData.isCancelled===true)return false;var main=$(this.box).find("> div");var header=$(this.box).find("> div .w2ui-form-header");var toolbar=$(this.box).find("> div .w2ui-form-toolbar");var tabs=$(this.box).find("> div .w2ui-form-tabs");var page=$(this.box).find("> div .w2ui-page");var cpage=$(this.box).find("> div .w2ui-page.page-"+this.page);var dpage=$(this.box).find("> div .w2ui-page.page-"+this.page+" > div");var buttons=$(this.box).find("> div .w2ui-buttons");resizeElements();if(parseInt($(this.box).height())==0||$(this.box).data("auto-size")===true){$(this.box).height((header.length>0?w2utils.getSize(header,"height"):0)+(this.tabs.tabs.length>0?w2utils.getSize(tabs,"height"):0)+(this.toolbar.items.length>0?w2utils.getSize(toolbar,"height"):0)+(page.length>0?w2utils.getSize(dpage,"height")+w2utils.getSize(cpage,"+height")+12:0)+(buttons.length>0?w2utils.getSize(buttons,"height"):0));$(this.box).data("auto-size",true)}resizeElements();obj.trigger($.extend(eventData,{phase:"after"}));function resizeElements(){main.width($(obj.box).width()).height($(obj.box).height());toolbar.css("top",obj.header!=""?w2utils.getSize(header,"height"):0);tabs.css("top",(obj.header!=""?w2utils.getSize(header,"height"):0)+(obj.toolbar.items.length>0?w2utils.getSize(toolbar,"height"):0));page.css("top",(obj.header!=""?w2utils.getSize(header,"height"):0)+(obj.toolbar.items.length>0?w2utils.getSize(toolbar,"height")+5:0)+(obj.tabs.tabs.length>0?w2utils.getSize(tabs,"height")+5:0));page.css("bottom",buttons.length>0?w2utils.getSize(buttons,"height"):0)}},refresh:function(){var obj=this;if(!this.box)return;if(!this.isGenerated||typeof $(this.box).html()=="undefined")return;$(this.box).find("input, textarea, select").each(function(index,el){var name=typeof $(el).attr("name")!="undefined"?$(el).attr("name"):$(el).attr("id");var field=obj.get(name);if(field){var div=$(el).parents(".w2ui-page");if(div.length>0){for(var i=0;i<100;i++){if(div.hasClass("page-"+i)){field.page=i;break}}}}});var eventData=this.trigger({phase:"before",target:this.name,type:"refresh",page:this.page});if(eventData.isCancelled===true)return false;$(this.box).find(".w2ui-page").hide();$(this.box).find(".w2ui-page.page-"+this.page).show();$(this.box).find(".w2ui-form-header").html(this.header);if(typeof this.tabs=="object"&&this.tabs.tabs.length>0){$("#form_"+this.name+"_tabs").show();this.tabs.active=this.tabs.tabs[this.page].id;this.tabs.refresh()}else{$("#form_"+this.name+"_tabs").hide()}if(typeof this.toolbar=="object"&&this.toolbar.items.length>0){$("#form_"+this.name+"_toolbar").show();this.toolbar.refresh()}else{$("#form_"+this.name+"_toolbar").hide()}for(var f in this.fields){var field=this.fields[f];field.el=$(this.box).find('[name="'+String(field.name).replace(/\\/g,"\\\\")+'"]')[0];if(typeof field.el=="undefined"){console.log('ERROR: Cannot associate field "'+field.name+'" with html control. Make sure html control exists with the same name.')}if(field.el)field.el.id=field.name;$(field.el).w2field("clear").off("change").on("change",function(){var value_new=this.value;var value_previous=obj.record[this.name]?obj.record[this.name]:"";var field=obj.get(this.name);if((field.type=="enum"||field.type=="upload")&&$(this).data("selected")){var new_arr=$(this).data("selected");var cur_arr=obj.record[this.name];var value_new=[];var value_previous=[];if($.isArray(new_arr))for(var i in new_arr)value_new[i]=$.extend(true,{},new_arr[i]);if($.isArray(cur_arr))for(var i in cur_arr)value_previous[i]=$.extend(true,{},cur_arr[i])}var eventData=obj.trigger({phase:"before",target:this.name,type:"change",value_new:value_new,value_previous:value_previous});
+if(eventData.isCancelled===true){$(this).val(obj.record[this.name]);return false}var val=this.value;if(this.type=="checkbox")val=this.checked?true:false;if(this.type=="radio")val=this.checked?true:false;if(field.type=="enum")val=value_new;if(field.type=="upload")val=value_new;obj.record[this.name]=val;obj.trigger($.extend(eventData,{phase:"after"}))});if(field.required){$(field.el).parent().addClass("w2ui-required")}else{$(field.el).parent().removeClass("w2ui-required")}}$(this.box).find("button, input[type=button]").each(function(index,el){$(el).off("click").on("click",function(event){var action=this.value;if(this.name)action=this.name;if(this.id)action=this.id;obj.action(action,event)})});for(var f in this.fields){var field=this.fields[f];var value=typeof this.record[field.name]!="undefined"?this.record[field.name]:"";if(!field.el)continue;switch(String(field.type).toLowerCase()){case"email":case"text":case"textarea":field.el.value=value;break;case"date":if(!field.options)field.options={};if(!field.options.format)field.options.format=w2utils.settings.date_format;field.el.value=value;this.record[field.name]=value;$(field.el).w2field($.extend({},field.options,{type:"date"}));break;case"int":field.el.value=value;$(field.el).w2field("int");break;case"float":field.el.value=value;$(field.el).w2field("float");break;case"money":field.el.value=value;$(field.el).w2field("money");break;case"hex":field.el.value=value;$(field.el).w2field("hex");break;case"alphanumeric":field.el.value=value;$(field.el).w2field("alphaNumeric");break;case"checkbox":if(this.record[field.name]==true||this.record[field.name]==1||this.record[field.name]=="t"){$(field.el).prop("checked",true)}else{$(field.el).prop("checked",false)}break;case"password":field.el.value=value;break;case"select":case"list":$(field.el).w2field($.extend({},field.options,{type:"list",value:value}));break;case"enum":if(typeof field.options=="undefined"||typeof field.options.url=="undefined"&&typeof field.options.items=="undefined"){console.log("ERROR: (w2form."+obj.name+") the field "+field.name+" defined as enum but not field.options.url or field.options.items provided.");break}this.record[field.name]=w2obj.field.cleanItems(value);value=this.record[field.name];$(field.el).w2field($.extend({},field.options,{type:"enum",selected:value}));break;case"upload":$(field.el).w2field($.extend({},field.options,{type:"upload",selected:value}));break;case"color":field.el.value=value;$(field.el).w2field("color");break;default:console.log('ERROR: field type "'+field.type+'" is not recognized.');break}}var tmp=$(this.box).find(".w2ui-page");for(var i=0;i *").length>1)$(tmp[i]).wrapInner("")}this.trigger($.extend(eventData,{phase:"after"}));this.resize()},render:function(box){var obj=this;if(typeof box=="object"){if($(this.box).find("#form_"+this.name+"_tabs").length>0){$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html("")}this.box=box}if(!this.isGenerated)return;var eventData=this.trigger({phase:"before",target:this.name,type:"render",box:typeof box!="undefined"?box:this.box});if(eventData.isCancelled===true)return false;var html="
"+(this.header!=""?'
'+this.header+"
":"")+' '+' '+this.formHTML+"
";$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-form").html(html);if($(this.box).length>0)$(this.box)[0].style.cssText+=this.style;if(typeof this.toolbar["render"]=="undefined"){this.toolbar=$().w2toolbar($.extend({},this.toolbar,{name:this.name+"_toolbar",owner:this}));this.toolbar.on("click",function(event){var eventData=obj.trigger({phase:"before",type:"toolbar",target:event.target,originalEvent:event});if(eventData.isCancelled===true)return false;obj.trigger($.extend(eventData,{phase:"after"}))})}if(typeof this.toolbar=="object"&&typeof this.toolbar.render=="function"){this.toolbar.render($("#form_"+this.name+"_toolbar")[0])}if(typeof this.tabs["render"]=="undefined"){this.tabs=$().w2tabs($.extend({},this.tabs,{name:this.name+"_tabs",owner:this}));this.tabs.on("click",function(event){obj.goto(this.get(event.target,true))})}if(typeof this.tabs=="object"&&typeof this.tabs.render=="function"){this.tabs.render($("#form_"+this.name+"_tabs")[0])}this.trigger($.extend(eventData,{phase:"after"}));this.resize();var url=typeof this.url!="object"?this.url:this.url.get;if(url&&this.recid!=0){this.request()}else{this.refresh()}if($(".w2ui-layout").length==0){this.tmp_resize=function(event){w2ui[obj.name].resize()};$(window).off("resize","body").on("resize","body",this.tmp_resize)}setTimeout(function(){obj.resize();obj.refresh()},150);function focusEl(){var inputs=$(obj.box).find("input, select, textarea");if(inputs.length>obj.focus)inputs[obj.focus].focus()}if(this.focus>=0)setTimeout(focusEl,500)},destroy:function(){var eventData=this.trigger({phase:"before",target:this.name,type:"destroy"});if(eventData.isCancelled===true)return false;if(typeof this.toolbar=="object"&&this.toolbar.destroy)this.toolbar.destroy();if(typeof this.tabs=="object"&&this.tabs.destroy)this.tabs.destroy();if($(this.box).find("#form_"+this.name+"_tabs").length>0){$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html("")}delete w2ui[this.name];this.trigger($.extend(eventData,{phase:"after"}));$(window).off("resize","body")}};$.extend(w2form.prototype,w2utils.event);w2obj.form=w2form})();
\ No newline at end of file
diff --git a/w2ui.jquery.json b/w2ui.jquery.json
index 7d951fbe6..45ec4cfcd 100644
--- a/w2ui.jquery.json
+++ b/w2ui.jquery.json
@@ -1,6 +1,6 @@
{
"name": "w2ui",
- "version": "1.3.0",
+ "version": "1.3.1",
"title": "W2UI: New JavaScript UI Library",
"description": "Complete set of JavaScript UI widget for development of data-driven web applications. Includes layout, grid, toolbar, sidebar, tabs, forms, fields, popup, overlay",
"keywords": [
@@ -44,7 +44,7 @@
"bugs" : "https://github.com/vitmalina/w2ui/issues",
"homepage" : "http://w2ui.com/web",
"docs" : "http://w2ui.com/web/docs",
- "download" : "http://w2ui.com/web/downloads/w2ui-1.3.zip",
+ "download" : "http://w2ui.com/web/downloads/w2ui-1.3.1.zip",
"dependencies": {
"jquery": ">=1.9"
}