Load '+ obj.limit + ' More...
');
+ }
+ }
+ }
+ // check for grid end
+ if (this.buffered >= this.total - this.offset) $('#grid_'+ this.name +'_rec_more').hide();
+ return;
+
+ function markSearch() {
+ // mark search
+ if(obj.markSearchResults === false) return;
+ clearTimeout(obj.last.marker_timer);
+ obj.last.marker_timer = setTimeout(function () {
+ // mark all search strings
+ 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 = '';
+ // first record needs for resize purposes
+ if (ind == -1) {
+ rec_html += '';
+ }
+ if (typeof col.render == 'object') data = '
' + col.render[data] + '
';
+ if (typeof col.render == 'string') {
+ var tmp = col.render.toLowerCase().split(':');
+ var prefix = '';
+ var suffix = '';
+ if ($.inArray(tmp[0], ['number', 'int', 'float', 'money', 'percent']) != -1) {
+ if (typeof tmp[1] == 'undefined' || !w2utils.isInt(tmp[1])) tmp[1] = 0;
+ if (tmp[1] > 20) tmp[1] = 20;
+ if (tmp[1] < 0) tmp[1] = 0;
+ if (tmp[0] == 'money') { tmp[1] = 2; prefix = w2utils.settings.currencySymbol; }
+ if (tmp[0] == 'percent') { suffix = '%'; if (tmp[1] !== '0') tmp[1] = 1; }
+ if (tmp[0] == 'int') { tmp[1] = 0; }
+ // format
+ data = '
' + prefix + w2utils.formatNumber(Number(data).toFixed(tmp[1])) + suffix + '
';
+ }
+ if (tmp[0] == 'date') {
+ if (typeof tmp[1] == 'undefined' || tmp[1] == '') tmp[1] = w2utils.settings.date_display;
+ data = '
' + prefix + w2utils.formatDate(data, tmp[1]) + suffix + '
';
+ }
+ if (tmp[0] == 'age') {
+ data = '
' + prefix + w2utils.age(data) + suffix + '
';
+ }
+ }
+ } 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;
+})(jQuery);
+
+/************************************************************************
+ * 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;
+})(jQuery);
+
+/************************************************************************
+ * 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 = '';
+ $('body').append(msg);
+ // allow element to render
+ setTimeout(function () {
+ $('#w2ui-popup .w2ui-box2').hide();
+ $('#w2ui-popup').css({
+ '-webkit-transition': options.speed +'s opacity, '+ options.speed +'s -webkit-transform',
+ '-webkit-transform': 'scale(1)',
+ '-moz-transition': options.speed +'s opacity, '+ options.speed +'s -moz-transform',
+ '-moz-transform': 'scale(1)',
+ '-ms-transition': options.speed +'s opacity, '+ options.speed +'s -ms-transform',
+ '-ms-transform': 'scale(1)',
+ '-o-transition': options.speed +'s opacity, '+ options.speed +'s -o-transform',
+ '-o-transform': 'scale(1)',
+ 'opacity': '1'
+ });
+ }, 1);
+ // clean transform
+ setTimeout(function () {
+ $('#w2ui-popup').css({
+ '-webkit-transform': '',
+ '-moz-transform': '',
+ '-ms-transform': '',
+ '-o-transform': ''
+ });
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ }, options.speed * 1000);
+ } else {
+ // trigger event
+ var eventData = this.trigger({ phase: 'before', type: 'open', target: 'popup', options: options, present: true });
+ if (eventData.isCancelled === true) return;
+ // check if size changed
+ if (typeof old_options == 'undefined' || old_options['width'] != options['width'] || old_options['height'] != options['height']) {
+ $('#w2ui-panel').remove();
+ w2popup.resize(options.width, options.height);
+ }
+ // show new items
+ var body = $('#w2ui-popup .w2ui-box2 > .w2ui-msg-body').html(options.body);
+ if (body.length > 0) body[0].style.cssText = options.style;
+ $('#w2ui-popup .w2ui-msg-buttons').html(options.buttons);
+ $('#w2ui-popup .w2ui-msg-title').html(
+ (options.showClose ? '
Close
' : '')+
+ (options.showMax ? '
Max
' : '') +
+ options.title);
+ // transition
+ var div_old = $('#w2ui-popup .w2ui-box1')[0];
+ var div_new = $('#w2ui-popup .w2ui-box2')[0];
+ w2utils.transition(div_old, div_new, options.transition);
+ div_new.className = 'w2ui-box1';
+ div_old.className = 'w2ui-box2';
+ $(div_new).addClass('w2ui-current-box');
+ // remove max state
+ $('#w2ui-popup').data('prev-size', null);
+ // call event onChange
+ setTimeout(function () {
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ }, 1);
+ }
+ // save new options
+ options._last_w2ui_name = w2utils.keyboard.active();
+ w2utils.keyboard.active(null);
+ $('#w2ui-popup').data('options', options);
+ // keyboard events
+ if (options.keyboard) $(document).on('keydown', this.keydown);
+
+ // initialize move
+ var tmp = { resizing: false };
+ $('#w2ui-popup .w2ui-msg-title')
+ .on('mousedown', function (event) { mvStart(event); })
+ .on('mousemove', function (event) { mvMove(event); })
+ .on('mouseup', function (event) { mvStop(event); });
+ $('#w2ui-popup .w2ui-msg-body')
+ .on('mousemove', function (event) { mvMove(event); })
+ .on('mouseup', function (event) { mvStop(event); });
+ $('#w2ui-lock')
+ .on('mousemove', function (event) { mvMove(event); })
+ .on('mouseup', function (event) { mvStop(event); });
+
+ // handlers
+ function mvStart(event) {
+ if (!event) event = window.event;
+ if (!window.addEventListener) { window.document.attachEvent('onselectstart', function() { return false; } ); }
+ tmp.resizing = true;
+ tmp.tmp_x = event.screenX;
+ tmp.tmp_y = event.screenY;
+ if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;
+ if (event.preventDefault) event.preventDefault(); else return false;
+ }
+
+ function mvMove(evnt) {
+ if (tmp.resizing != true) return;
+ if (!evnt) evnt = window.event;
+ tmp.tmp_div_x = (evnt.screenX - tmp.tmp_x);
+ tmp.tmp_div_y = (evnt.screenY - tmp.tmp_y);
+ $('#w2ui-popup').css({
+ '-webkit-transition': 'none',
+ '-webkit-transform': 'translate3d('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px, 0px)',
+ '-moz-transition': 'none',
+ '-moz-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)',
+ '-ms-transition': 'none',
+ '-ms-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)',
+ '-o-transition': 'none',
+ '-o-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)'
+ });
+ $('#w2ui-panel').css({
+ '-webkit-transition': 'none',
+ '-webkit-transform': 'translate3d('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px, 0px)',
+ '-moz-transition': 'none',
+ '-moz-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)',
+ '-ms-transition': 'none',
+ '-ms-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px',
+ '-o-transition': 'none',
+ '-o-transform': 'translate('+ tmp.tmp_div_x +'px, '+ tmp.tmp_div_y +'px)'
+ });
+ }
+
+ function mvStop(evnt) {
+ if (tmp.resizing != true) return;
+ if (!evnt) evnt = window.event;
+ tmp.tmp_div_x = (evnt.screenX - tmp.tmp_x);
+ tmp.tmp_div_y = (evnt.screenY - tmp.tmp_y);
+ $('#w2ui-popup').css({
+ '-webkit-transition': 'none',
+ '-webkit-transform': 'translate3d(0px, 0px, 0px)',
+ '-moz-transition': 'none',
+ '-moz-transform': 'translate(0px, 0px)',
+ '-ms-transition': 'none',
+ '-ms-transform': 'translate(0px, 0px)',
+ '-o-transition': 'none',
+ '-o-transform': 'translate(0px, 0px)',
+ 'left': (parseInt($('#w2ui-popup').css('left')) + parseInt(tmp.tmp_div_x)) + 'px',
+ 'top': (parseInt($('#w2ui-popup').css('top')) + parseInt(tmp.tmp_div_y)) + 'px'
+ });
+ $('#w2ui-panel').css({
+ '-webkit-transition': 'none',
+ '-webkit-transform': 'translate3d(0px, 0px, 0px)',
+ '-moz-transition': 'none',
+ '-moz-transform': 'translate(0px, 0px)',
+ '-ms-transition': 'none',
+ '-ms-transform': 'translate(0px, 0px)',
+ '-o-transition': 'none',
+ '-o-transform': 'translate(0px, 0px)',
+ 'left': (parseInt($('#w2ui-panel').css('left')) + parseInt(tmp.tmp_div_x)) + 'px',
+ 'top': (parseInt($('#w2ui-panel').css('top')) + parseInt(tmp.tmp_div_y)) + 'px'
+ });
+ tmp.resizing = false;
+ }
+ return this;
+ },
+
+ keydown: function (event) {
+ var options = $('#w2ui-popup').data('options');
+ if (!options.keyboard) return;
+ // trigger event
+ var eventData = w2popup.trigger({ phase: 'before', type: 'keydown', target: 'popup', options: options, object: w2popup, originalEvent: event });
+ if (eventData.isCancelled === true) return;
+ // default behavior
+ switch (event.keyCode) {
+ case 27:
+ event.preventDefault();
+ if ($('#w2ui-popup .w2ui-popup-message').length > 0) w2popup.message(); else w2popup.close();
+ break;
+ }
+ // event after
+ w2popup.trigger($.extend(eventData, { phase: 'after'}));
+ },
+
+ close: function (options) {
+ var obj = this;
+ var options = $.extend({}, $('#w2ui-popup').data('options'), options);
+ // trigger event
+ var eventData = this.trigger({ phase: 'before', type: 'close', target: 'popup', options: options });
+ if (eventData.isCancelled === true) return;
+ // default behavior
+ $('#w2ui-popup, #w2ui-panel').css({
+ '-webkit-transition': options.speed +'s opacity, '+ options.speed +'s -webkit-transform',
+ '-webkit-transform': 'scale(0.9)',
+ '-moz-transition': options.speed +'s opacity, '+ options.speed +'s -moz-transform',
+ '-moz-transform': 'scale(0.9)',
+ '-ms-transition': options.speed +'s opacity, '+ options.speed +'s -ms-transform',
+ '-ms-transform': 'scale(0.9)',
+ '-o-transition': options.speed +'s opacity, '+ options.speed +'s -o-transform',
+ '-o-transform': 'scale(0.9)',
+ 'opacity': '0'
+ });
+ w2popup.unlockScreen();
+ setTimeout(function () {
+ $('#w2ui-popup').remove();
+ $('#w2ui-panel').remove();
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after'}));
+ }, options.speed * 1000);
+ // restore active
+ w2utils.keyboard.active(options._last_w2ui_name);
+ // remove keyboard events
+ if (options.keyboard) $(document).off('keydown', this.keydown);
+ },
+
+ toggle: function () {
+ var options = $('#w2ui-popup').data('options');
+ if (options.maximized === true) w2popup.min(); else w2popup.max();
+ },
+
+ max: function () {
+ var obj = this;
+ var options = $('#w2ui-popup').data('options');
+ if (options.maximized === true) return;
+ // trigger event
+ var eventData = this.trigger({ phase: 'before', type: 'max', target: 'popup', options: options });
+ if (eventData.isCancelled === true) return;
+ // default behavior
+ options.maximized = true;
+ options.prevSize = $('#w2ui-popup').css('width')+':'+$('#w2ui-popup').css('height');
+ $('#w2ui-popup').data('options', options);
+ // do resize
+ w2popup.resize(10000, 10000, function () {
+ obj.trigger($.extend(eventData, { phase: 'after'}));
+ });
+ },
+
+ min: function () {
+ var obj = this;
+ var options = $('#w2ui-popup').data('options');
+ if (options.maximized !== true) return;
+ var size = options.prevSize.split(':');
+ // trigger event
+ var eventData = this.trigger({ phase: 'before', type: 'min', target: 'popup', options: options });
+ if (eventData.isCancelled === true) return;
+ // default behavior
+ options.maximized = false;
+ options.prevSize = null;
+ $('#w2ui-popup').data('options', options);
+ // do resize
+ w2popup.resize(size[0], size[1], function () {
+ obj.trigger($.extend(eventData, { phase: 'after'}));
+ });
+ },
+
+ get: function () {
+ return $('#w2ui-popup').data('options');
+ },
+
+ set: function (options) {
+ w2popup.open(options);
+ },
+
+ clear: function() {
+ $('#w2ui-popup .w2ui-msg-title').html('');
+ $('#w2ui-popup .w2ui-msg-body').html('');
+ $('#w2ui-popup .w2ui-msg-buttons').html('');
+ },
+
+ reset: function () {
+ w2popup.open(w2popup.defaults);
+ },
+
+ load: function (options) {
+ if (String(options.url) == 'undefined') {
+ console.log('ERROR: The url parameter is empty.');
+ return;
+ }
+ var tmp = String(options.url).split('#');
+ var url = tmp[0];
+ var selector = tmp[1];
+ if (String(options) == 'undefined') options = {};
+ // load url
+ var html = $('#w2ui-popup').data(url);
+ if (typeof html != 'undefined' && html != null) {
+ popup(html, selector);
+ } else {
+ $.get(url, function (data, status, obj) {
+ popup(obj.responseText, selector);
+ $('#w2ui-popup').data(url, obj.responseText); // remember for possible future purposes
+ });
+ }
+ function popup(html, selector) {
+ delete options.url;
+ $('body').append('
'+ html +'
');
+ if (typeof selector != 'undefined' && $('#w2ui-tmp #'+selector).length > 0) {
+ $('#w2ui-tmp #'+ selector).w2popup(options);
+ } else {
+ $('#w2ui-tmp > div').w2popup(options);
+ }
+ // link styles
+ if ($('#w2ui-tmp > style').length > 0) {
+ var style = $('
').append($('#w2ui-tmp > style').clone()).html();
+ if ($('#w2ui-popup #div-style').length == 0) {
+ $('#w2ui-ppopup').append('
');
+ }
+ $('#w2ui-popup #div-style').html(style);
+ }
+ $('#w2ui-tmp').remove();
+ }
+ },
+
+ message: function (options) {
+ $().w2tag(); // hide all tags
+ if (!options) options = { width: 200, height: 100 };
+ if (parseInt(options.width) < 10) options.width = 10;
+ if (parseInt(options.height) < 10) options.height = 10;
+ if (typeof options.hideOnClick == 'undefined') options.hideOnClick = false;
+
+ var head = $('#w2ui-popup .w2ui-msg-title');
+ if ($('#w2ui-popup .w2ui-popup-message').length == 0) {
+ var pwidth = parseInt($('#w2ui-popup').width());
+ $('#w2ui-popup .w2ui-box1')
+ .before('');
+ $('#w2ui-popup .w2ui-popup-message').data('options', options);
+ } else {
+ if (typeof options.width == 'undefined') options.width = w2utils.getSize($('#w2ui-popup .w2ui-popup-message'), 'width');
+ if (typeof options.height == 'undefined') options.height = w2utils.getSize($('#w2ui-popup .w2ui-popup-message'), 'height');
+ }
+ var display = $('#w2ui-popup .w2ui-popup-message').css('display');
+ $('#w2ui-popup .w2ui-popup-message').css({
+ '-webkit-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)'),
+ '-moz-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)'),
+ '-ms-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)'),
+ '-o-transform': (display == 'none' ? 'translateY(-'+ options.height + 'px)': 'translateY(0px)')
+ });
+ if (display == 'none') {
+ $('#w2ui-popup .w2ui-popup-message').show().html(options.html);
+ setTimeout(function() {
+ $('#w2ui-popup .w2ui-popup-message').css({
+ '-webkit-transition': '0s', '-moz-transition': '0s', '-ms-transition': '0s', '-o-transition': '0s',
+ 'z-Index': 1500
+ }); // has to be on top of lock
+ w2popup.lock();
+ if (typeof options.onOpen == 'function') options.onOpen();
+ }, 300);
+ } else {
+ $('#w2ui-popup .w2ui-popup-message').css('z-Index', 250);
+ var options = $('#w2ui-popup .w2ui-popup-message').data('options');
+ $('#w2ui-popup .w2ui-popup-message').remove();
+ w2popup.unlock();
+ if (typeof options.onClose == 'function') options.onClose();
+ }
+ // timer needs to animation
+ setTimeout(function () {
+ $('#w2ui-popup .w2ui-popup-message').css({
+ '-webkit-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)'),
+ '-moz-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)'),
+ '-ms-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)'),
+ '-o-transform': (display == 'none' ? 'translateY(0px)': 'translateY(-'+ options.height +'px)')
+ });
+ }, 1);
+ },
+
+ lock: function (msg, showSpinner) {
+ w2utils.lock($('#w2ui-popup'), msg, showSpinner);
+ },
+
+ unlock: function () {
+ w2utils.unlock($('#w2ui-popup'));
+ },
+
+ // --- INTERNAL FUNCTIONS
+
+ lockScreen: function (options) {
+ if ($('#w2ui-lock').length > 0) return false;
+ if (typeof options == 'undefined') options = $('#w2ui-popup').data('options');
+ if (typeof options == 'undefined') options = {};
+ options = $.extend({}, w2popup.defaults, options);
+ // show element
+ $('body').append('
');
+ // lock screen
+ setTimeout(function () {
+ $('#w2ui-lock').css({
+ '-webkit-transition': options.speed +'s opacity',
+ '-moz-transition': options.speed +'s opacity',
+ '-ms-transition': options.speed +'s opacity',
+ '-o-transition': options.speed +'s opacity',
+ 'opacity': options.opacity
+ });
+ }, 1);
+ // add events
+ if (options.modal == true) {
+ $('#w2ui-lock').on('mousedown', function () {
+ $('#w2ui-lock').css({
+ '-webkit-transition': '.1s',
+ '-moz-transition': '.1s',
+ '-ms-transition': '.1s',
+ '-o-transition': '.1s',
+ 'opacity': '0.6'
+ });
+ if (window.getSelection) window.getSelection().removeAllRanges();
+ });
+ $('#w2ui-lock').on('mouseup', function () {
+ setTimeout(function () {
+ $('#w2ui-lock').css({
+ '-webkit-transition': '.1s',
+ '-moz-transition': '.1s',
+ '-ms-transition': '.1s',
+ '-o-transition': '.1s',
+ 'opacity': options.opacity
+ });
+ }, 100);
+ if (window.getSelection) window.getSelection().removeAllRanges();
+ });
+ } else {
+ $('#w2ui-lock').on('mouseup', function () { w2popup.close(); });
+ }
+ return true;
+ },
+
+ unlockScreen: function () {
+ if ($('#w2ui-lock').length == 0) return false;
+ var options = $.extend({}, $('#w2ui-popup').data('options'), options);
+ $('#w2ui-lock').css({
+ '-webkit-transition': options.speed +'s opacity',
+ '-moz-transition': options.speed +'s opacity',
+ '-ms-transition': options.speed +'s opacity',
+ '-o-transition': options.speed +'s opacity',
+ 'opacity': 0
+ });
+ setTimeout(function () {
+ $('#w2ui-lock').remove();
+ }, options.speed * 1000);
+ return true;
+ },
+
+ resize: function (width, height, callBack) {
+ var options = $('#w2ui-popup').data('options');
+ // calculate new position
+ if (parseInt($(window).width()) - 10 < parseInt(width)) width = parseInt($(window).width()) - 10;
+ if (parseInt($(window).height()) - 10 < parseInt(height)) height = parseInt($(window).height()) - 10;
+ var top = ((parseInt($(window).height()) - parseInt(height)) / 2) * 0.8;
+ var left = (parseInt($(window).width()) - parseInt(width)) / 2;
+ // resize there
+ $('#w2ui-popup').css({
+ '-webkit-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top',
+ '-moz-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top',
+ '-ms-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top',
+ '-o-transition': options.speed + 's width, '+ options.speed + 's height, '+ options.speed + 's left, '+ options.speed + 's top',
+ 'top': top,
+ 'left': left,
+ 'width': width,
+ 'height': height
+ });
+ if (typeof callBack == 'function') {
+ setTimeout(function () {
+ callBack();
+ }, options.speed * 1000);
+ }
+ }
+ }
+
+ // merge in event handling
+ $.extend(w2popup, w2utils.event);
+
+})(jQuery);
+
+// ============================================
+// --- Common dialogs
+
+var w2alert = function (msg, title, callBack) {
+ if (typeof title == 'undefined') title = w2utils.lang('Notification');
+ if (jQuery('#w2ui-popup').length > 0) {
+ w2popup.message({
+ width : 400,
+ height : 150,
+ html : '
'+
+ '
'+
+ ' '+
+ '
',
+ onClose : function () {
+ if (typeof callBack == 'function') callBack();
+ }
+ });
+ } else {
+ w2popup.open({
+ width : 450,
+ height : 200,
+ showMax : false,
+ title : title,
+ body : '
',
+ buttons : '',
+ onClose : function () {
+ if (typeof callBack == 'function') callBack();
+ }
+ });
+ }
+};
+
+var w2confirm = function (msg, title, callBack) {
+ if (typeof callBack == 'undefined' || typeof title == 'function') {
+ callBack = title;
+ title = w2utils.lang('Confirmation');
+ }
+ if (typeof title == 'undefined') {
+ title = w2utils.lang('Confirmation');
+ }
+ if (jQuery('#w2ui-popup').length > 0) {
+ w2popup.message({
+ width : 400,
+ height : 150,
+ html : '
'+
+ '
'+
+ ' '+
+ ' '+
+ '
',
+ onOpen: function () {
+ jQuery('#w2ui-popup .w2ui-popup-message .w2ui-popup-button').on('click', function (event) {
+ w2popup.message();
+ if (typeof callBack == 'function') callBack(event.target.id);
+ });
+ },
+ onKeydown: function (event) {
+ switch (event.originalEvent.keyCode) {
+ case 13: // enter
+ if (typeof callBack == 'function') callBack('Yes');
+ w2popup.message();
+ break
+ case 27: // esc
+ if (typeof callBack == 'function') callBack('No');
+ w2popup.message();
+ break
+ }
+ }
+ });
+ } else {
+ w2popup.open({
+ width : 450,
+ height : 200,
+ title : title,
+ modal : true,
+ showClose : false,
+ body : '
',
+ buttons : ''+
+ '',
+ onOpen: function (event) {
+ event.onComplete = function () {
+ jQuery('#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: // enter
+ if (typeof callBack == 'function') callBack('Yes');
+ w2popup.close();
+ break
+ case 27: // esc
+ if (typeof callBack == 'function') callBack('No');
+ w2popup.close();
+ break
+ }
+ }
+ });
+ }
+};
+
+/************************************************************************
+ * Library: Web 2.0 UI for jQuery (using prototypical inheritance)
+ * - Following objects defined
+ * - w2tabs - tabs widget
+ * - $().w2tabs - jQuery wrapper
+ * - Dependencies: jQuery, w2utils
+ *
+ * == NICE TO HAVE ==
+ * - tabs might not work in chromium apps, need bind()
+ * - on overflow display << >>
+ * - individual tab onClick (possibly other events) are not working
+ *
+ ************************************************************************/
+
+(function ($) {
+ var w2tabs = function (options) {
+ this.box = null; // DOM Element that holds the element
+ this.name = null; // unique name for w2ui
+ 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);
+ }
+
+ // ====================================================
+ // -- Registers as a jQuery plugin
+
+ $.fn.w2tabs = 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 $().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;
+ }
+ // extend tabs
+ 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]);
+ }
+ // register new object
+ 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' );
+ }
+ };
+
+ // ====================================================
+ // -- Implementation of core functionality
+
+ w2tabs.prototype = {
+ tab : {
+ id : null, // commnad to be sent to all event handlers
+ 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];
+ // assume it is array
+ for (var r in tab) {
+ // checks
+ 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;
+ }
+ // add tab
+ 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 < arguments.length; a++) {
+ var tab = this.get(arguments[a]);
+ if (!tab) return false;
+ removed++;
+ // remove from array
+ this.tabs.splice(this.get(tab.id, true), 1);
+ // remove from screen
+ $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).remove();
+ }
+ return removed;
+ },
+
+ select: function (id) {
+ if (this.get(id) == null || this.active == id) return false;
+ this.active = id;
+ this.refresh();
+ return true;
+ },
+
+ set: function (id, tab) {
+ var index = this.get(id, true);
+ if (index == null) return false;
+ $.extend(this.tabs[index], tab);
+ this.refresh(id);
+ return true;
+ },
+
+ get: function (id, returnIndex) {
+ if (arguments.length == 0) {
+ var all = [];
+ for (var i = 0; i < this.tabs.length; i++) if (this.tabs[i].id != null) all.push(this.tabs[i].id);
+ return all;
+ }
+ for (var i in this.tabs) {
+ if (this.tabs[i].id == id) {
+ if (returnIndex === true) return i; else return this.tabs[i];
+ }
+ }
+ return null;
+ },
+
+ show: function () {
+ var shown = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var tab = this.get(arguments[a]);
+ if (!tab || tab.hidden === false) continue;
+ tab.hidden = false;
+ this.refresh(tab.id);
+ shown++;
+ }
+ return shown;
+ },
+
+ hide: function () {
+ var hidden = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var tab = this.get(arguments[a]);
+ if (!tab || tab.hidden === true) continue;
+ tab.hidden = true;
+ this.refresh(tab.id);
+ hidden++;
+ }
+ return hidden;
+ },
+
+ enable: function (id) {
+ var enabled = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var tab = this.get(arguments[a]);
+ if (!tab || tab.disabled === false) continue;
+ tab.disabled = false;
+ this.refresh(tab.id);
+ enabled++;
+ }
+ return enabled;
+ },
+
+ disable: function (id) {
+ var disabled = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var tab = this.get(arguments[a]);
+ if (!tab || tab.disabled === true) continue;
+ tab.disabled = true;
+ this.refresh(tab.id);
+ disabled++;
+ }
+ return disabled;
+ },
+
+ refresh: function (id) {
+ var time = (new Date()).getTime();
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ if (String(id) == 'undefined') {
+ // refresh all
+ for (var i in this.tabs) this.refresh(this.tabs[i].id);
+ }
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name), object: this.get(id) });
+ if (eventData.isCancelled === true) return false;
+ // create or refresh only one item
+ var tab = this.get(id);
+ if (tab == null) return;
+ if (typeof tab.caption != 'undefined') tab.text = tab.caption;
+
+ var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id));
+ var tabHTML = (tab.closable ? '
' : '') +
+ '
' + tab.text + '
';
+ if (jq_el.length == 0) {
+ // does not exist - create it
+ var addStyle = '';
+ if (tab.hidden) { addStyle += 'display: none;'; }
+ if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; }
+ html = '
'+ tabHTML + ' | ';
+ if (this.get(id, true) != this.tabs.length-1 && $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).length > 0) {
+ $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.tabs[parseInt(this.get(id, true))+1].id)).before(html);
+ } else {
+ $(this.box).find('#tabs_'+ this.name +'_right').before(html);
+ }
+ } else {
+ // refresh
+ jq_el.html(tabHTML);
+ if (tab.hidden) { jq_el.css('display', 'none'); }
+ else { jq_el.css('display', ''); }
+ if (tab.disabled) { jq_el.css({ 'opacity': '0.2', '-moz-opacity': '0.2', '-webkit-opacity': '0.2', '-o-opacity': '0.2', 'filter': 'alpha(opacity=20)' }); }
+ else { jq_el.css({ 'opacity': '1', '-moz-opacity': '1', '-webkit-opacity': '1', '-o-opacity': '1', 'filter': 'alpha(opacity=100)' }); }
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ return (new Date()).getTime() - time;
+ },
+
+ render: function (box) {
+ var time = (new Date()).getTime();
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ if (String(box) != 'undefined' && box != null) {
+ if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) {
+ $(this.box)
+ .removeAttr('name')
+ .removeClass('w2ui-reset w2ui-tabs')
+ .html('');
+ }
+ this.box = box;
+ }
+ if (!this.box) return;
+ // render all buttons
+ var html = '
'+
+ ' '+ this.right +' |
'+
+ '
';
+ $(this.box)
+ .attr('name', this.name)
+ .addClass('w2ui-reset w2ui-tabs')
+ .html(html);
+ if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style;
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ this.refresh();
+ return (new Date()).getTime() - time;
+ },
+
+ resize: function () {
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name });
+ if (eventData.isCancelled === true) return false;
+ // empty function
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ destroy: function () {
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'destroy', target: this.name });
+ if (eventData.isCancelled === true) return false;
+ // clean up
+ if ($(this.box).find('> table #tabs_'+ this.name + '_right').length > 0) {
+ $(this.box)
+ .removeAttr('name')
+ .removeClass('w2ui-reset w2ui-tabs')
+ .html('');
+ }
+ delete w2ui[this.name];
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ // ===================================================
+ // -- Internal Event Handlers
+
+ click: function (id, event) {
+ var tab = this.get(id);
+ if (tab == null || tab.disabled) return false;
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'click', target: id, object: this.get(id), originalEvent: event });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(this.active) +' .w2ui-tab').removeClass('active');
+ this.active = tab.id;
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ this.refresh(id);
+ },
+
+ animateClose: function(id, event) {
+ var tab = this.get(id);
+ if (tab == null || tab.disabled) return false;
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'close', target: id, object: this.get(id), originalEvent: event });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ var obj = this;
+ $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id)).css({
+ '-webkit-transition': '.2s',
+ '-moz-transition': '2s',
+ '-ms-transition': '.2s',
+ '-o-transition': '.2s',
+ opacity: '0' });
+ setTimeout(function () {
+ var width = $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).width();
+ $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id))
+ .html('
')
+ setTimeout(function () {
+ $(obj.box).find('#tabs_'+ obj.name +'_tab_'+ w2utils.escapeId(tab.id)).find(':first-child').css({ 'width': '0px' });
+ }, 50);
+ }, 200);
+ setTimeout(function () {
+ obj.remove(id);
+ }, 450);
+ // event before
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ this.refresh();
+ },
+
+ animateInsert: function(id, tab) {
+ if (this.get(id) == null) return;
+ if (!$.isPlainObject(tab)) return;
+ // check for unique
+ var unique = true;
+ for (var i in this.tabs) { if (this.tabs[i].id == tab.id) { unique = false; break; } }
+ if (!unique) {
+ console.log('ERROR: The parameter "id='+ tab.id +'" is not unique within the current tabs. (obj: '+ this.name +')');
+ return;
+ }
+ // insert simple div
+ var jq_el = $(this.box).find('#tabs_'+ this.name +'_tab_'+ w2utils.escapeId(tab.id));
+ if (jq_el.length != 0) return; // already exists
+ // measure width
+ if (typeof tab.caption != 'undefined') tab.text = tab.caption;
+ var tmp = '
'+
+ '
'+
+ ''+
+ (tab.closable ? '' : '') +
+ ' '+ tab.text +' '+
+ ' |
'+
+ '
';
+ $('body').append(tmp);
+ // create dummy element
+ tabHTML = '
';
+ var addStyle = '';
+ if (tab.hidden) { addStyle += 'display: none;'; }
+ if (tab.disabled) { addStyle += 'opacity: 0.2; -moz-opacity: 0.2; -webkit-opacity: 0.2; -o-opacity: 0.2; filter:alpha(opacity=20);'; }
+ html = '
'+ tabHTML +' | ';
+ 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);
+ }
+ // -- move
+ 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 () {
+ // insert for real
+ obj.insert(id, tab);
+ }, 200);
+ }
+ }
+
+ $.extend(w2tabs.prototype, w2utils.event);
+ w2obj.tabs = w2tabs;
+})(jQuery);
+
+/************************************************************************
+ * Library: Web 2.0 UI for jQuery (using prototypical inheritance)
+ * - Following objects defined
+ * - w2toolbar - toolbar widget
+ * - $().w2toolbar - jQuery wrapper
+ * - Dependencies: jQuery, w2utils
+ *
+ * == NICE TO HAVE ==
+ * - on overflow display << >>
+ *
+ ************************************************************************/
+
+(function ($) {
+ var w2toolbar = function (options) {
+ this.box = null, // DOM Element that holds the element
+ this.name = null, // unique name for w2ui
+ this.items = [],
+ this.right = '', // HTML text on the right of toolbar
+ this.onClick = null,
+ this.onRender = null,
+ this.onRefresh = null,
+ this.onResize = null,
+ this.onDestroy = null
+
+ $.extend(true, this, w2obj.toolbar, options);
+ }
+
+ // ====================================================
+ // -- Registers as a jQuery plugin
+
+ $.fn.w2toolbar = 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 $().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;
+ // extend 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]);
+ }
+ // register new object
+ 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' );
+ }
+ };
+
+ // ====================================================
+ // -- Implementation of core functionality
+
+ w2toolbar.prototype = {
+ item: {
+ id : null, // commnad to be sent to all event handlers
+ type : 'button', // button, check, radio, drop, menu, break, html, spacer
+ text : '',
+ html : '',
+ img : null,
+ icon : null,
+ hidden : false,
+ disabled: false,
+ checked : false, // used for radio buttons
+ arrow : true, // arrow down for drop/menu types
+ hint : '',
+ group : null, // used for radio buttons
+ items : null, // for type menu it is an array of items in the menu
+ onClick : null
+ },
+
+ add: function (items) {
+ this.insert(null, items);
+ },
+
+ insert: function (id, items) {
+ if (!$.isArray(items)) items = [items];
+ for (var o in items) {
+ // checks
+ 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 < this.items.length; i++) { if (this.items[i].id == items[o].id) { unique = false; return; } }
+ if (!unique) {
+ console.log('ERROR: The parameter "id" is not unique within the current toolbar.');
+ return;
+ }
+ if (!w2utils.isAlphaNumeric(items[o].id)) {
+ console.log('ERROR: The parameter "id" must be alpha-numeric + "-_".');
+ return;
+ }
+ // add item
+ var it = $.extend({}, w2toolbar.prototype.item, items[o]);
+ if (id == null || typeof id == 'undefined') {
+ this.items.push(it);
+ } else {
+ var middle = this.get(id, true);
+ this.items = this.items.slice(0, middle).concat([it], this.items.slice(middle));
+ }
+ this.refresh(it.id);
+ }
+ },
+
+ remove: function (id) {
+ var removed = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var it = this.get(arguments[a]);
+ if (!it) continue;
+ removed++;
+ // remove from screen
+ $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id)).remove();
+ // remove from array
+ var ind = this.get(it.id, true);
+ if (ind) this.items.splice(ind, 1);
+ }
+ return removed;
+ },
+
+ set: function (id, item) {
+ var index = this.get(id, true);
+ if (index == null) return false;
+ $.extend(this.items[index], item);
+ this.refresh(id);
+ return true;
+ },
+
+ get: function (id, returnIndex) {
+ if (arguments.length == 0) {
+ var all = [];
+ for (var i = 0; i < this.items.length; i++) if (this.items[i].id != null) all.push(this.items[i].id);
+ return all;
+ }
+ for (var i = 0; i < this.items.length; i++) {
+ if (this.items[i].id == id) {
+ if (returnIndex === true) return i; else return this.items[i];
+ }
+ }
+ return null;
+ },
+
+ show: function (id) {
+ var items = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var it = this.get(arguments[a]);
+ if (!it) continue;
+ items++;
+ it.hidden = false;
+ this.refresh(it.id);
+ }
+ return items;
+ },
+
+ hide: function (id) {
+ var items = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var it = this.get(arguments[a]);
+ if (!it) continue;
+ items++;
+ it.hidden = true;
+ this.refresh(it.id);
+ }
+ return items;
+ },
+
+ enable: function (id) {
+ var items = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var it = this.get(arguments[a]);
+ if (!it) continue;
+ items++;
+ it.disabled = false;
+ this.refresh(it.id);
+ }
+ return items;
+ },
+
+ disable: function (id) {
+ var items = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var it = this.get(arguments[a]);
+ if (!it) continue;
+ items++;
+ it.disabled = true;
+ this.refresh(it.id);
+ }
+ return items;
+ },
+
+ check: function (id) {
+ var items = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var it = this.get(arguments[a]);
+ if (!it) continue;
+ items++;
+ it.checked = true;
+ this.refresh(it.id);
+ }
+ return items;
+ },
+
+ uncheck: function (id) {
+ var items = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var it = this.get(arguments[a]);
+ if (!it) continue;
+ items++;
+ it.checked = false;
+ this.refresh(it.id);
+ }
+ return items;
+ },
+
+ render: function (box) {
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box });
+ if (eventData.isCancelled === true) return false;
+
+ if (typeof box != 'undefined' && box != null) {
+ if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) {
+ $(this.box)
+ .removeAttr('name')
+ .removeClass('w2ui-reset w2ui-toolbar')
+ .html('');
+ }
+ this.box = box;
+ }
+ if (!this.box) return;
+ // render all buttons
+ var html = '
'+
+ '';
+ for (var i = 0; i < this.items.length; i++) {
+ var it = this.items[i];
+ if (typeof it.id == 'undefined' || it.id == null) it.id = "item_" + i;
+ if (it == null) continue;
+ if (it.type == 'spacer') {
+ html += ' | ';
+ } else {
+ html += ''+ this.getItemHTML(it) +
+ ' | ';
+ }
+ }
+ html += ''+ this.right +' | ';
+ html += '
'+
+ '
';
+ $(this.box)
+ .attr('name', this.name)
+ .addClass('w2ui-reset w2ui-toolbar')
+ .html(html);
+ if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style;
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ refresh: function (id) {
+ var time = (new Date()).getTime();
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name), item: this.get(id) });
+ if (eventData.isCancelled === true) return false;
+
+ if (typeof id == 'undefined') {
+ // refresh all
+ for (var i = 0; i < this.items.length; i++) {
+ var it = this.items[i];
+ if (typeof it.id == 'undefined' || it.id == null) it.id = "item_" + i;
+ this.refresh(it.id);
+ }
+ }
+ // create or refresh only one item
+ var it = this.get(id);
+ if (it == null) return;
+
+ var el = $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id));
+ var html = this.getItemHTML(it);
+ if (el.length == 0) {
+ // does not exist - create it
+ if (it.type == 'spacer') {
+ html = '
| ';
+ } else {
+ html = '
'+ html +
+ ' | ';
+ }
+ if (this.get(id, true) == this.items.length-1) {
+ $(this.box).find('#tb_'+ this.name +'_right').before(html);
+ } else {
+ $(this.box).find('#tb_'+ this.name +'_item_'+ w2utils.escapeId(this.items[parseInt(this.get(id, true))+1].id)).before(html);
+ }
+ } else {
+ // refresh
+ el.html(html);
+ if (it.hidden) { el.css('display', 'none'); } else { el.css('display', ''); }
+ if (it.disabled) { el.addClass('disabled'); } else { el.removeClass('disabled'); }
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ return (new Date()).getTime() - time;
+ },
+
+ resize: function () {
+ var time = (new Date()).getTime();
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name });
+ if (eventData.isCancelled === true) return false;
+
+ // empty function
+
+ // event after
+ 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;
+ // clean up
+ if ($(this.box).find('> table #tb_'+ this.name + '_right').length > 0) {
+ $(this.box)
+ .removeAttr('name')
+ .removeClass('w2ui-reset w2ui-toolbar')
+ .html('');
+ }
+ $(this.box).html('');
+ delete w2ui[this.name];
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ // ========================================
+ // --- Internal Functions
+
+ getItemHTML: function (item) {
+ var html = '';
+
+ if (typeof item.caption != 'undefined') item.text = item.caption;
+ if (typeof item.hint == 'undefined') item.hint = '';
+ if (typeof item.text == 'undefined') item.text = '';
+
+ switch (item.type) {
+ case 'menu':
+ case 'button':
+ case 'check':
+ case 'radio':
+ case 'drop':
+ var img = '
| ';
+ if (item.img) img = '
| ';
+ if (item.icon) img = '
| ';
+ html += '
';
+ break;
+
+ case 'break':
+ html += '
';
+ break;
+
+ case 'html':
+ html += '
'+
+ ' ' + item.html + ' | '+
+ '
';
+ break;
+ }
+
+ var newHTML = '';
+ if (typeof item.onRender == 'function') newHTML = item.onRender.call(this, item.id, html);
+ if (typeof this.onRender == 'function') newHTML = this.onRender(item.id, html);
+ if (newHTML != '' && typeof newHTML != 'undefined') html = newHTML;
+ return html;
+ },
+
+ menuClick: function (id, menu_index, event) {
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ var obj = this;
+ var it = this.get(id);
+ if (it && !it.disabled) {
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'click', target: (typeof id != 'undefined' ? id : this.name), item: this.get(id),
+ subItem: (typeof menu_index != 'undefined' && this.get(id) ? this.get(id).items[menu_index] : null), originalEvent: event });
+ if (eventData.isCancelled === true) return false;
+
+ // normal processing
+
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ }
+ },
+
+ click: function (id, event) {
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ var obj = this;
+ var it = this.get(id);
+ if (it && !it.disabled) {
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'click', target: (typeof id != 'undefined' ? id : this.name),
+ item: this.get(id), originalEvent: event });
+ if (eventData.isCancelled === true) return false;
+
+ $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').removeClass('down');
+
+ if (it.type == 'radio') {
+ for (var i = 0; i < this.items.length; i++) {
+ var itt = this.items[i];
+ if (itt == null || itt.id == it.id || itt.type != 'radio') continue;
+ if (itt.group == it.group && itt.checked) {
+ itt.checked = false;
+ this.refresh(itt.id);
+ }
+ }
+ it.checked = true;
+ $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').addClass('checked');
+ }
+
+ if (it.type == 'drop' || it.type == 'menu') {
+ if (it.checked) {
+ // if it was already checked, second click will hide it
+ it.checked = false;
+ } else {
+ // show overlay
+ setTimeout(function () {
+ var el = $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id));
+ if (!$.isPlainObject(it.overlay)) it.overlay = {};
+ if (it.type == 'drop') {
+ el.w2overlay(it.html, $.extend({ left: (el.width() - 50) / 2, top: 3 }, it.overlay));
+ }
+ if (it.type == 'menu') {
+ el.w2menu(it.items, $.extend({ left: (el.width() - 50) / 2, top: 3 }, it.overlay, {
+ select: function (item, event, index) { obj.menuClick(it.id, index, event); }
+ }));
+ }
+ // window.click to hide it
+ $(document).on('click', hideDrop);
+ function hideDrop() {
+ it.checked = false;
+ if (it.checked) {
+ $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').addClass('checked');
+ } else {
+ $('#tb_'+ obj.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').removeClass('checked');
+ }
+ obj.refresh(it.id);
+ $(document).off('click', hideDrop);
+ }
+ }, 1);
+ }
+ }
+
+ if (it.type == 'check' || it.type == 'drop' || it.type == 'menu') {
+ it.checked = !it.checked;
+ if (it.checked) {
+ $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').addClass('checked');
+ } else {
+ $('#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button').removeClass('checked');
+ }
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ }
+ }
+ }
+
+ $.extend(w2toolbar.prototype, w2utils.event);
+ w2obj.toolbar = w2toolbar;
+})(jQuery);
+
+/************************************************************************
+ * Library: Web 2.0 UI for jQuery (using prototypical inheritance)
+ * - Following objects defined
+ * - w2sidebar - sidebar widget
+ * - $().w2sidebar - jQuery wrapper
+ * - Dependencies: jQuery, w2utils
+ *
+ * == NICE TO HAVE ==
+ * - return ids of all subitems
+ * - add find() method to find nodes by a specific criteria (I want all nodes for exampe)
+ * - dbl click should be like it is in grid (with timer not HTML dbl click event)
+ *
+ ************************************************************************/
+
+(function ($) {
+ var w2sidebar = function (options) {
+ this.name = null;
+ this.box = null;
+ this.sidebar = null;
+ this.parent = null;
+ this.nodes = []; // Sidebar child nodes
+ this.menu = [];
+ this.selected = null; // current selected node (readonly)
+ this.img = null;
+ this.icon = null;
+ this.style = '';
+ this.topHTML = '';
+ this.bottomHTML = '';
+ this.keyboard = true;
+ this.onClick = null; // Fire when user click on Node Text
+ this.onDblClick = null; // Fire when user dbl clicks
+ this.onContextMenu = null;
+ this.onMenuClick = null; // when context menu item selected
+ this.onExpand = null; // Fire when node Expands
+ this.onCollapse = null; // Fire when node Colapses
+ this.onKeydown = null;
+ this.onRender = null;
+ this.onRefresh = null;
+ this.onResize = null;
+ this.onDestroy = null;
+
+ $.extend(true, this, w2obj.sidebar, options);
+ }
+
+ // ====================================================
+ // -- Registers as a jQuery plugin
+
+ $.fn.w2sidebar = 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 $().w2sidebar().');
+ 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;
+ }
+ // extend items
+ var nodes = method.nodes;
+ var object = new w2sidebar(method);
+ $.extend(object, { handlers: [], nodes: [] });
+ if (typeof nodes != 'undefined') {
+ object.add(object, nodes);
+ }
+ if ($(this).length != 0) {
+ object.render($(this)[0]);
+ }
+ object.sidebar = object;
+ // register new object
+ 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.w2sidebar' );
+ }
+ };
+
+ // ====================================================
+ // -- Implementation of core functionality
+
+ w2sidebar.prototype = {
+
+ node: {
+ id : null,
+ text : '',
+ count : '',
+ img : null,
+ icon : null,
+ nodes : [],
+ style : '',
+ selected : false,
+ expanded : false,
+ hidden : false,
+ disabled : false,
+ group : false, // if true, it will build as a group
+ plus : false, // if true, plus will be shown even if there is no sub nodes
+ // events
+ onClick : null,
+ onDblClick : null,
+ onContextMenu : null,
+ onExpand : null,
+ onCollapse : null,
+ // internal
+ parent : null, // node object
+ sidebar : null
+ },
+
+ add: function (parent, nodes) {
+ if (arguments.length == 1) {
+ // need to be in reverse order
+ nodes = arguments[0];
+ parent = this;
+ }
+ if (typeof parent == 'string') parent = this.get(parent);
+ return this.insert(parent, null, nodes);
+ },
+
+ insert: function (parent, before, nodes) {
+ if (arguments.length == 2) {
+ // need to be in reverse order
+ nodes = arguments[1];
+ before = arguments[0];
+ var ind = this.get(before);
+ if (ind == null) {
+ var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text);
+ console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.');
+ return null;
+ }
+ parent = this.get(before).parent;
+ }
+ if (typeof parent == 'string') parent = this.get(parent);
+ if (!$.isArray(nodes)) nodes = [nodes];
+ for (var o in nodes) {
+ if (typeof nodes[o].id == 'undefined') {
+ var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text);
+ console.log('ERROR: Cannot insert node "'+ txt +'" because it has no id.');
+ continue;
+ }
+ if (this.get(this, nodes[o].id) != null) {
+ var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text);
+ console.log('ERROR: Cannot insert node with id='+ nodes[o].id +' (text: '+ txt + ') because another node with the same id already exists.');
+ continue;
+ }
+ var tmp = $.extend({}, w2sidebar.prototype.node, nodes[o]);
+ tmp.sidebar= this;
+ tmp.parent = parent;
+ var nd = tmp.nodes;
+ tmp.nodes = []; // very important to re-init empty nodes array
+ if (before == null) { // append to the end
+ parent.nodes.push(tmp);
+ } else {
+ var ind = this.get(parent, before, true);
+ if (ind == null) {
+ var txt = (nodes[o].caption != 'undefined' ? nodes[o].caption : nodes[o].text);
+ console.log('ERROR: Cannot insert node "'+ txt +'" because cannot find node "'+ before +'" to insert before.');
+ return null;
+ }
+ parent.nodes.splice(ind, 0, tmp);
+ }
+ if (typeof nd != 'undefined' && nd.length > 0) { this.insert(tmp, null, nd); }
+ }
+ this.refresh(parent.id);
+ return tmp;
+ },
+
+ remove: function () { // multiple arguments
+ var deleted = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var tmp = this.get(arguments[a]);
+ if (tmp == null) continue;
+ var ind = this.get(tmp.parent, arguments[a], true);
+ if (ind == null) continue;
+ tmp.parent.nodes.splice(ind, 1);
+ deleted++;
+ }
+ if (deleted > 0 && arguments.length == 1) this.refresh(tmp.parent.id); else this.refresh();
+ return deleted;
+ },
+
+ set: function (parent, id, node) {
+ if (arguments.length == 2) {
+ // need to be in reverse order
+ node = id;
+ id = parent;
+ parent = this;
+ }
+ // searches all nested nodes
+ this._tmp = null;
+ if (typeof parent == 'string') parent = this.get(parent);
+ if (parent.nodes == null) return null;
+ for (var i=0; i < parent.nodes.length; i++) {
+ if (parent.nodes[i].id == id) {
+ // make sure nodes inserted correctly
+ var nodes = node.nodes;
+ $.extend(parent.nodes[i], node, { nodes: [] });
+ if (typeof nodes != 'undefined') {
+ this.add(parent.nodes[i], nodes);
+ }
+ this.refresh(id);
+ return true;
+ } else {
+ this._tmp = this.set(parent.nodes[i], id, node);
+ if (this._tmp) return true;
+ }
+ }
+ return false;
+ },
+
+ get: function (parent, id, returnIndex) { // can be just called get(id) or get(id, true)
+ if (arguments.length == 1 || (arguments.length == 2 && id === true) ) {
+ // need to be in reverse order
+ returnIndex = id;
+ id = parent;
+ parent = this;
+ }
+ // searches all nested nodes
+ this._tmp = null;
+ if (typeof parent == 'string') parent = this.get(parent);
+ if (parent.nodes == null) return null;
+ for (var i=0; i < parent.nodes.length; i++) {
+ if (parent.nodes[i].id == id) {
+ if (returnIndex === true) return i; else return parent.nodes[i];
+ } else {
+ this._tmp = this.get(parent.nodes[i], id, returnIndex);
+ if (this._tmp || this._tmp === 0) return this._tmp;
+ }
+ }
+ return this._tmp;
+ },
+
+ hide: function () { // multiple arguments
+ var hidden = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var tmp = this.get(arguments[a]);
+ if (tmp == null) continue;
+ tmp.hidden = true;
+ hidden++;
+ }
+ if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh();
+ return hidden;
+ },
+
+ show: function () {
+ var shown = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var tmp = this.get(arguments[a]);
+ if (tmp == null) continue;
+ tmp.hidden = false;
+ shown++;
+ }
+ if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh();
+ return shown;
+ },
+
+ disable: function () { // multiple arguments
+ var disabled = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var tmp = this.get(arguments[a]);
+ if (tmp == null) continue;
+ tmp.disabled = true;
+ if (tmp.selected) this.unselect(tmp.id);
+ disabled++;
+ }
+ if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh();
+ return disabled;
+ },
+
+ enable: function () { // multiple arguments
+ var enabled = 0;
+ for (var a = 0; a < arguments.length; a++) {
+ var tmp = this.get(arguments[a]);
+ if (tmp == null) continue;
+ tmp.disabled = false;
+ enabled++;
+ }
+ if (arguments.length == 1) this.refresh(arguments[0]); else this.refresh();
+ return enabled;
+ },
+
+ select: function (id) {
+ if (this.selected == id) return false;
+ this.unselect(this.selected);
+ var new_node = this.get(id);
+ if (!new_node) return false;
+ $(this.box).find('#node_'+ w2utils.escapeId(id))
+ .addClass('w2ui-selected')
+ .find('.w2ui-icon').addClass('w2ui-icon-selected');
+ new_node.selected = true;
+ this.selected = id;
+ },
+
+ unselect: function (id) {
+ var current = this.get(id);
+ if (!current) return false;
+ current.selected = false;
+ $(this.box).find('#node_'+ w2utils.escapeId(id))
+ .removeClass('w2ui-selected')
+ .find('.w2ui-icon').removeClass('w2ui-icon-selected');
+ if (this.selected == id) this.selected = null;
+ return true;
+ },
+
+ toggle: function(id) {
+ var nd = this.get(id);
+ if (nd == null) return;
+ if (nd.plus) {
+ this.set(id, { plus: false });
+ this.expand(id);
+ this.refresh(id);
+ return;
+ }
+ if (nd.nodes.length == 0) return;
+ if (this.get(id).expanded) this.collapse(id); else this.expand(id);
+ },
+
+ collapse: function (id) {
+ var nd = this.get(id);
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'collapse', target: id, object: nd });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideUp('fast');
+ $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('
+
');
+ nd.expanded = false;
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ this.resize();
+ },
+
+ collapseAll: function (parent) {
+ if (typeof parent == 'undefined') parent = this;
+ if (typeof parent == 'string') parent = this.get(parent);
+ if (parent.nodes == null) return null;
+ for (var i=0; i < parent.nodes.length; i++) {
+ if (parent.nodes[i].expanded === true) parent.nodes[i].expanded = false;
+ if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]);
+ }
+ this.refresh(parent.id);
+ },
+
+ expand: function (id) {
+ var nd = this.get(id);
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'expand', target: id, object: nd });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ $(this.box).find('#node_'+ w2utils.escapeId(id) +'_sub').slideDown('fast');
+ $(this.box).find('#node_'+ w2utils.escapeId(id) +' .w2ui-node-dots:first-child').html('
-
');
+ nd.expanded = true;
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ this.resize();
+ },
+
+ expandAll: function (parent) {
+ if (typeof parent == 'undefined') parent = this;
+ if (typeof parent == 'string') parent = this.get(parent);
+ if (parent.nodes == null) return null;
+ for (var i=0; i < parent.nodes.length; i++) {
+ if (parent.nodes[i].expanded === false) parent.nodes[i].expanded = true;
+ if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]);
+ }
+ this.refresh(parent.id);
+ },
+
+ expandParents: function (id) {
+ var node = this.get(id);
+ if (node == null) return;
+ if (node.parent) {
+ node.parent.expanded = true;
+ this.expandParents(node.parent.id);
+ }
+ this.refresh(id);
+ },
+
+ click: function (id, event) {
+ var obj = this;
+ var nd = this.get(id);
+ if (nd == null) return;
+ var old = this.selected;
+ if (nd.disabled || nd.group) return; // should click event if already selected
+ // move selected first
+ $(obj.box).find('#node_'+ w2utils.escapeId(old)).removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected');
+ $(obj.box).find('#node_'+ w2utils.escapeId(id)).addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected');
+ // need timeout to allow rendering
+ setTimeout(function () {
+ // event before
+ var eventData = obj.trigger({ phase: 'before', type: 'click', target: id, originalEvent: event, object: nd });
+ if (eventData.isCancelled === true) {
+ // restore selection
+ $(obj.box).find('#node_'+ w2utils.escapeId(id)).removeClass('w2ui-selected').find('.w2ui-icon').removeClass('w2ui-icon-selected');
+ $(obj.box).find('#node_'+ w2utils.escapeId(old)).addClass('w2ui-selected').find('.w2ui-icon').addClass('w2ui-icon-selected');
+ return false;
+ }
+ // default action
+ if (old != null) obj.get(old).selected = false;
+ obj.get(id).selected = true;
+ obj.selected = id;
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ }, 1);
+ },
+
+ keydown: function (event) {
+ var obj = this;
+ var nd = obj.get(obj.selected);
+ if (!nd || obj.keyboard !== true) return;
+ // trigger event
+ var eventData = obj.trigger({ phase: 'before', type: 'keydown', target: obj.name, originalEvent: event });
+ if (eventData.isCancelled === true) return false;
+ // default behaviour
+ if (event.keyCode == 13 || event.keyCode == 32) { // enter or space
+ if (nd.nodes.length > 0) obj.toggle(obj.selected);
+ }
+ if (event.keyCode == 37) { // left
+ if (nd.nodes.length > 0) {
+ obj.collapse(obj.selected);
+ } else {
+ // collapse parent
+ if (nd.parent && !nd.parent.disabled && !nd.parent.group) {
+ obj.collapse(nd.parent.id);
+ obj.click(nd.parent.id);
+ setTimeout(function () { obj.scrollIntoView(); }, 50);
+ }
+ }
+ }
+ if (event.keyCode == 39) { // right
+ if (nd.nodes.length > 0) obj.expand(obj.selected);
+ }
+ if (event.keyCode == 38) { // up
+ var tmp = prev(nd);
+ if (tmp != null) { obj.click(tmp.id, event); setTimeout(function () { obj.scrollIntoView(); }, 50); }
+ }
+ if (event.keyCode == 40) { // down
+ var tmp = next(nd);
+ if (tmp != null) { obj.click(tmp.id, event); setTimeout(function () { obj.scrollIntoView(); }, 50); }
+ }
+ // cancel event if needed
+ if ($.inArray(event.keyCode, [13, 32, 37, 38, 39, 40]) != -1) {
+ if (event.preventDefault) event.preventDefault();
+ if (event.stopPropagation) event.stopPropagation();
+ }
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ return;
+
+ function next (node, noSubs) {
+ if (node == null) return null;
+ var parent = node.parent;
+ var ind = obj.get(node.id, true);
+ var nextNode = null;
+ // jump inside
+ if (node.expanded && node.nodes.length > 0 && noSubs !== true) {
+ var t = node.nodes[0];
+ if (!t.disabled && !t.group) nextNode = t; else nextNode = next(t);
+ } else {
+ if (parent && ind + 1 < parent.nodes.length) {
+ nextNode = parent.nodes[ind + 1];
+ } else {
+ nextNode = next(parent, true); // jump to the parent
+ }
+ }
+ if (nextNode != null && (nextNode.disabled || nextNode.group)) nextNode = next(nextNode);
+ return nextNode;
+ }
+
+ function prev (node) {
+ if (node == null) return null;
+ var parent = node.parent;
+ var ind = obj.get(node.id, true);
+ var prevNode = null;
+ var noSubs = false;
+ if (ind > 0) {
+ prevNode = parent.nodes[ind - 1];
+ // jump inside parents last node
+ if (prevNode.expanded && prevNode.nodes.length > 0) {
+ var t = prevNode.nodes[prevNode.nodes.length - 1];
+ if (!t.disabled && !t.group) prevNode = t; else prevNode = prev(t);
+ }
+ } else {
+ prevNode = parent; // jump to the parent
+ noSubs = true;
+ }
+ if (prevNode != null && (prevNode.disabled || prevNode.group)) prevNode = prev(prevNode);
+ return prevNode;
+ }
+ },
+
+ scrollIntoView: function (id) {
+ if (typeof id == 'undefined') id = this.selected;
+ var nd = this.get(id);
+ if (nd == null) return;
+ var body = $(this.box).find('.w2ui-sidebar-div');
+ var item = $(this.box).find('#node_'+ w2utils.escapeId(id));
+ var offset = item.offset().top - body.offset().top;
+ if (offset + item.height() > body.height()) {
+ body.animate({ 'scrollTop': body.scrollTop() + body.height() / 1.3 });
+ }
+ if (offset <= 0) {
+ body.animate({ 'scrollTop': body.scrollTop() - body.height() / 1.3 });
+ }
+ },
+
+ dblClick: function (id, event) {
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ var nd = this.get(id);
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'dblClick', target: id, originalEvent: event, object: nd });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ if (nd.nodes.length > 0) this.toggle(id);
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ contextMenu: function (id, event) {
+ var obj = this;
+ var nd = obj.get(id);
+ if (id != obj.selected) obj.click(id);
+ // need timeout to allow click to finish first
+ setTimeout(function () {
+ // event before
+ var eventData = obj.trigger({ phase: 'before', type: 'contextMenu', target: id, originalEvent: event, object: nd });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ if (nd.group || nd.disabled) return;
+ if (obj.menu.length > 0) {
+ $(obj.box).find('#node_'+ w2utils.escapeId(id))
+ .w2menu(obj.menu, {
+ left: (event ? event.offsetX || event.pageX : 50) - 25,
+ select: function (item, event, index) { obj.menuClick(id, index, event); }
+ }
+ );
+ }
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ }, 1);
+ },
+
+ menuClick: function (itemId, index, event) {
+ var obj = this;
+ // event before
+ var eventData = obj.trigger({ phase: 'before', type: 'menuClick', target: itemId, originalEvent: event, menuIndex: index, menuItem: obj.menu[index] });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ // -- empty
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ render: function (box) {
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'render', target: this.name, box: box });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ if (typeof box != 'undefined' && box != null) {
+ if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) {
+ $(this.box)
+ .removeAttr('name')
+ .removeClass('w2ui-reset w2ui-sidebar')
+ .html('');
+ }
+ this.box = box;
+ }
+ if (!this.box) return;
+ $(this.box)
+ .attr('name', this.name)
+ .addClass('w2ui-reset w2ui-sidebar')
+ .html('
'+
+ '' +
+ ''+
+ ''+
+ '
'
+ );
+ $(this.box).find('> div').css({
+ width : $(this.box).width() + 'px',
+ height : $(this.box).height() + 'px'
+ });
+ if ($(this.box).length > 0) $(this.box)[0].style.cssText += this.style;
+ // adjust top and bottom
+ if (this.topHTML != '') {
+ $(this.box).find('.w2ui-sidebar-top').html(this.topHTML);
+ $(this.box).find('.w2ui-sidebar-div')
+ .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px');
+ }
+ if (this.bottomHTML != '') {
+ $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML);
+ $(this.box).find('.w2ui-sidebar-div')
+ .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px');
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ // ---
+ this.refresh();
+ },
+
+ refresh: function (id) {
+ var time = (new Date()).getTime();
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'refresh', target: (typeof id != 'undefined' ? id : this.name) });
+ if (eventData.isCancelled === true) return false;
+ // adjust top and bottom
+ if (this.topHTML != '') {
+ $(this.box).find('.w2ui-sidebar-top').html(this.topHTML);
+ $(this.box).find('.w2ui-sidebar-div')
+ .css('top', $(this.box).find('.w2ui-sidebar-top').height() + 'px');
+ }
+ if (this.bottomHTML != '') {
+ $(this.box).find('.w2ui-sidebar-bottom').html(this.bottomHTML);
+ $(this.box).find('.w2ui-sidebar-div')
+ .css('bottom', $(this.box).find('.w2ui-sidebar-bottom').height() + 'px');
+ }
+ // default action
+ $(this.box).find('> div').css({
+ width : $(this.box).width() + 'px',
+ height : $(this.box).height() + 'px'
+ });
+ var obj = this;
+ if (typeof id == 'undefined') {
+ var node = this;
+ var nm = '.w2ui-sidebar-div';
+ } else {
+ var node = this.get(id);
+ if (node == null) return;
+ var nm = '#node_'+ w2utils.escapeId(node.id) + '_sub';
+ }
+ if (node != this) {
+ var tmp = '#node_'+ w2utils.escapeId(node.id);
+ var nodeHTML = getNodeHTML(node);
+ $(this.box).find(tmp).before('');
+ $(this.box).find(tmp).remove();
+ $(this.box).find(nm).remove();
+ $('#sidebar_'+ this.name + '_tmp').before(nodeHTML);
+ $('#sidebar_'+ this.name + '_tmp').remove();
+ }
+ // refresh sub nodes
+ $(this.box).find(nm).html('');
+ for (var i=0; i < node.nodes.length; i++) {
+ var nodeHTML = getNodeHTML(node.nodes[i]);
+ $(this.box).find(nm).append(nodeHTML);
+ if (node.nodes[i].nodes.length != 0) { this.refresh(node.nodes[i].id); }
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ return (new Date()).getTime() - time;
+
+ function getNodeHTML(nd) {
+ var html = '';
+ var img = nd.img;
+ if (img == null) img = this.img;
+ var icon = nd.icon;
+ if (icon == null) icon = this.icon;
+ // -- find out level
+ var tmp = nd.parent;
+ var level = 0;
+ while (tmp && tmp.parent != null) {
+ if (tmp.group) level--;
+ tmp = tmp.parent;
+ level++;
+ }
+ if (typeof nd.caption != 'undefined') nd.text = nd.caption;
+ if (nd.group) {
+ html =
+ '
'+
+ ' '+ (!nd.hidden && nd.expanded ? w2utils.lang('Hide') : w2utils.lang('Show')) +''+
+ ' '+ nd.text +''+
+ '
'+
+ '
';
+ } else {
+ if (nd.selected && !nd.disabled) obj.selected = nd.id;
+ var tmp = '';
+ if (img) tmp = '
';
+ if (icon) tmp = '
';
+ html =
+ '
'+
+ '
'+
+ ''+
+ ' ' + (nd.nodes.length > 0 ? (nd.expanded ? '-' : '+') : (nd.plus ? '+' : '')) + ' ' +
+ ' | '+
+ ''+
+ tmp +
+ (nd.count !== '' ? ' '+ nd.count +' ' : '') +
+ ''+ nd.text +' '+
+ ' | '+
+ '
'+
+ '
'+
+ '
';
+ }
+ return html;
+ }
+ },
+
+ resize: function () {
+ var time = (new Date()).getTime();
+ if (window.getSelection) window.getSelection().removeAllRanges(); // clear selection
+ // event before
+ var eventData = this.trigger({ phase: 'before', type: 'resize', target: this.name });
+ if (eventData.isCancelled === true) return false;
+ // default action
+ $(this.box).css('overflow', 'hidden'); // container should have no overflow
+ //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'hidden');
+ $(this.box).find('> div').css({
+ width : $(this.box).width() + 'px',
+ height : $(this.box).height() + 'px'
+ });
+ //$(this.box).find('.w2ui-sidebar-div').css('overflow', 'auto');
+ // event after
+ 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;
+ // clean up
+ if ($(this.box).find('> div > div.w2ui-sidebar-div').length > 0) {
+ $(this.box)
+ .removeAttr('name')
+ .removeClass('w2ui-reset w2ui-sidebar')
+ .html('');
+ }
+ delete w2ui[this.name];
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ lock: function (msg, showSpinner) {
+ var box = $(this.box).find('> div:first-child');
+ w2utils.lock(box, msg, showSpinner);
+ },
+
+ unlock: function () {
+ w2utils.unlock(this.box);
+ }
+ }
+
+ $.extend(w2sidebar.prototype, w2utils.event);
+ w2obj.sidebar = w2sidebar;
+})(jQuery);
+
+/************************************************************************
+ * Library: Web 2.0 UI for jQuery (using prototypical inheritance)
+ * - Following objects defined
+ * - w2field - various field controls
+ * - $().w2field - jQuery wrapper
+ * - Dependencies: jQuery, w2utils
+ *
+ * == NICE TO HAVE ==
+ * - select - for select, list - for drop down (needs this in grid)
+ * - enum add events: onLoad, onRequest, onCompare, onSelect, onDelete, onClick for already selected elements
+ * - upload (regular files)
+ * - enum - refresh happens on each key press even if not needed (for speed)
+ * - BUG with prefix/postfix and arrows (test in different contexts)
+ * - multiple date selection
+ * - rewrire everythin in objects (w2ftext, w2fenum, w2fdate)
+ * - render calendar to the div
+ *
+ ************************************************************************/
+
+(function ($) {
+
+ /* SINGELTON PATTERN */
+
+ var w2field = new (function () {
+ this.customTypes = [];
+ });
+
+ // ====================================================
+ // -- Registers as a jQuery plugin
+
+ $.fn.w2field = function(method) {
+ // Method calling logic
+ if (w2field[method]) {
+ return w2field[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
+ } else if ( typeof method === 'object') {
+ return w2field.init.apply( this, arguments );
+ } else if ( typeof method === 'string') {
+ return w2field.init.apply( this, [{ type: method }] );
+ } else {
+ console.log('ERROR: Method ' + method + ' does not exist on jQuery.w2field');
+ }
+ };
+
+ $.extend(w2field, {
+ // CONTEXT: this - is jQuery object
+ init: function (options) {
+ var obj = w2field;
+ return $(this).each(function (field, index) {
+ // Check for Custom Types
+ if (typeof w2field.customTypes[options.type.toLowerCase()] == 'function') {
+ w2field.customTypes[options.type.toLowerCase()].call(this, options);
+ return;
+ }
+ // Common Types
+ var tp = options.type.toLowerCase();
+ switch (tp) {
+
+ case 'clear': // removes any previous field type
+ $(this)
+ .off('focus')
+ .off('blur')
+ .off('keypress')
+ .off('keydown')
+ .off('change')
+ .removeData(); // removes all attached data
+ if ($(this).prev().hasClass('w2ui-list')) { // if enum
+ $(this).prev().remove();
+ $(this).removeAttr('tabindex').css('border-color', '').show();
+ }
+ if ($(this).prev().hasClass('w2ui-upload')) { // if upload
+ $(this).prev().remove();
+ $(this).removeAttr('tabindex').css('border-color', '').show();
+ }
+ if ($(this).prev().hasClass('w2ui-field-helper')) { // helpers
+ $(this).css('padding-left', $(this).css('padding-top'));
+ $(this).prev().remove();
+ }
+ if ($(this).next().hasClass('w2ui-field-helper')) { // helpers
+ $(this).css('padding-right', $(this).css('padding-top'));
+ $(this).next().remove();
+ }
+ if ($(this).next().hasClass('w2ui-field-helper')) { // helpers
+ $(this).next().remove();
+ }
+ break;
+
+ case 'text':
+ case 'int':
+ case 'float':
+ case 'money':
+ case 'alphanumeric':
+ case 'hex':
+ var el = this;
+ var defaults = {
+ min : null,
+ max : null,
+ arrows : false,
+ keyboard: true,
+ suffix : '',
+ prefix : ''
+ }
+ options = $.extend({}, defaults, options);
+ if (['text', 'alphanumeric', 'hex'].indexOf(tp) != -1) {
+ options.arrows = false;
+ options.keyboard = false;
+ }
+ // init events
+ $(this)
+ .data('options', options)
+ .on('keypress', function (event) { // keyCode & charCode differ in FireFox
+ if (event.metaKey || event.ctrlKey || event.altKey || (event.charCode != event.keyCode && event.keyCode > 0)) return;
+ if (event.keyCode == 13) $(this).change();
+ var ch = String.fromCharCode(event.charCode);
+ if (!checkType(ch, true)) {
+ if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;
+ return false;
+ }
+ })
+ .on('keydown', function (event, extra) {
+ if (!options.keyboard) return;
+ var cancel = false;
+ var v = $(el).val();
+ if (!checkType(v)) v = options.min || 0; else v = parseFloat(v);
+ var key = event.keyCode || extra.keyCode;
+ var inc = 1;
+ if (event.ctrlKey || event.metaKey) inc = 10;
+ switch (key) {
+ case 38: // up
+ $(el).val((v + inc <= options.max || options.max == null ? v + inc : options.max)).change();
+ if (tp == 'money') $(el).val( Number($(el).val()).toFixed(2) );
+ cancel = true;
+ break;
+ case 40: // down
+ $(el).val((v - inc >= options.min || options.min == null ? v - inc : options.min)).change();
+ if (tp == 'money') $(el).val( Number($(el).val()).toFixed(2) );
+ cancel = true;
+ break;
+ }
+ if (cancel) {
+ event.preventDefault();
+ // set cursor to the end
+ setTimeout(function () { el.setSelectionRange(el.value.length, el.value.length); }, 0);
+ }
+ })
+ .on('change', function (event) {
+ // check max/min
+ var v = $(el).val();
+ var cancel = false;
+ if (options.min != null && v != '' && v < options.min) { $(el).val(options.min).change(); cancel = true; }
+ if (options.max != null && v != '' && v > options.max) { $(el).val(options.max).change(); cancel = true; }
+ if (cancel) {
+ event.stopPropagation();
+ event.preventDefault();
+ return false;
+ }
+ // check validity
+ if (this.value != '' && !checkType(this.value)) $(this).val(options.min != null ? options.min : '');
+ });
+ if ($(this).val() == '' && options.min != null) $(this).val(options.min);
+ if (options.prefix != '') {
+ $(this).before(
+ '
'+
+ options.prefix +
+ '
');
+ var helper = $(this).prev();
+ 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' : $(this).css('padding-left'),
+ 'padding-right' : 0,
+ 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px',
+ 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px',
+ 'margin-left' : 0,
+ 'margin-right' : 0
+ })
+ .on('click', function () {
+ $(this).next().focus();
+ });
+ $(this).css('padding-left', (helper.width() + parseInt($(this).css('padding-left')) + 5) + 'px');
+ }
+ var pr = parseInt($(this).css('padding-right'));
+ if (options.arrows != '') {
+ $(this).after(
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
');
+ var height = w2utils.getSize(this, 'height');
+ var helper = $(this).next();
+ helper
+ .css({
+ 'color' : $(this).css('color'),
+ 'font-family' : $(this).css('font-family'),
+ 'font-size' : $(this).css('font-size'),
+ 'height' : ($(this).height() + parseInt($(this).css('padding-top')) + parseInt($(this).css('padding-bottom')) ) + 'px',
+ 'padding' : '0px',
+ 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px',
+ 'margin-bottom' : '0px',
+ 'border-left' : '1px solid silver'
+ })
+ .css('margin-left', '-'+ (helper.width() + parseInt($(this).css('margin-right')) + 12) + 'px')
+ .on('mousedown', function (event) {
+ var btn = this;
+ var evt = event;
+ $('body').on('mouseup', tmp);
+ $('body').data('_field_update_timer', setTimeout(update, 700));
+ update(false);
+ // timer function
+ function tmp() {
+ clearTimeout($('body').data('_field_update_timer'));
+ $('body').off('mouseup', tmp);
+ }
+ // update function
+ function update(notimer) {
+ $(el).focus().trigger($.Event("keydown"), {
+ keyCode : ($(evt.target).attr('type') == 'up' ? 38 : 40)
+ });
+ if (notimer !== false) $('body').data('_field_update_timer', setTimeout(update, 60));
+ };
+ });
+ pr += helper.width() + 12;
+ $(this).css('padding-right', pr + 'px');
+ }
+ if (options.suffix != '') {
+ $(this).after(
+ '
'+
+ options.suffix +
+ '
');
+ 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')) + 5) + 'px');
+ pr += helper.width() + 3;
+ $(this).css('padding-right', pr + 'px');
+ }
+
+ function checkType(ch, loose) {
+ switch (tp) {
+ case 'int':
+ if (loose && ['-'].indexOf(ch) != -1) return true;
+ return w2utils.isInt(ch);
+ break;
+ case 'float':
+ if (loose && ['-','.'].indexOf(ch) != -1) return true;
+ return w2utils.isFloat(ch);
+ break;
+ case 'money':
+ if (loose && ['-','.','$','€','£','¥'].indexOf(ch) != -1) return true;
+ return w2utils.isMoney(ch);
+ break;
+ case 'hex':
+ return w2utils.isHex(ch);
+ break;
+ case 'alphanumeric':
+ return w2utils.isAlphaNumeric(ch);
+ break;
+ }
+ return true;
+ }
+ break;
+
+ case 'date':
+ var obj = this;
+ var defaults = {
+ format : w2utils.settings.date_format, // date format
+ start : '', // start of selectable range
+ end : '', // end of selectable range
+ blocked : {}, // {'4/11/2011': 'yes'}
+ colored : {} // {'4/11/2011': 'red:white'}
+ }
+ options = $.extend({}, defaults, options);
+ // -- insert div for calendar
+ $(this) // remove transtion needed for functionality
+ .css( { 'transition': 'none', '-webkit-transition': 'none', '-moz-transition': 'none', '-ms-transition': 'none', '-o-transition': 'none' })
+ .data("options", options)
+ .on('focus', function () {
+ var top = parseFloat($(obj).offset().top) + parseFloat(obj.offsetHeight);
+ var left = parseFloat($(obj).offset().left);
+ clearInterval($(obj).data('mtimer'));
+ $('#global_calendar_div').remove();
+ $('body').append('
'+
+ '
');
+ $('#global_calendar_div')
+ .html($().w2field('calendar_get', obj.value, options))
+ .css({
+ left: left + 'px',
+ top: top + 'px'
+ })
+ .data('el', obj)
+ .show();
+ var max = $(window).width() + $(document).scrollLeft() - 1;
+ if (left + $('#global_calendar_div').width() > max) {
+ $('#global_calendar_div').css('left', (max - $('#global_calendar_div').width()) + 'px');
+ }
+ // monitors
+ var mtimer = setInterval(function () {
+ var max = $(window).width() + $(document).scrollLeft() - 1;
+ var left = $(obj).offset().left;
+ if (left + $('#global_calendar_div').width() > max) left = max - $('#global_calendar_div').width();
+ // monitor if moved
+ if ($('#global_calendar_div').data('position') != ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) {
+ $('#global_calendar_div').css({
+ '-webkit-transition': '.2s',
+ left: left + 'px',
+ top : ($(obj).offset().top + obj.offsetHeight) + 'px'
+ }).data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight));
+ }
+ // monitor if destroyed
+ if ($(obj).length == 0 || ($(obj).offset().left == 0 && $(obj).offset().top == 0)) {
+ clearInterval(mtimer);
+ $('#global_calendar_div').remove();
+ return;
+ }
+ }, 100);
+ $(obj).data('mtimer', mtimer);
+ })
+ .on('blur', function (event) {
+ // trim empty spaces
+ $(obj).val($.trim($(obj).val()));
+ // check if date is valid
+ if ($.trim($(obj).val()) != '' && !w2utils.isDate($(obj).val(), options.format)) {
+ $(this).w2tag(w2utils.lang('Not a valid date') + ': '+ options.format);
+ }
+ clearInterval($(obj).data('mtimer'));
+ $('#global_calendar_div').remove();
+ })
+ .on('keypress', function (event) {
+ var obj = this;
+ setTimeout(function () {
+ $('#global_calendar_div').html( $().w2field('calendar_get', obj.value, options) );
+ }, 10);
+ });
+ setTimeout(function () {
+ // if it is unix time - convert to readable date
+ if (w2utils.isInt(obj.value)) obj.value = w2utils.formatDate(obj.value, options.format);
+ }, 1);
+ break;
+
+ case 'time':
+ break;
+
+ case 'datetime':
+ break;
+
+ case 'color':
+ var obj = this;
+ var defaults = {
+ prefix : '#',
+ suffix : '
'
+ }
+ options = $.extend({}, defaults, options);
+ // -- insert div for color
+ $(this)
+ .attr('maxlength', 6)
+ .on('focus', function () {
+ var top = parseFloat($(obj).offset().top) + parseFloat(obj.offsetHeight);
+ var left = parseFloat($(obj).offset().left);
+ clearInterval($(obj).data('mtimer'));
+ $('#global_color_div').remove();
+ $('body').append('
'+
+ '
');
+ $('#global_color_div')
+ .html($().w2field('getColorHTML', obj.value))
+ .css({
+ left: left + 'px',
+ top: top + 'px'
+ })
+ .data('el', obj)
+ .show();
+ var max = $(window).width() + $(document).scrollLeft() - 1;
+ if (left + $('#global_color_div').width() > max) {
+ $('#global_color_div').css('left', (max - $('#global_color_div').width()) + 'px');
+ }
+ // monitors
+ var mtimer = setInterval(function () {
+ var max = $(window).width() + $(document).scrollLeft() - 1;
+ var left = $(obj).offset().left;
+ if (left + $('#global_color_div').width() > max) left = max - $('#global_color_div').width();
+ // monitor if moved
+ if ($('#global_color_div').data('position') != ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight)) {
+ $('#global_color_div').css({
+ '-webkit-transition': '.2s',
+ left: left + 'px',
+ top : ($(obj).offset().top + obj.offsetHeight) + 'px'
+ }).data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight));
+ }
+ // monitor if destroyed
+ if ($(obj).length == 0 || ($(obj).offset().left == 0 && $(obj).offset().top == 0)) {
+ clearInterval(mtimer);
+ $('#global_color_div').remove();
+ return;
+ }
+ }, 100);
+ $(obj).data('mtimer', mtimer);
+ })
+ .on('click', function () {
+ $(this).trigger('focus');
+ })
+ .on('blur', function (event) {
+ // trim empty spaces
+ $(obj).val($.trim($(obj).val()));
+ clearInterval($(obj).data('mtimer'));
+ $('#global_color_div').remove();
+ })
+ .on('keydown', function (event) { // need this for cut/paster
+ if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) {
+ var obj = this;
+ $(this).prop('maxlength', 7);
+ setTimeout(function () {
+ var val = $(obj).val();
+ if (val.substr(0, 1) == '#') val = val.substr(1);
+ if (!w2utils.isHex(val)) val = '';
+ $(obj).val(val).prop('maxlength', 6).change();
+ }, 20);
+ }
+ })
+ .on('keyup', function (event) {
+ if (event.keyCode == 86 && (event.ctrlKey || event.metaKey)) $(this).prop('maxlength', 6);
+ })
+ .on('keypress', function (event) { // keyCode & charCode differ in FireFox
+ if (event.keyCode == 13) $(this).change();
+ //if (event.ct)
+ var ch = String.fromCharCode(event.charCode);
+ if (!w2utils.isHex(ch, true)) {
+ if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;
+ return false;
+ }
+ })
+ .on('change', function (event) {
+ var color = '#' + $(this).val();
+ if ($(this).val().length != 6 && $(this).val().length != 3) color = '';
+ $(this).next().find('div').css('background-color', color);
+ });
+ if (options.prefix != '') {
+ $(this).before(
+ '
'+
+ options.prefix +
+ '
');
+ var helper = $(this).prev();
+ 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' : $(this).css('padding-left'),
+ 'padding-right' : 0,
+ 'margin-top' : (parseInt($(this).css('margin-top')) + 1) + 'px',
+ 'margin-bottom' : (parseInt($(this).css('margin-bottom')) + 1) + 'px',
+ 'margin-left' : 0,
+ 'margin-right' : 0
+ })
+ .on('click', function () {
+ $(this).next().focus();
+ });
+ $(this).css('padding-left', (helper.width() + parseInt($(this).css('padding-left')) + 2) + 'px');
+ }
+ if (options.suffix != '') {
+ $(this).after(
+ '
'+
+ options.suffix +
+ '
');
+ 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');
+ // set color to current
+ 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);
+ // define refresh method
+ obj.refresh = function () {
+ var settings = $(obj).data('settings');
+ var html = '';
+ var items = w2field.cleanItems(settings.items);
+ // build options
+ 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();
+ }
+ // pull from server
+ 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 { // refresh local
+ 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 : [], // preselected items
+ max : 0, // maximum number of items that can be selected 0 for unlim
+ maxHeight : 172, // max height for input control to grow
+ showAll : false, // if true then show selected item in drop down
+ match : 'begins with', // ['begins with', 'contains']
+ render : null, // render(item, selected)
+ maxCache : 500, // number items to cache
+ onShow : null, // when overlay is shown onShow(settings)
+ onHide : null, // when overlay is hidden onHide(settings)
+ onAdd : null, // onAdd(item, settings)
+ onRemove : null, // onRemove(index, settings)
+ onItemOver : null,
+ onItemOut : null,
+ onItemClick : null
+ }
+ var obj = this;
+ var settings = $.extend({}, defaults, options);
+
+ // normalize items and selected
+ 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'
+ });
+
+ // add item to selected
+ 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) {
+ // if max reached, replace last
+ 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');
+ // insert global div
+ if ($('#w2ui-global-items').length == 0) {
+ $('body').append('
');
+ } else {
+ // ignore second click
+ 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));
+
+ // show drop content
+ w2field.list_render.call(obj);
+
+ // monitors
+ var monitor = function () {
+ var div = $('#w2ui-global-items');
+ // monitor if destroyed
+ if ($(obj).length == 0 || ($(obj).offset().left == 0 && $(obj).offset().top == 0)) {
+ clearInterval($(obj).data('mtimer'));
+ hide();
+ return;
+ }
+ // monitor if moved
+ 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));
+ // if moved then resize
+ 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));
+ // onShow
+ 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();
+ // onShow
+ if (typeof settings.onHide == 'function') settings.onHide.call(this, settings);
+ }
+
+ // render controls with all items in it
+ this.refresh = function () {
+ var obj = this;
+ // remove all items
+ $($(this).data('div')).remove();
+ // rebuild it
+ 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 = '
';
+ $(this).before(html);
+
+ var div = $(this).prev()[0];
+ $(this).data('div', div);
+ // click on item
+ $(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) // click on item
+ .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;
+ });
+ // adjust height
+ obj.resize();
+ }
+ this.resize = function () {
+ var settings = $(this).data('settings');
+ var div = $(this).prev();
+ var cntHeight = $(div).find('>div').height(); //w2utils.getSize(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 = 1000;
+ $(this).height(cntHeight);
+ }
+ // init control
+ $(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;
+ }
+ // init defaults
+ var defaults = {
+ url : '', // not yet implemented
+ base64 : true, // if true max file size is 20mb (only tru for now)
+ hint : w2utils.lang('Attach files by dragging and dropping or Click to Select'),
+ max : 0, // max number of files, 0 - unlim
+ maxSize : 0, // max size of all files, 0 - unlim
+ maxFileSize : 0, // max size of a single file, 0 -unlim
+ onAdd : null,
+ onRemove : null,
+ onItemClick : null,
+ onItemDblClick : null,
+ onItemOver : null,
+ onItemOut : null,
+ onProgress : null, // not yet implemented
+ onComplete : null // not yet implemented
+ }
+ var obj = this;
+ var settings = $.extend({}, defaults, options);
+ if (settings.base64 === true) {
+ if (settings.maxSize == 0) settings.maxSize = 20 * 1024 * 1024; // 20mb
+ if (settings.maxFileSize == 0) settings.maxFileSize = 20 * 1024 * 1024; // 20mb
+ }
+ 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];
+ // add li element
+ var cnt = $(div).find('.file-list li').length;
+ $(div).find('> span:first-child').remove();
+ $(div).find('.file-list').append('
' +
+ '
' +
+ ' ' + file.name + '' +
+ ' - ' + w2utils.size(file.size) + ''+
+ '');
+ var li = $(div).find('.file-list #file-' + cnt);
+ var previewHTML = "";
+ if ((/image/i).test(file.type)) { // image
+ previewHTML = '
'+
+ '
'+
+ '
';
+ }
+ var td1 = 'style="padding: 3px; text-align: right; color: #777;"';
+ var td2 = 'style="padding: 3px"';
+ previewHTML += '
'+
+ '
'+
+ ' Name: | '+ file.name +' |
'+
+ ' Size: | '+ w2utils.size(file.size) +' |
'+
+ ' Type: | ' +
+ ' '+ file.type +''+
+ ' |
'+
+ ' Modified: | '+ w2utils.date(file.modified) +' |
'+
+ '
'+
+ '
';
+ 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]);
+ var html = '' +
+ ''+ $().w2field('calendar_month', (dt.getMonth() + 1), dt.getFullYear(), options) +' | '+
+ // ''+
+ '
';
+ return html;
+ },
+
+ calendar_next: function(month_year) {
+ var tmp = String(month_year).split('/');
+ var month = tmp[0];
+ var year = tmp[1];
+ if (parseInt(month) < 12) {
+ month = parseInt(month) + 1;
+ } else {
+ month = 1;
+ year = parseInt(year) + 1;
+ }
+ var options = $($('#global_calendar_div.w2ui-calendar').data('el')).data('options');
+ $('#global_calendar_div.w2ui-calendar').html( $().w2field('calendar_get', w2utils.formatDate(month+'/1/'+year, options.format), options) );
+ },
+
+ calendar_previous: function(month_year) {
+ var tmp = String(month_year).split('/');
+ var month = tmp[0];
+ var year = tmp[1];
+ if (parseInt(month) > 1) {
+ month = parseInt(month) - 1;
+ } else {
+ month = 12;
+ year = parseInt(year) - 1;
+ }
+ var options = $($('#global_calendar_div.w2ui-calendar').data('el')).data('options');
+ $('#global_calendar_div.w2ui-calendar').html( $().w2field('calendar_get', w2utils.formatDate(month+'/1/'+year, options.format), options) );
+ },
+
+ calendar_month: function(month, year, options) {
+ var td = new Date();
+ var months = w2utils.settings.fullmonths;
+ var days = w2utils.settings.fulldays;
+ var daysCount = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31'];
+ var today = (Number(td.getMonth())+1) + '/' + td.getDate() + '/' + (String(td.getYear()).length > 3 ? td.getYear() : td.getYear() + 1900);
+
+ year = Number(year);
+ month = Number(month);
+ if (year === null || year === '') year = String(td.getYear()).length > 3 ? td.getYear() : td.getYear() + 1900;
+ if (month === null || month === '') month = Number(td.getMonth())+1;
+ if (month > 12) { month = month - 12; year++; }
+ if (month < 1 || month == 0) { month = month + 12; year--; }
+ if (year/4 == Math.floor(year/4)) { daysCount[1] = '29'; } else { daysCount[1] = '28'; }
+ if (year == null) { year = td.getYear(); }
+ if (month == null) { month = td.getMonth()-1; }
+
+ // start with the required date
+ var td = new Date();
+ td.setDate(1);
+ td.setMonth(month-1);
+ td.setYear(year);
+ var weekDay = td.getDay();
+ var tabDays = w2utils.settings.shortdays;
+ var dayTitle = '';
+ for ( var i = 0, len = tabDays.length; i < len; i++) {
+ dayTitle += '' + tabDays[i] + ' | ';
+ }
+ var html =
+ ''+
+ '
<-
'+
+ '
->
'+
+ months[month-1] +', '+ year +
+ '
'+
+ ''+
+ ' ' + dayTitle + '
'+
+ ' ';
+
+ var day = 1;
+ for (var ci=1; ci<43; ci++) {
+ if (weekDay == 0 && ci == 1) {
+ for (var ti=0; ti<6; ti++) html += ' | ';
+ ci += 6;
+ } else {
+ if (ci < weekDay || day > daysCount[month-1]) {
+ html += ' | ';
+ if ((ci)%7 == 0) html += '
';
+ continue;
+ }
+ }
+ var dt = month + '/' + day + '/' + year;
+
+ var className = '';
+ if (ci % 7 == 6) className = 'w2ui-saturday';
+ if (ci % 7 == 0) className = 'w2ui-sunday';
+ if (dt == today) className += ' w2ui-today';
+
+ var dspDay = day;
+ var col = '';
+ var bgcol = '';
+ var blocked = '';
+ if (options.colored) if (options.colored[dt] != undefined) { // if there is predefined colors for dates
+ tmp = options.colored[dt].split(':');
+ bgcol = 'background-color: ' + tmp[0] + ';';
+ col = 'color: ' + tmp[1] + ';';
+ }
+ var noSelect = false;
+ // enable range
+ if (options.start || options.end) {
+ var start = new Date(options.start);
+ var end = new Date(options.end);
+ var current = new Date(dt);
+ if (current < start || current > end) {
+ blocked = ' w2ui-blocked-date';
+ noSelect = true;
+ }
+ }
+ // block predefined dates
+ if (options.blocked && $.inArray(dt, options.blocked) != -1) {
+ blocked = ' w2ui-blocked-date';
+ noSelect = true;
+ }
+ html += ''+ dspDay + ' | ';
+ if (ci % 7 == 0 || (weekDay == 0 && ci == 1)) html += '
';
+ day++;
+ }
+ html += '
';
+ return html;
+ },
+
+ getColorHTML: function (color) {
+ var html = ''+
+ '
';
+ var colors = [
+ ['000000', '444444', '666666', '999999', 'CCCCCC', 'EEEEEE', 'F3F3F3', 'FFFFFF'],
+ ['FF011B', 'FF9838', 'FFFD59', '01FD55', '00FFFE', '0424F3', '9B24F4', 'FF21F5'],
+ ['F4CCCC', 'FCE5CD', 'FFF2CC', 'D9EAD3', 'D0E0E3', 'CFE2F3', 'D9D1E9', 'EAD1DC'],
+ ['EA9899', 'F9CB9C', 'FEE599', 'B6D7A8', 'A2C4C9', '9FC5E8', 'B4A7D6', 'D5A6BD'],
+ ['E06666', 'F6B26B', 'FED966', '93C47D', '76A5AF', '6FA8DC', '8E7CC3', 'C27BA0'],
+ ['CC0814', 'E69138', 'F1C232', '6AA84F', '45818E', '3D85C6', '674EA7', 'A54D79'],
+ ['99050C', 'B45F17', 'BF901F', '37761D', '124F5C', '0A5394', '351C75', '741B47'],
+ ['660205', '783F0B', '7F6011', '274E12', '0C343D', '063762', '20124D', '4C1030']
+ ];
+ for (var i=0; i<8; i++) {
+ html += '';
+ for (var j=0; j<8; j++) {
+ html += ''+
+ ' '+
+ ' '+ (color == colors[i][j] ? '' : ' ')+
+ ' '+
+ ' | ';
+ }
+ html += '
';
+ if (i < 2) html += ' |
';
+ }
+ html += '
';
+ return html;
+ }
+ });
+
+ w2obj.field = w2field;
+
+}) (jQuery);
+
+/************************************************************************
+ * Library: Web 2.0 UI for jQuery (using prototypical inheritance)
+ * - Following objects defined
+ * - w2form - form widget
+ * - $().w2form - jQuery wrapper
+ * - Dependencies: jQuery, w2utils, w2fields, w2tabs, w2toolbar, w2alert
+ *
+ * == NICE TO HAVE ==
+ * - refresh(field) - would refresh only one field
+ * - include delta on save
+ *
+ ************************************************************************/
+
+
+(function ($) {
+ var w2form = function(options) {
+ // public properties
+ this.name = null;
+ this.header = '';
+ this.box = null; // HTML element that hold this element
+ this.url = '';
+ this.formURL = ''; // url where to get form HTML
+ this.formHTML = ''; // form HTML (might be loaded from the url)
+ this.page = 0; // current page
+ this.recid = 0; // can be null or 0
+ this.fields = [];
+ this.actions = {};
+ this.record = {};
+ this.original = {};
+ this.postData = {};
+ this.toolbar = {}; // if not empty, then it is toolbar
+ this.tabs = {}; // if not empty, then it is tabs object
+
+ this.style = '';
+ this.focus = 0; // focus first or other element
+ this.msgNotJSON = w2utils.lang('Return data is not in JSON format.');
+ this.msgRefresh = w2utils.lang('Refreshing...');
+ this.msgSaving = w2utils.lang('Saving...');
+
+ // events
+ 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;
+
+ // internal
+ this.isGenerated = false;
+ this.last = {
+ xhr : null // jquery xhr requests
+ }
+
+ $.extend(true, this, w2obj.form, options);
+ };
+
+ // ====================================================
+ // -- Registers as a jQuery plugin
+
+ $.fn.w2form = function(method) {
+ if (typeof method === 'object' || !method ) {
+ var obj = this;
+ // check required parameters
+ 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;
+ }
+ // remember items
+ var record = method.record;
+ var original = method.original;
+ var fields = method.fields;
+ var toolbar = method.toolbar;
+ var tabs = method.tabs;
+ // extend items
+ 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);
+ // reassign variables
+ 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];
+ // render if necessary
+ 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 != '') {
+ // it is already loaded into formHTML
+ } else if ($(this).length != 0 && $.trim($(this).html()) != '') {
+ object.formHTML = $(this).html();
+ } else { // try to generate it
+ object.formHTML = object.generateHTML();
+ }
+ // register new object
+ w2ui[object.name] = object;
+ // render if not loaded from url
+ 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');
+ }
+ }
+
+ // ====================================================
+ // -- Implementation of core functionality
+
+ 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.clear();
+ this.request(callBack);
+ } else {
+ this.refresh();
+ if (typeof callBack == 'function') callBack();
+ }
+ },
+
+ clear: function () {
+ this.recid = 0;
+ this.record = {};
+ // clear all enum fields
+ for (var f in this.fields) {
+ var field = this.fields[f];
+ }
+ $().w2tag();
+ this.refresh();
+ },
+
+ error: function (msg) {
+ var obj = this;
+ // let the management of the error outside of the grid
+ 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;
+ }
+ // need a time out because message might be already up)
+ setTimeout(function () { w2alert(msg, 'Error'); }, 1);
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ validate: function (showErrors) {
+ if (typeof showErrors == 'undefined') showErrors = true;
+ // validate before saving
+ 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 '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':
+ // convert true/false
+ if (this.record[field.name] == true) this.record[field.name] = 1; else this.record[field.name] = 0;
+ break;
+ case 'date':
+ // format date before submit
+ 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 {
+ // convert to universal timestamp with time zone
+ //var d = new Date(this.record[field.name]);
+ //var tz = (d.getTimezoneOffset() > 0 ? '+' : '-') + Math.floor(d.getTimezoneOffset()/60) + ':' + (d.getTimezoneOffset() % 60);
+ //this.record[field.name] = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate() + ' '
+ // + d.getHours() + ':' + d.getSeconds() + ':' + d.getMilliseconds() + tz;
+ //this.record[field.name + '_unix'] = Math.round(d.getTime() / 1000);
+ //this.record[field.name] = w2utils.formatDate(this.record[field.name], 'mm/dd/yyyy');
+ }
+ break;
+ case 'select':
+ case 'list':
+ break;
+ case 'enum':
+ break;
+ }
+ // === check required - if field is '0' it should be considered not empty
+ 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 });
+ }
+ }
+ // event before
+ var eventData = this.trigger({ phase: 'before', target: this.name, type: 'validate', errors: errors });
+ if (eventData.isCancelled === true) return errors;
+ // show error
+ if (showErrors) for (var e in eventData.errors) {
+ var err = eventData.errors[e];
+ $(err.field.el).w2tag(err.error, { "class": 'w2ui-error' });
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ return errors;
+ },
+
+ request: function (postData, callBack) { // if (1) param then it is call back if (2) then postData and callBack
+ var obj = this;
+ // check for multiple params
+ 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;
+ // build parameters list
+ var params = {};
+ // add list params
+ params['cmd'] = 'get-record';
+ params['name'] = this.name;
+ params['recid'] = this.recid;
+ // append other params
+ $.extend(params, this.postData);
+ $.extend(params, postData);
+ // event before
+ 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; }
+ // default action
+ this.record = {};
+ this.original = {};
+ // call server to get data
+ 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();
+ // event before
+ 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;
+ }
+ // parse server response
+ var responseText = obj.last.xhr.responseText;
+ if (status != 'error') {
+ // default action
+ if (typeof responseText != 'undefined' && responseText != '') {
+ var data;
+ // check if the onLoad handler has not already parsed the data
+ if (typeof responseText == "object") {
+ data = responseText;
+ } else {
+ // $.parseJSON or $.getJSON did not work because it expect perfect JSON data - where everything is in double quotes
+ 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);
+ }
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ obj.refresh();
+ // call back
+ if (typeof callBack == 'function') callBack(data);
+ }
+ });
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ submit: function (postData, callBack) {
+ return this.save(postData, callBack);
+ },
+
+ save: function (postData, callBack) {
+ var obj = this;
+ // check for multiple params
+ if (typeof postData == 'function') {
+ callBack = postData;
+ postData = null;
+ }
+ // validation
+ var errors = obj.validate(true);
+ if (errors.length !== 0) {
+ obj.goto(errors[0].field.page);
+ return;
+ }
+ // submit save
+ 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 + ' ');
+ // need timer to allow to lock
+ setTimeout(function () {
+ // build parameters list
+ var params = {};
+ // add list params
+ params['cmd'] = 'save-record';
+ params['name'] = obj.name;
+ params['recid'] = obj.recid;
+ // append other params
+ $.extend(params, obj.postData);
+ $.extend(params, postData);
+ params.record = $.extend(true, {}, obj.record);
+ // convert before submitting
+ for (var f in obj.fields) {
+ var field = obj.fields[f];
+ switch (String(field.type).toLowerCase()) {
+ case 'date': // to yyyy-mm-dd format
+ var dt = params.record[field.name];
+ if (field.options.format.toLowerCase() == 'dd/mm/yyyy' || field.options.format.toLowerCase() == 'dd-mm-yyyy'
+ || field.options.format.toLowerCase() == 'dd.mm.yyyy') {
+ var tmp = dt.replace(/-/g, '/').replace(/\./g, '/').split('/');
+ var dt = new Date(tmp[2] + '-' + tmp[1] + '-' + tmp[0]);
+ }
+ params.record[field.name] = w2utils.formatDate(dt, 'yyyy-mm-dd');
+ break;
+ }
+ }
+ // event before
+ 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;
+ }
+ // default action
+ 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();
+ // upload
+ 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();
+
+ // event before
+ 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;
+ }
+ // parse server response
+ var responseText = xhr.responseText;
+ if (status != 'error') {
+ // default action
+ if (typeof responseText != 'undefined' && responseText != '') {
+ var data;
+ // check if the onLoad handler has not already parsed the data
+ if (typeof responseText == "object") {
+ data = responseText;
+ } else {
+ // $.parseJSON or $.getJSON did not work because it expect perfect JSON data - where everything is in double quotes
+ 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);
+ }
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ obj.refresh();
+ // call back
+ if (typeof callBack == 'function') callBack(data);
+ }
+ });
+ // event after
+ 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); // needed timer so if server fast, it will not flash
+ },
+
+ goto: function (page) {
+ if (typeof page != 'undefined') this.page = page;
+ // if it was auto size, resize it
+ if ($(this.box).data('auto-size') === true) $(this.box).height(0);
+ this.refresh();
+ },
+
+ generateHTML: function () {
+ var pages = []; // array for each page
+ 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 '+ field.html.caption +':
'+
+ '\n '+
+ input + field.html.text +
+ '
';
+ if (typeof pages[field.html.page] == 'undefined') pages[field.html.page] = '';
+ pages[field.html.page] += html;
+ }
+ for (var p in pages) pages[p] += '\n
';
+ // buttons if any
+ var buttons = '';
+ if (!$.isEmptyObject(this.actions)) {
+ buttons += '\n';
+ for (var a in this.actions) {
+ buttons += '\n ';
+ }
+ buttons += '\n
';
+ }
+ return pages.join('') + buttons;
+ },
+
+ action: function (action, event) {
+ // event before
+ var eventData = this.trigger({ phase: 'before', target: action, type: 'action', originalEvent: event });
+ if (eventData.isCancelled === true) return false;
+ // default actions
+ if (typeof (this.actions[action]) == 'function') {
+ this.actions[action].call(this, event);
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ },
+
+ resize: function () {
+ var obj = this;
+ // event before
+ var eventData = this.trigger({ phase: 'before', target: this.name, type: 'resize' });
+ if (eventData.isCancelled === true) return false;
+ // default behaviour
+ 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');
+ // if no height, calculate it
+ 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) + // why 12 ???
+ (buttons.length > 0 ? w2utils.getSize(buttons, 'height') : 0)
+ );
+ $(this.box).data('auto-size', true);
+ }
+ resizeElements();
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+
+ function resizeElements() {
+ // resize elements
+ 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;
+ // update what page field belongs
+ $(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) {
+ // find page
+ 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; }
+ }
+ }
+ }
+ });
+ // event before
+ var eventData = this.trigger({ phase: 'before', target: this.name, type: 'refresh', page: this.page })
+ if (eventData.isCancelled === true) return false;
+ // default action
+ $(this.box).find('.w2ui-page').hide();
+ $(this.box).find('.w2ui-page.page-' + this.page).show();
+ $(this.box).find('.w2ui-form-header').html(this.header);
+ // refresh tabs if needed
+ 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();
+ }
+ // refresh tabs if needed
+ if (typeof this.toolbar == 'object' && this.toolbar.items.length > 0) {
+ $('#form_'+ this.name +'_toolbar').show();
+ this.toolbar.refresh();
+ } else {
+ $('#form_'+ this.name +'_toolbar').hide();
+ }
+ // refresh values of all fields
+ 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.');
+ //return;
+ }
+ if (field.el) field.el.id = field.name;
+ $(field.el).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]); // clone array
+ if ($.isArray(cur_arr)) for (var i in cur_arr) value_previous[i] = $.extend(true, {}, cur_arr[i]); // clone array
+ }
+ // event before
+ 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 previous value
+ return false;
+ }
+ // default action
+ 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;
+ // event after
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ });
+ if (field.required) {
+ $(field.el).parent().addClass('w2ui-required');
+ } else {
+ $(field.el).parent().removeClass('w2ui-required');
+ }
+ }
+ // attach actions on buttons
+ $(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);
+ });
+ });
+ // init controls with record
+ 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':
+ // hide passwords
+ 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;
+ }
+ // normalize value
+ 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;
+ default:
+ console.log('ERROR: field type "'+ field.type +'" is not recognized.');
+ break;
+ }
+ }
+ // wrap pages in div
+ var tmp = $(this.box).find('.w2ui-page');
+ for (var i = 0; i < tmp.length; i++) {
+ if ($(tmp[i]).find('> *').length > 1) $(tmp[i]).wrapInner('');
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ this.resize();
+ },
+
+ render: function (box) {
+ var obj = this;
+ if (typeof box == 'object') {
+ // remove from previous box
+ 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;
+ // event before
+ var eventData = this.trigger({ phase: 'before', target: this.name, type: 'render', box: (typeof box != 'undefined' ? box : this.box) });
+ if (eventData.isCancelled === true) return false;
+ // default actions
+ var html = '' +
+ (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;
+
+ // init toolbar regardless it is defined or not
+ 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;
+ // no default action
+ obj.trigger($.extend(eventData, { phase: 'after' }));
+ });
+ }
+ if (typeof this.toolbar == 'object' && typeof this.toolbar.render == 'function') {
+ this.toolbar.render($('#form_'+ this.name +'_toolbar')[0]);
+ }
+ // init tabs regardless it is defined or not
+ 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]);
+ }
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ // after render actions
+ this.resize();
+ var url = (typeof this.url != 'object' ? this.url : this.url.get);
+ if (url && this.recid != 0) {
+ this.request();
+ } else {
+ this.refresh();
+ }
+ // attach to resize event
+ if ($('.w2ui-layout').length == 0) { // if there is layout, it will send a resize event
+ 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); // need timer because resize is on timer
+ // focus on load
+ 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); // need timeout to allow form to render
+ },
+
+ destroy: function () {
+ // event before
+ var eventData = this.trigger({ phase: 'before', target: this.name, type: 'destroy' });
+ if (eventData.isCancelled === true) return false;
+ // clean up
+ 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];
+ // event after
+ this.trigger($.extend(eventData, { phase: 'after' }));
+ $(window).off('resize', 'body')
+ }
+ }
+
+ $.extend(w2form.prototype, w2utils.event);
+ w2obj.form = w2form;
+})(jQuery);
diff --git a/js/w2ui.min.js b/js/w2ui.min.js
new file mode 100644
index 0000000..2135cb1
--- /dev/null
+++ b/js/w2ui.min.js
@@ -0,0 +1 @@
+var w2ui=w2ui||{},w2obj=w2obj||{},w2utils=function(n){function nt(n){var t=/^[-]?[0-9]+$/;return t.test(n)}function tt(n){var t=new RegExp(w2utils.settings.float);return t.test(n)}function d(n){var t=new RegExp(w2utils.settings.currency);return t.test(n)}function w(n){var t=/^[a-fA-F0-9]+$/;return t.test(n)}function b(n){var t=/^[a-zA-Z0-9_-]+$/;return t.test(n)}function k(n){var t=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;return t.test(n)}function et(n,t,i){if(!n)return!1;t||(t=w2utils.settings.date_format);var r=n.replace(/-/g,"/").replace(/\./g,"/").toLowerCase().split("/"),o=t.replace(/-/g,"/").replace(/\./g,"/").toLowerCase(),s="Invalid Date",u,f,e;return(o=="mm/dd/yyyy"&&(u=r[0],f=r[1],e=r[2]),o=="m/d/yyyy"&&(u=r[0],f=r[1],e=r[2]),o=="dd/mm/yyyy"&&(u=r[1],f=r[0],e=r[2]),o=="d/m/yyyy"&&(u=r[1],f=r[0],e=r[2]),o=="yyyy/dd/mm"&&(u=r[2],f=r[1],e=r[0]),o=="yyyy/d/m"&&(u=r[2],f=r[1],e=r[0]),o=="yyyy/mm/dd"&&(u=r[1],f=r[2],e=r[0]),o=="yyyy/m/d"&&(u=r[1],f=r[2],e=r[0]),s=new Date(u+"/"+f+"/"+e),typeof u=="undefined")?!1:s=="Invalid Date"?!1:s.getMonth()+1!=u||s.getDate()!=f||s.getFullYear()!=e?!1:i===!0?s:!0}function ot(t){var r,i;return String(t)=="undefined"?!1:(t=t.toUpperCase(),r=t.indexOf("PM")>=0||t.indexOf("AM")>=0?12:23,t=n.trim(t.replace("AM","")),t=n.trim(t.replace("PM","")),i=t.split(":"),i.length!=2)?!1:i[0]==""||parseInt(i[0])<0||parseInt(i[0])>r||!this.isInt(i[0])?!1:i[1]==""||parseInt(i[1])<0||parseInt(i[1])>59||!this.isInt(i[1])?!1:!0}function st(n){var f,i;if(n==""||typeof n=="undefined"||n==null||(w2utils.isInt(n)&&(n=Number(n)),f=new Date(n),w2utils.isInt(n)&&(f=new Date(Number(n))),i=String(n).split("-"),i.length==3&&(f=new Date(i[0],Number(i[1])-1,i[2])),i=String(n).split("/"),i.length==3&&(f=new Date(i[2],Number(i[0])-1,i[1])),f=="Invalid Time"))return"";var e=new Date,t=(e.getTime()-f.getTime())/1e3,r="",u="";return t<60?(r=Math.floor(t),u="sec",t<0&&(r=0,u="sec")):t<3600?(r=Math.floor(t/60),u="min"):t<86400?(r=Math.floor(t/3600),u="hour"):t<2592e3?(r=Math.floor(t/86400),u="day"):t<31104e3?(r=Math.floor(t/259200)/10,u="month"):t>=31104e3&&(r=Math.floor(t/3110400)/10,u="year"),r+" "+u+(r>1?"s":"")}function ft(n){var o=w2utils.settings.shortmonths,t,i,f,r;if(n==""||typeof n=="undefined"||n==null||(w2utils.isInt(n)&&(n=Number(n)),t=new Date(n),w2utils.isInt(n)&&(t=new Date(Number(n))),i=String(n).split("-"),i.length==3&&(t=new Date(i[0],Number(i[1])-1,i[2])),i=String(n).split("/"),i.length==3&&(t=new Date(i[2],Number(i[0])-1,i[1])),t=="Invalid Date"))return"";f=new Date,r=new Date,r.setTime(r.getTime()-864e5);var u=o[t.getMonth()]+" "+t.getDate()+", "+t.getFullYear(),h=o[f.getMonth()]+" "+f.getDate()+", "+f.getFullYear(),c=o[r.getMonth()]+" "+r.getDate()+", "+r.getFullYear(),l=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+" "+(t.getHours()>=12?"pm":"am"),s=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+":"+(t.getSeconds()<10?"0":"")+t.getSeconds()+" "+(t.getHours()>=12?"pm":"am"),e=u;return u==h&&(e=l),u==c&&(e=w2utils.lang("Yesterday")),''+e+""}function it(n){if(!w2utils.isFloat(n)||n=="")return"";if(n=parseFloat(n),n==0)return 0;var i=["Bt","KB","MB","GB","TB"],t=parseInt(Math.floor(Math.log(n)/Math.log(1024)));return(Math.floor(n/Math.pow(1024,t)*10)/10).toFixed(t==0?0:1)+" "+i[t]}function rt(n){var t="";return(w2utils.isFloat(n)||w2utils.isInt(n)||w2utils.isMoney(n))&&(t=String(n).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1,")),t}function ut(n,t){var s=w2utils.settings.shortmonths,o=w2utils.settings.fullmonths,r,i;if((typeof t=="undefined"&&(t=this.settings.date_format),typeof n=="undefined"||n==""||n==null)||(r=new Date(n),w2utils.isInt(n)&&(r=new Date(Number(n))),i=String(n).split("-"),i.length==3&&(r=new Date(i[0],Number(i[1])-1,i[2])),i=String(n).split("/"),i.length==3&&(r=new Date(i[2],Number(i[0])-1,i[1])),r=="Invalid Date"))return"";var f=r.getFullYear(),u=r.getMonth(),e=r.getDate();return t.toLowerCase().replace("month",w2utils.settings.fullmonths[u]).replace("mon",w2utils.settings.shortmonths[u]).replace(/yyyy/g,f).replace(/yyy/g,f).replace(/yy/g,String(f).substr(2)).replace(/(^|[^a-z$])y/g,"$1"+f).replace(/mm/g,(u+1<10?"0":"")+(u+1)).replace(/dd/g,(e<10?"0":"")+e).replace(/(^|[^a-z$])m/g,"$1"+(u+1)).replace(/(^|[^a-z$])d/g,"$1"+e)}function e(n,t){var h=w2utils.settings.shortmonths,s=w2utils.settings.fullmonths,i;if((typeof t=="undefined"&&(t=this.settings.time_format),typeof n=="undefined"||n==""||n==null)||(i=new Date(n),w2utils.isInt(n)&&(i=new Date(Number(n))),i=="Invalid Date"))return"";var e="am",u=i.getHours(),o=i.getHours(),r=i.getMinutes(),f=i.getSeconds();return r<10&&(r="0"+r),f<10&&(f="0"+f),(t.indexOf("am")!=-1||t.indexOf("pm")!=-1)&&(u>=12&&(e="pm"),u>12&&(u=u-12)),t.toLowerCase().replace("am",e).replace("pm",e).replace("hh",u).replace("h24",o).replace("mm",r).replace("mi",r).replace("ss",f).replace(/(^|[^a-z$])h/g,"$1"+u).replace(/(^|[^a-z$])m/g,"$1"+r).replace(/(^|[^a-z$])s/g,"$1"+f)}function o(n,t){var i;return i=typeof t!="string"?[this.settings.date_format,this.settings.time_format]:t.split("|"),this.formatDate(n,i[0])+" "+this.formatTime(n,i[1])}function s(t){if(t==null)return t;switch(typeof t){case"string":t=n.trim(String(t).replace(/(<([^>]+)>)/ig,""));break;case"object":for(var i in t)t[i]=this.stripTags(t[i])}return t}function f(n){if(n==null)return n;switch(typeof n){case"string":n=String(n).replace(/&/g,"&").replace(/>/g,">").replace(/\|\/? {}\\])/g,"\\$1")}function r(n){function l(n){for(var n=String(n).replace(/\r\n/g,"\n"),i="",t,r=0;r127&&t<2048?(i+=String.fromCharCode(t>>6|192),i+=String.fromCharCode(t&63|128)):(i+=String.fromCharCode(t>>12|224),i+=String.fromCharCode(t>>6&63|128),i+=String.fromCharCode(t&63|128));return i}var e="",s,f,u,h,c,o,r,i=0,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=l(n);i>2,c=(s&3)<<4|f>>4,o=(f&15)<<2|u>>6,r=u&63,isNaN(f)?o=r=64:isNaN(u)&&(r=64),e=e+t.charAt(h)+t.charAt(c)+t.charAt(o)+t.charAt(r);return e}function u(n){function l(n){for(var u="",t=0,i=0,f=0,r=0;t191&&i<224?(r=n.charCodeAt(t+1),u+=String.fromCharCode((i&31)<<6|r&63),t+=2):(r=n.charCodeAt(t+1),c3=n.charCodeAt(t+2),u+=String.fromCharCode((i&15)<<12|(r&63)<<6|c3&63),t+=3);return u}var t="",s,o,c,h,f,r,e,i=0,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=n.replace(/[^A-Za-z0-9\+\/\=]/g,"");i>4,o=(f&15)<<4|r>>2,c=(r&3)<<6|e,t=t+String.fromCharCode(s),r!=64&&(t=t+String.fromCharCode(o)),e!=64&&(t=t+String.fromCharCode(c));return t=l(t)}function v(t,i,r,u){function f(n,t,i){var r=!!window.webkitURL;return r||typeof i=="undefined"||(t=i),";"+n+": "+t+"; -webkit-"+n+": "+t+"; -moz-"+n+": "+t+"; -ms-"+n+": "+t+"; -o-"+n+": "+t+";"}var o=n(t).width(),s=n(t).height(),e=.5;if(!t||!i){console.log("ERROR: Cannot do transition when one of the divs is null");return}t.parentNode.style.cssText+=f("perspective","700px")+"; overflow: hidden;",t.style.cssText+="; position: absolute; z-index: 1019; "+f("backface-visibility","hidden"),i.style.cssText+="; position: absolute; z-index: 1020; "+f("backface-visibility","hidden");switch(r){case"slide-left":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+=f("transition",e+"s")+";"+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)")},1);break;case"slide-right":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(-"+o+"px, 0, 0)","translate(-"+o+"px, 0)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0px, 0, 0)","translate(0px, 0)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d("+o+"px, 0, 0)","translate("+o+"px, 0)")},1);break;case"slide-down":t.style.cssText+="overflow: hidden; z-index: 1; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; z-index: 0; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)")},1);break;case"slide-up":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, "+s+"px, 0)","translate(0, "+s+"px)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")},1);break;case"flip-left":t.style.cssText+="overflow: hidden; "+f("-transform","rotateY(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateY(-180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(180deg)")},1);break;case"flip-right":t.style.cssText+="overflow: hidden; "+f("transform","rotateY(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateY(180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateY(-180deg)")},1);break;case"flip-down":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateX(180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(-180deg)")},1);break;case"flip-up":t.style.cssText+="overflow: hidden; "+f("transform","rotateX(0deg)"),i.style.cssText+="overflow: hidden; "+f("transform","rotateX(-180deg)"),n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(0deg)"),t.style.cssText+=f("transition",e+"s")+"; "+f("transform","rotateX(180deg)")},1);break;case"pop-in":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(.8)")+"; opacity: 0;",n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1)")+"; opacity: 1;",t.style.cssText+=f("transition",e+"s")+";"},1);break;case"pop-out":t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+f("transform","scale(1)")+"; opacity: 1;",i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;",n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;",t.style.cssText+=f("transition",e+"s")+"; "+f("transform","scale(1.7)")+"; opacity: 0;"},1);break;default:t.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)"),i.style.cssText+="overflow: hidden; "+f("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;",n(i).show(),window.setTimeout(function(){i.style.cssText+=f("transition",e+"s")+"; opacity: 1;",t.style.cssText+=f("transition",e+"s")},1)}setTimeout(function(){r=="slide-down"&&(n(t).css("z-index","1019"),n(i).css("z-index","1020")),i&&n(i).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""}),t&&(n(t).css({opacity:"1","-webkit-transition":"","-moz-transition":"","-ms-transition":"","-o-transition":"","-webkit-transform":"","-moz-transform":"","-ms-transform":"","-o-transform":"","-webkit-backface-visibility":"","-moz-backface-visibility":"","-ms-backface-visibility":"","-o-backface-visibility":""}),t.parentNode&&n(t.parentNode).css({"-webkit-perspective":"","-moz-perspective":"","-ms-perspective":"","-o-perspective":""})),typeof u=="function"&&u()},e*1e3)}function y(t,i,r){i||i==0||(i=""),w2utils.unlock(t),n(t).find(">:first-child").before(''),setTimeout(function(){var f=n(t).find(".w2ui-lock"),u=n(t).find(".w2ui-lock-msg");f.data("old_opacity",f.css("opacity")).css("opacity","0").show(),u.data("old_opacity",u.css("opacity")).css("opacity","0").show(),setTimeout(function(){var f=n(t).find(".w2ui-lock"),u=n(t).find(".w2ui-lock-msg"),o=(n(t).width()-w2utils.getSize(u,"width"))/2,e=(n(t).height()*.9-w2utils.getSize(u,"height"))/2;f.css({opacity:f.data("old_opacity"),left:"0px",top:"0px",width:"100%",height:"100%"}),i||u.css({"background-color":"transparent",border:"0px"}),r===!0&&(i='"+i),u.html(i).css({opacity:u.data("old_opacity"),left:o+"px",top:e+"px"})},10)},10),n().w2tag()}function p(t){n(t).find(".w2ui-lock").remove(),n(t).find(".w2ui-lock-msg").remove()}function a(t,i){var f={left:parseInt(n(t).css("border-left-width"))||0,right:parseInt(n(t).css("border-right-width"))||0,top:parseInt(n(t).css("border-top-width"))||0,bottom:parseInt(n(t).css("border-bottom-width"))||0},u={left:parseInt(n(t).css("margin-left"))||0,right:parseInt(n(t).css("margin-right"))||0,top:parseInt(n(t).css("margin-top"))||0,bottom:parseInt(n(t).css("margin-bottom"))||0},r={left:parseInt(n(t).css("padding-left"))||0,right:parseInt(n(t).css("padding-right"))||0,top:parseInt(n(t).css("padding-top"))||0,bottom:parseInt(n(t).css("padding-bottom"))||0};switch(i){case"top":return f.top+u.top+r.top;case"bottom":return f.bottom+u.bottom+r.bottom;case"left":return f.left+u.left+r.left;case"right":return f.right+u.right+r.right;case"width":return f.left+f.right+u.left+u.right+r.left+r.right+parseInt(n(t).width());case"height":return f.top+f.bottom+u.top+u.bottom+r.top+r.bottom+parseInt(n(t).height());case"+width":return f.left+f.right+u.left+u.right+r.left+r.right;case"+height":return f.top+f.bottom+u.top+u.bottom+r.top+r.bottom}return 0}function h(n){var t=this.settings.phrases[n];return typeof t=="undefined"?n:t}function c(t){t||(t="en-us"),t.length==5&&(t="locale/"+t+".json"),n.ajax({url:t,type:"GET",dataType:"JSON",async:!1,cache:!1,success:function(t){w2utils.settings=n.extend(!0,w2utils.settings,t)},error:function(){console.log("ERROR: Cannot load locale "+t)}})}function l(){if(t.scrollBarSize)return t.scrollBarSize;var i='';return n("body").append(i),t.scrollBarSize=100-n("#_scrollbar_width > div").width(),n("#_scrollbar_width").remove(),String(navigator.userAgent).indexOf("MSIE")>=0&&(t.scrollBarSize=t.scrollBarSize/2),t.scrollBarSize}var t={};return{settings:{locale:"en-us",date_format:"m/d/yyyy",date_display:"Mon d, yyyy",time_format:"hh:mi pm",currency:"^[$€£¥]?[-]?[0-9]*[.]?[0-9]+$",currencySymbol:"$",float:"^[-]?[0-9]*[.]?[0-9]+$",shortmonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],fullmonths:["January","February","March","April","May","June","July","August","September","October","November","December"],shortdays:["M","T","W","T","F","S","S"],fulldays:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],RESTfull:!1,phrases:{}},isInt:nt,isFloat:tt,isMoney:d,isHex:w,isAlphaNumeric:b,isEmail:k,isDate:et,isTime:ot,age:st,date:ft,size:it,formatNumber:rt,formatDate:ut,formatTime:e,formatDateTime:o,stripTags:s,encodeTags:f,escapeId:i,base64encode:r,base64decode:u,transition:v,lock:y,unlock:p,lang:h,locale:c,getSize:a,scrollBarSize:l}}(jQuery),w2popup,w2alert,w2confirm;w2utils.event={on:function(n,t){if(jQuery.isPlainObject(n)||(n={type:n}),n=jQuery.extend({type:null,execute:"before",target:null,onComplete:null},n),typeof n.type=="undefined"){console.log("ERROR: You must specify event type when calling .on() method of "+this.name);return}if(typeof t=="undefined"){console.log("ERROR: You must specify event handler function when calling .on() method of "+this.name);return}this.handlers.push({event:n,handler:t})},off:function(n,t){var r,u,i;if(jQuery.isPlainObject(n)||(n={type:n}),n=jQuery.extend({},{type:null,execute:"before",target:null,onComplete:null},n),typeof n.type=="undefined"){console.log("ERROR: You must specify event type when calling .off() method of "+this.name);return}typeof t=="undefined"&&(t=null),r=[];for(u in this.handlers)i=this.handlers[u],(i.event.type==n.type||n.type=="*")&&(i.event.target==n.target||n.target==null)&&(i.handler==t||t==null)||r.push(i);this.handlers=r},trigger:function(n){var n=jQuery.extend({type:null,phase:"before",target:null,isStopped:!1,isCancelled:!1},n,{preventDefault:function(){this.isCancelled=!0},stopPropagation:function(){this.isStopped=!0}}),e,t,r,i,f;for(typeof n.target=="undefined"&&(n.target=null),e=this.handlers.length-1;e>=0;e--)if(t=this.handlers[e],(t.event.type==n.type||t.event.type=="*")&&(t.event.target==n.target||t.event.target==null)&&(t.event.execute==n.phase||t.event.execute=="*"||t.event.phase=="*")&&(n=jQuery.extend({},t.event,n),r=[],i=RegExp(/\((.*?)\)/).exec(t.handler),i&&(r=i[1].split(/\s*,\s*/)),r.length==2?t.handler.call(this,n.target,n):t.handler.call(this,n),n.isStopped===!0||n.stop===!0))return n;if(f="on"+n.type.substr(0,1).toUpperCase()+n.type.substr(1),n.phase=="before"&&typeof this[f]=="function"){var u=this[f],r=[],i=RegExp(/\((.*?)\)/).exec(u);if(i&&(r=i[1].split(/\s*,\s*/)),r.length==2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0)return n}if(typeof n.object!="undefined"&&n.object!=null&&n.phase=="before"&&typeof n.object[f]=="function"){var u=n.object[f],r=[],i=RegExp(/\((.*?)\)/).exec(u);if(i&&(r=i[1].split(/\s*,\s*/)),r.length==2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0)return n}return n.phase=="after"&&n.onComplete!=null&&n.onComplete.call(this,n),n}},w2utils.keyboard=function(n){function f(){jQuery(document).on("keydown",e);jQuery(document).on("mousedown",o)}function e(n){var i=n.target.tagName;jQuery.inArray(i,["INPUT","SELECT","TEXTAREA"])==-1&&jQuery(n.target).prop("contenteditable")!="true"&&t&&w2ui[t]&&typeof w2ui[t].keydown=="function"&&w2ui[t].keydown.call(w2ui[t],n)}function o(n){var r=n.target.tagName,i=jQuery(n.target).parents(".w2ui-reset");i.length>0&&(t=i.attr("name"))}function i(n){if(typeof n=="undefined")return t;t=n}function r(){t=null}function u(){}var t=null;return n.active=i,n.clear=r,n.register=u,f(),n}({}),function(n){n.fn.w2render=function(t){n(this).length>0&&(typeof t=="string"&&w2ui[t]&&w2ui[t].render(n(this)[0]),typeof t=="object"&&t.render(n(this)[0]))},n.fn.w2destroy=function(n){!n&&this.length>0&&(n=this.attr("name")),typeof n=="string"&&w2ui[n]&&w2ui[n].destroy(),typeof n=="object"&&n.destroy()},n.fn.w2marker=function(t){return t==""||typeof t=="undefined"?n(this).each(function(n,t){t.innerHTML=t.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1")}):n(this).each(function(n,i){var f,r,u;typeof t=="string"&&(t=[t]),i.innerHTML=i.innerHTML.replace(/\(.*)\<\/span\>/ig,"$1");for(f in t)r=t[f],typeof r!="string"&&(r=String(r)),r=r.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").replace(/&/g,"&").replace(//g,"<"),u=new RegExp(r+"(?!([^<]+)?>)","gi"),i.innerHTML=i.innerHTML.replace(u,function(n){return''+n+""})})},n.fn.w2tag=function(t,i){if(n.isPlainObject(i)||(i={}),n.isPlainObject(i.css)||(i.css={}),typeof i["class"]=="undefined"&&(i["class"]=""),n(this).length==0){n(".w2ui-tag").each(function(t,i){var r=n(i).data("options");typeof r=="undefined"&&(r={}),n(n(i).data("taged-el")).removeClass(r["class"]),clearInterval(n(i).data("timer")),n(i).remove()});return}return n(this).each(function(r,u){var h=u.id,f=w2utils.escapeId(u.id),s,o;if(t==""||t==null||typeof t=="undefined")n("#w2ui-tag-"+f).css("opacity",0),setTimeout(function(){clearInterval(n("#w2ui-tag-"+f).data("timer")),n("#w2ui-tag-"+f).remove()},300);else{clearInterval(n("#w2ui-tag-"+f).data("timer")),n("#w2ui-tag-"+f).remove(),n("body").append('0?"w2ui-tag-popup":"")+'" \tstyle="">
'),s=setInterval(function(){if(n(u).length==0||n(u).offset().left==0&&n(u).offset().top==0){clearInterval(n("#w2ui-tag-"+f).data("timer")),e();return}n("#w2ui-tag-"+f).data("position")!=n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top&&n("#w2ui-tag-"+f).css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top)},100),setTimeout(function(){n(u).offset()&&(n("#w2ui-tag-"+f).css({opacity:"1",left:n(u).offset().left+u.offsetWidth+"px",top:n(u).offset().top+"px"}).html('").data("text",t).data("taged-el",u).data("options",i).data("position",n(u).offset().left+u.offsetWidth+"x"+n(u).offset().top).data("timer",s),n(u).off("keypress",e).on("keypress",e).off("change",e).on("change",e).css(i.css).addClass(i["class"]),typeof i.onShow=="function"&&i.onShow())},1),o="",n(u).length>0&&(o=n(u)[0].style.cssText);function e(){n("#w2ui-tag-"+f).length<=0||(clearInterval(n("#w2ui-tag-"+f).data("timer")),n("#w2ui-tag-"+f).remove(),n(u).off("keypress",e).removeClass(i["class"]),n(u).length>0&&(n(u)[0].style.cssText=o),typeof i.onHide=="function"&&i.onHide())}}})},n.fn.w2overlay=function(t,i){function e(){var t;(typeof i.onHide=="function"&&(t=i.onHide()),t!==!1)&&(n("#w2ui-overlay").remove(),n(document).off("click",e))}function o(){n(document).on("click",e);if(n("#w2ui-overlay > div").length>0){var u=n("#w2ui-overlay > div").height(),r=n("#w2ui-overlay> div").width(),t=window.innerHeight-n("#w2ui-overlay > div").offset().top-7;u>t&&n("#w2ui-overlay> div").height(t).width(r+w2utils.scrollBarSize()).css({"overflow-y":"auto"}),r=n("#w2ui-overlay> div").width(),t=window.innerWidth-n("#w2ui-overlay > div").offset().left-7,r>t&&n("#w2ui-overlay> div").width(t).css({"overflow-x":"auto"}),typeof i.onShow=="function"&&i.onShow()}}var u,f,r;if(n.isPlainObject(i)||(i={}),n.isPlainObject(i.css)||(i.css={}),this.length==0||t==""||typeof t=="undefined")return e(),n(this);n("#w2ui-overlay").length>0&&n(document).click(),n("body").append('0?"w2ui-overlay-popup":"")+'">\t
'),u=this,r=n("#w2ui-overlay div"),r.css(i.css).html(t),typeof i["class"]!="undefined"&&r.addClass(i["class"]),typeof i.top=="undefined"&&(i.top=0),typeof i.left=="undefined"&&(i.left=0),typeof i.width=="undefined"&&(i.width=100),typeof i.height=="undefined"&&(i.height=0),f=r.css("background-color"),r=n("#w2ui-overlay"),typeof f!="undefined"&&f!="rgba(0, 0, 0, 0)"&&f!="transparent"&&r.css("background-color",f);r.css({display:"none",left:n(u).offset().left+i.left+"px",top:n(u).offset().top+w2utils.getSize(n(u),"height")+3+i.top+"px","min-width":i.width?i.width:"auto","min-height":i.height?i.height:"auto"}).fadeIn("fast").data("position",n(u).offset().left+"x"+(n(u).offset().top+u.offsetHeight)).on("click",function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0});return setTimeout(o,0),n(this)},n.fn.w2menu=function(t,i){function r(){for(var f='"}return(typeof i.select=="undefined"&&typeof i.onSelect=="function"&&(i.select=i.onSelect),typeof i.select!="function")?(console.log("ERROR: options.select is required to be a function, not "+typeof i.select+" in $().w2menu(menu, options)"),n(this)):n.isArray(t)?(n.fn.w2menuHandler=function(n,r){i.select(t[r],n,r)},n(this).w2overlay(r(),i)):(console.log("ERROR: first parameter should be an array of objects or strings in $().w2menu(menu, options)"),n(this))}}(jQuery),function($){var w2grid=function(n){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:!1,toolbar:!1,footer:!1,columnHeaders:!0,lineNumbers:!1,expandColumn:!1,selectColumn:!1,emptyRecords:!0,toolbarReload:!0,toolbarColumns:!0,toolbarSearch:!0,toolbarAdd:!1,toolbarEdit:!1,toolbarDelete:!1,toolbarSave:!1,selectionBorder:!0,recordTitles:!0},this.autoLoad=!0,this.fixedBody=!0,this.recordHeight=24,this.keyboard=!0,this.selectType="row",this.multiSearch=!0,this.multiSelect=!0,this.multiSort=!0,this.markSearchResults=!0,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:!1,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?!0:!1,$.extend(!0,this,w2obj.grid,n)};$.fn.w2grid=function(n){var i,u,a,r,e,o,s;if(typeof n!="object"&&n){if(w2ui[$(this).attr("name")])return s=w2ui[$(this).attr("name")],s[n].apply(s,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+n+" does not exist on jQuery.w2grid")}else{if(!n||typeof n.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2grid().');return}if(typeof w2ui[n.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+n.name+").");return}if(!w2utils.isAlphaNumeric(n.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}var h=n.columns,l=n.columnGroups,f=n.records,c=n.searches,y=n.searchData,v=n.sortData,w=n.postData,p=n.toolbar,t=new w2grid(n);$.extend(t,{postData:{},records:[],columns:[],searches:[],toolbar:{},sortData:[],searchData:[],handlers:[]}),t.onExpand!=null&&(t.show.expandColumn=!0),$.extend(!0,t.toolbar,p);for(i in h)t.columns[i]=$.extend(!0,{},h[i]);for(i in l)t.columnGroups[i]=$.extend(!0,{},l[i]);for(i in c)t.searches[i]=$.extend(!0,{},c[i]);for(i in y)t.searchData[i]=$.extend(!0,{},y[i]);for(i in v)t.sortData[i]=$.extend(!0,{},v[i]);t.postData=$.extend(!0,{},w);for(u in f){if(f[u].recid==null||typeof f[u].recid=="undefined"){console.log("ERROR: Cannot add records without recid. (obj: "+t.name+")");return}t.records[u]=$.extend(!0,{},f[u])}t.records.length>0&&(t.buffered=t.records.length);for(a in t.columns)(r=t.columns[a],typeof r.searchable!="undefined"&&t.getSearch(r.field)==null)&&(e=r.searchable,o="",r.searchable===!0&&(e="text",o='size="20"'),t.addSearch({field:r.field,caption:r.caption,type:e,attr:o}));return t.initToolbar(),$(this).length!=0&&t.render($(this)[0]),w2ui[t.name]=t,t}},w2grid.prototype={msgDelete:w2utils.lang("Are you sure you want to delete selected records?"),msgNotJSON:w2utils.lang("Returned data is not in valid JSON format."),msgRefresh:w2utils.lang("Refreshing..."),buttons:{reload:{type:"button",id:"reload",img:"icon-reload",hint:w2utils.lang("Reload data in the list")},columns:{type:"drop",id:"column-on-off",img:"icon-columns",hint:w2utils.lang("Show/hide columns"),arrow:!1,html:""},search:{type:"html",id:"search",html:'"},"search-go":{type:"check",id:"search-advanced",caption:w2utils.lang("Search..."),hint:w2utils.lang("Open Search Fields")},add:{type:"button",id:"add",caption:w2utils.lang("Add New"),hint:w2utils.lang("Add new record"),img:"icon-add"},edit:{type:"button",id:"edit",caption:w2utils.lang("Edit"),hint:w2utils.lang("Edit selected record"),img:"icon-edit",disabled:!0},"delete":{type:"button",id:"delete",caption:w2utils.lang("Delete"),hint:w2utils.lang("Delete selected records"),img:"icon-delete",disabled:!0},save:{type:"button",id:"save",caption:w2utils.lang("Save"),hint:w2utils.lang("Save changed records"),img:"icon-save"}},add:function(n){var i,t,r;$.isArray(n)||(n=[n]),i=0;for(t in n){if(n[t].recid==null||typeof n[t].recid=="undefined"){console.log("ERROR: Cannot add record without recid. (obj: "+this.name+")");continue}this.records.push(n[t]),i++}return this.buffered=this.records.length,r=typeof this.url!="object"?this.url:this.url.get,r||(this.localSort(),this.localSearch()),this.refresh(),i},find:function(n,t){var f,i,u,r,e;for((typeof n=="undefined"||n==null)&&(n={}),f=[],i=0;i0&&!o)for(f in this.last.searchIds)this.last.searchIds[f]==r&&(r=f);$(u).replaceWith(this.getRecordHTML(r,s))}}return!0},get:function(n,t){for(var i=0;i=0;n--)this.records[n].recid==arguments[t]&&(this.records.splice(n,1),r++);return i=typeof this.url!="object"?this.url:this.url.get,i||(this.buffered=this.records.length,this.localSort(),this.localSearch()),this.refresh(),r},addColumn:function(n,t){var r=0,i;arguments.length==1?(t=n,n=this.columns.length):(typeof n=="string"&&(n=this.getColumn(n,!0)),n===null&&(n=this.columns.length)),$.isArray(t)||(t=[t]);for(i in t)this.columns.splice(n,0,t[i]),n++,r++;return this.initColumnOnOff(),this.refresh(),r},removeColumn:function(){for(var i=0,n,t=0;t=0;n--)this.columns[n].field==arguments[t]&&(this.columns.splice(n,1),i++);return this.initColumnOnOff(),this.refresh(),i},getColumn:function(n,t){for(var i=0;i=0;n--)this.columns[n].field==arguments[t]&&(this.columns[n].hidden=!this.columns[n].hidden,i++);return this.refresh(),i},showColumn:function(){for(var i=0,n,t=0;t=0;n--)this.columns[n].field==arguments[t]&&this.columns[n].hidden!==!1&&(this.columns[n].hidden=!1,i++);return this.refresh(),i},hideColumn:function(){for(var i=0,n,t=0;t=0;n--)this.columns[n].field==arguments[t]&&this.columns[n].hidden!==!0&&(this.columns[n].hidden=!0,i++);return this.refresh(),i},addSearch:function(n,t){var r=0,i;arguments.length==1?(t=n,n=this.searches.length):(typeof n=="string"&&(n=this.getSearch(n,!0)),n===null&&(n=this.searches.length)),$.isArray(t)||(t=[t]);for(i in t)this.searches.splice(n,0,t[i]),n++,r++;return this.searchClose(),r},removeSearch:function(){for(var i=0,n,t=0;t=0;n--)this.searches[n].field==arguments[t]&&(this.searches.splice(n,1),i++);return this.searchClose(),i},getSearch:function(n,t){for(var i=0;i=0;n--)this.searches[n].field==arguments[t]&&(this.searches[n].hidden=!this.searches[n].hidden,i++);return this.searchClose(),i},showSearch:function(){for(var i=0,n,t=0;t=0;n--)this.searches[n].field==arguments[t]&&this.searches[n].hidden!==!1&&(this.searches[n].hidden=!1,i++);return this.searchClose(),i},hideSearch:function(){for(var i=0,n,t=0;t=0;n--)this.searches[n].field==arguments[t]&&this.searches[n].hidden!==!0&&(this.searches[n].hidden=!0,i++);return this.searchClose(),i},getSearchData:function(n){for(var t in this.searchData)if(this.searchData[t].field==n)return this.searchData[t];return null},localSort:function(n){var r=typeof this.url!="object"?this.url:this.url.get,i,t;if(r){console.log("ERROR: grid.localSort can only be used on local data source, grid.url should be empty.");return}if(!$.isEmptyObject(this.sortData))return i=+new Date,t=this,this.records.sort(function(n,i){var e=0,f,r,u;for(f in t.sortData)if(r=n[t.sortData[f].field],u=i[t.sortData[f].field],String(t.sortData[f].field).indexOf(".")!=-1&&(r=t.parseField(n,t.sortData[f].field),u=t.parseField(i,t.sortData[f].field)),typeof r=="string"&&(r=$.trim(r.toLowerCase())),typeof u=="string"&&(u=$.trim(u.toLowerCase())),r>u&&(e=t.sortData[f].direction=="asc"?1:-1),r0&&!a){this.total=0;for(l in this.records){s=this.records[l],u=0;for(v in this.searchData)if(i=this.searchData[v],t=this.getSearch(i.field),i!=null){t==null&&(t={field:i.field,type:i.type}),f=String(c.parseField(s,t.field)).toLowerCase(),typeof i.value!="undefined"&&($.isArray(i.value)?(r=i.value[0],e=i.value[1]):r=String(i.value).toLowerCase());switch(i.operator){case"is":s[t.field]==i.value&&u++,t.type=="date"&&(o=new Date(Number(f)),f=+new Date(o.getFullYear(),o.getMonth(),o.getDate()),r=Number(r),e=Number(f)+864e5,r>=f&&r<=e&&u++);break;case"between":t.type=="int"&&parseInt(s[t.field])>=parseInt(r)&&parseInt(s[t.field])<=parseInt(e)&&u++,t.type=="float"&&parseFloat(s[t.field])>=parseFloat(r)&&parseFloat(s[t.field])<=parseFloat(e)&&u++,t.type=="date"&&(o=new Date(Number(e)),e=+new Date(o.getFullYear(),o.getMonth(),o.getDate()),e=Number(e)+864e5,f>=r&&f=0&&u++;break;case"ends with":f.indexOf(r)==f.length-r.length&&u++}}(this.last.logic=="OR"&&u!=0||this.last.logic=="AND"&&u==this.searchData.length)&&this.last.searchIds.push(parseInt(l))}this.total=this.last.searchIds.length}return this.buffered=this.total,h=+new Date-h,n!==!0&&setTimeout(function(){c.status("Search took "+h/1e3+" sec")},10),h},getRangeData:function(n,t){var o=this.get(n[0].recid,!0),c=this.get(n[1].recid,!0),s=n[0].column,h=n[1].column,r=[],u,f,i,e;if(s==h)for(u=o;u<=c;u++)f=this.records[u],e=f[this.columns[s].field]||null,t!==!0?r.push(e):r.push({data:e,column:s,index:u,record:f});else if(o==c)for(f=this.records[o],i=s;i<=h;i++)e=f[this.columns[i].field]||null,t!==!0?r.push(e):r.push({data:e,column:i,index:o,record:f});else for(u=o;u<=c;u++)for(f=this.records[u],r.push([]),i=s;i<=h;i++)e=f[this.columns[i].field],t!==!0?r[r.length-1].push(e):r[r.length-1].push({data:e,column:i,index:u,record:f});return r},addRange:function(n){var o=0,t,u,e,f,s;if(this.selectType=="row")return o;$.isArray(n)||(n=[n]);for(t in n){if(typeof n[t]!="object"&&(n[t]={name:"selection"}),n[t].name=="selection"){if(this.show.selectionBorder===!1)continue;if(u=this.getSelection(),u.length==0){this.removeRange(n[t].name);continue}else var i=u[0],r=u[u.length-1],c=$("#grid_"+this.name+"_rec_"+i.recid+" td[col="+i.column+"]"),h=$("#grid_"+this.name+"_rec_"+r.recid+" td[col="+r.column+"]")}else var i=n[t].range[0],r=n[t].range[1],c=$("#grid_"+this.name+"_rec_"+i.recid+" td[col="+i.column+"]"),h=$("#grid_"+this.name+"_rec_"+r.recid+" td[col="+r.column+"]");if(i){e={name:n[t].name,range:[{recid:i.recid,column:i.column},{recid:r.recid,column:r.column}],style:n[t].style||""},f=!1;for(s in this.ranges)if(this.ranges[s].name==n[t].name){f=t;break}f!==!1?this.ranges[f]=e:this.ranges.push(e),o++}}return this.refreshRanges(),o},removeRange:function(){for(var r=0,i,n,t=0;t=0;n--)this.ranges[n].name==i&&(this.ranges.splice(n,1),r++);return r},refreshRanges:function(){function l(t){var i=n.getSelection();n.last.move={type:"expand",x:t.screenX,y:t.screenY,divX:0,divY:0,recid:i[0].recid,column:i[0].column,originalRange:[{recid:i[0].recid,column:i[0].column},{recid:i[i.length-1].recid,column:i[i.length-1].column}],newRange:[{recid:i[0].recid,column:i[0].column},{recid:i[i.length-1].recid,column:i[i.length-1].column}]};$(document).off("mousemove",f).on("mousemove",f);$(document).off("mouseup",e).on("mouseup",e)}function f(t){var r=n.last.move,e,o,u,f;if(r&&r.type=="expand"&&(r.divX=t.screenX-r.x,r.divY=t.screenY-r.y,u=t.originalEvent.target,u.tagName!="TD"&&(u=$(u).parents("td")[0]),typeof $(u).attr("col")!="undefined"&&(o=parseInt($(u).attr("col"))),u=$(u).parents("tr")[0],e=$(u).attr("recid"),r.newRange[1].recid!=e||r.newRange[1].column!=o)){if(f=$.extend({},r.newRange),r.newRange=[{recid:r.recid,column:r.column},{recid:e,column:o}],i=n.trigger($.extend(i,{originalRange:r.originalRange,newRange:r.newRange})),i.isCancelled===!0){r.newRange=f,i.newRange=f;return}n.removeRange("grid-selection-expand"),n.addRange({name:"grid-selection-expand",range:i.newRange,style:"background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);"})}}function e(){n.removeRange("grid-selection-expand"),delete n.last.move,$(document).off("mousemove",f),$(document).off("mouseup",e),n.trigger($.extend(i,{phase:"after"}))}var n=this,a=+new Date,o=$("#grid_"+this.name+"_records"),c,i;for(c in this.ranges){var t=this.ranges[c],h=t.range[0],s=t.range[1],r=$("#grid_"+this.name+"_rec_"+h.recid+" td[col="+h.column+"]"),u=$("#grid_"+this.name+"_rec_"+s.recid+" td[col="+s.column+"]");$("#grid_"+this.name+"_"+t.name).length==0?o.append(''+(t.name=="selection"?'
':"")+"
"):$("#grid_"+this.name+"_"+t.name).attr("style",t.style),r.length>0&&u.length>0&&$("#grid_"+this.name+"_"+t.name).css({left:r.position().left-1+o.scrollLeft()+"px",top:r.position().top-1+o.scrollTop()+"px",width:u.position().left-r.position().left+u.width()+3+"px",height:u.position().top-r.position().top+u.height()+3+"px"})}$(this.box).find("#grid_"+this.name+"_resizer").off("mousedown").on("mousedown",l);return i={phase:"before",type:"selectionExtend",target:n.name,originalRange:null,newRange:null},+new Date-a},select:function(){for(var s=0,r,o,e,f,u,i=0;i td[col="+r+"]").addClass("w2ui-selected"),s++,n.selected&&($("#grid_"+this.name+"_rec_"+w2utils.escapeId(t)).data("selected","yes"),$("#grid_"+this.name+"_cell_"+h+"_select_check").prop("checked",!0))}this.trigger($.extend(u,{phase:"after"}))}}return $("#grid_"+this.name+"_check_all").prop("checked",!0),$("#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",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),s},unselect:function(){for(var s=0,f,i,h,o,r,e,t=0;t td[col="+i+"]").removeClass("w2ui-selected"),s++,r.length==0&&(n.selected=!1,$("#grid_"+this.name+"_rec_"+w2utils.escapeId(u)).removeData("selected"),$("#grid_"+this.name+"_cell_"+c+"_select_check").prop("checked",!1))}this.trigger($.extend(e,{phase:"after"}))}}return $("#grid_"+this.name+"_check_all").prop("checked",!0),$("#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",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),s},selectAll:function(){var r,n,u,f,t,i;if(this.multiSelect!==!1&&(r=this.trigger({phase:"before",type:"select",target:this.name,all:!0}),r.isCancelled!==!0)){n=[];for(u in this.columns)n.push(parseInt(u));if(f=typeof this.url!="object"?this.url:this.url.get,f)this.selectType=="row"?this.set({selected:!0}):this.set({selected:!0,selectedColumns:n.slice()}),this.refresh();else if(this.searchData.length==0)this.set({selected:!0}),this.selectType=="row"?this.set({selected:!0}):this.set({selected:!0,selectedColumns:n.slice()});else{for(t=0;t=1?this.toolbar.enable("delete"):this.toolbar.disable("delete"),this.addRange("selection"),this.trigger($.extend(r,{phase:"after"}))}},selectNone:function(){var f=this.trigger({phase:"before",type:"unselect",target:this.name,all:!0}),r,n,t,i,u;if(f.isCancelled!==!0){this.last.selected=[];for(r in this.records)if(n=this.records[r],n.selected===!0&&(n.selected=!1,t=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(n.recid)),t.removeClass("w2ui-selected").removeData("selected"),$("#grid_"+this.name+"_cell_"+r+"_select_check").prop("checked",!1),this.selectType!="row")){i=n.selectedColumns;for(u in i)t.find(" > td[col="+i[u]+"]").removeClass("w2ui-selected");n.selectedColumns=[]}this.toolbar.disable("edit","delete"),this.removeRange("selection"),this.trigger($.extend(f,{phase:"after"}))}},getSelection:function(n){var t,i,r,u,f;if(this.selectType=="row"){t=this.find({selected:!0},!0),i=[];for(r in t)n===!0?i.push(t[r]):i.push(this.records[t[r]].recid);return i}t=this.find({selected:!0},!0),i=[];for(r in t){u=this.records[t[r]];for(f in u.selectedColumns)i.push({recid:u.recid,index:parseInt(t[r]),column:u.selectedColumns[f]})}return i},search:function(n,t){var it=this,nt=typeof this.url!="object"?this.url:this.url.get,u=[],v=this.last.multi,a=this.last.logic,g=this.last.field,p=this.last.search,f,d,h,s,c,r,o,k,b,i,y;if(arguments.length==0){p="";for(f in this.searches){var i=this.searches[f],l=$("#grid_"+this.name+"_operator_"+f).val(),e=$("#grid_"+this.name+"_field_"+f).val(),w=$("#grid_"+this.name+"_field2_"+f).val();if(e!=""&&e!=null||typeof w!="undefined"&&w!=""){r={field:i.field,type:i.type,operator:l},l=="between"?$.extend(r,{value:[e,w]}):l=="in"?$.extend(r,{value:e.split(",")}):$.extend(r,{value:e});try{i.type=="date"&&l=="between"&&(r.value[0]=w2utils.isDate(e,w2utils.settings.date_format,!0).getTime(),r.value[1]=w2utils.isDate(w,w2utils.settings.date_format,!0).getTime()),i.type=="date"&&l=="is"&&(r.value=w2utils.isDate(e,w2utils.settings.date_format,!0).getTime())}catch(tt){}u.push(r)}}u.length>0&&!nt?(v=!0,a="AND"):(v=!0,a="AND")}if(typeof n=="string"&&(g=n,p=t,v=!1,a="OR",typeof t!="undefined"))if(n.toLowerCase()=="all")if(this.searches.length>0)for(f in this.searches)i=this.searches[f],(i.type=="text"||i.type=="int"&&w2utils.isInt(t)||i.type=="float"&&w2utils.isFloat(t)||i.type=="money"&&w2utils.isMoney(t)||i.type=="hex"&&w2utils.isHex(t)||i.type=="date"&&w2utils.isDate(t)||i.type=="alphaNumeric"&&w2utils.isAlphaNumeric(t))&&(r={field:i.field,type:i.type,operator:i.type=="text"?"contains":"is",value:t},u.push(r)),i.type=="int"&&String(t).indexOf("-")!=-1&&(c=String(t).split("-"),r={field:i.field,type:i.type,operator:"between",value:[c[0],c[1]]},u.push(r));else for(d in this.columns)r={field:this.columns[d].field,type:"text",operator:"contains",value:t},u.push(r);else if(i=this.getSearch(n),i==null&&(i={field:n,type:"text"}),i.field==n&&(this.last.caption=i.caption),t!=""){if(h="contains",s=t,w2utils.isInt(t)&&(h="is",s=t),i.type=="int"&&t!=""&&(String(t).indexOf("-")!=-1&&(r=t.split("-"),r.length==2&&(h="between",s=[parseInt(r[0]),parseInt(r[1])])),String(t).indexOf(",")!=-1)){r=t.split(","),h="in",s=[];for(c in r)s.push(r[c])}r={field:i.field,type:i.type,operator:h,value:s},u.push(r)}if($.isArray(n)){o="AND",typeof t=="string"&&(o=t.toUpperCase(),o!="OR"&&o!="AND"&&(o="AND")),p="",v=!0,a=o;for(k in n)b=n[k],i=this.getSearch(b.field),i==null&&(i={type:"text",operator:"contains"}),u.push($.extend(!0,{},i,b))}(y=this.trigger({phase:"before",type:"search",target:this.name,searchData:u,searchField:n?n:"multi",searchValue:t?t:"multi"}),y.isCancelled!==!0)&&(this.searchData=y.searchData,this.last.field=g,this.last.search=p,this.last.multi=v,this.last.logic=a,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selected=[],this.searchClose(),this.set({expanded:!1}),nt?(this.last.xhr_offset=0,this.reload()):(this.localSearch(),this.refresh()),this.trigger($.extend(y,{phase:"after"})))},searchOpen:function(){if(this.box&&this.searches.length!=0){var n=this;$("#tb_"+this.name+"_toolbar_item_search-advanced").w2overlay(this.getSearchesHTML(),{left:-10,"class":"w2ui-grid-searches",onShow:function(){n.last.logic=="OR"&&(n.searchData=[]),n.initSearches(),$("#w2ui-overlay .w2ui-grid-searches").data("grid-name",n.name);var t=$("#w2ui-overlay .w2ui-grid-searches *[rel=search]");t.length>0&&t[0].focus()}})}},searchClose:function(){this.box&&this.searches.length!=0&&(this.toolbar&&this.toolbar.uncheck("search-advanced"),$("#w2ui-overlay .w2ui-grid-searches").length>0&&$().w2overlay())},searchShowFields:function(n){var r,i,t;for(typeof n=="undefined"&&(n=$("#grid_"+this.name+"_search_all")),r='",$(n).w2overlay(r,{left:-15,top:7})},searchReset:function(n){var t=this.trigger({phase:"before",type:"search",target:this.name,searchData:[]});t.isCancelled!==!0&&(this.searchData=[],this.last.search="",this.last.logic="OR",this.last.multi&&(this.multiSearch?(this.last.field="all",this.last.caption=w2utils.lang("All Fields")):(this.last.field=this.searches[0].field,this.last.caption=this.searches[0].caption)),this.last.multi=!1,this.last.xhr_offset=0,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selected=[],this.searchClose(),n||this.reload(),this.trigger($.extend(t,{phase:"after"})))},clear:function(n){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,n||this.refresh()},reset:function(n){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(n),this.last.sortData!=null&&(this.sortData=this.last.sortData),this.set({selected:!1,expanded:!1},!0),n||this.refresh()},skip:function(n){var t=typeof this.url!="object"?this.url:this.url.get;t?(this.offset=parseInt(n),(this.offset<0||!w2utils.isInt(this.offset))&&(this.offset=0),this.offset>this.total&&(this.offset=this.total-this.limit),this.records=[],this.buffered=0,this.last.xhr_offset=0,this.last.pull_more=!0,this.last.scrollTop=0,this.last.scrollLeft=0,$("#grid_"+this.name+"_records").prop("scrollTop",0),this.initColumnOnOff(),this.reload()):console.log("ERROR: grid.skip() can only be called when you have remote data source.")},load:function(n,t){if(typeof n=="undefined"){console.log('ERROR: You need to provide url argument when calling .load() method of "'+this.name+'" object.');return}this.request("get-records",{},n,t)},reload:function(n){var t=typeof this.url!="object"?this.url:this.url.get;t?(this.last.xhr_offset>0&&this.last.xhr_offset div"),o.type=="enum"&&console.log("ERROR: Grid's inline editing does not support enum field type."),(o.type=="list"||o.type=="select")&&console.log("ERROR: Grid's inline editing does not support list/select field type."),typeof o.inTag=="undefined"&&(o.inTag=""),typeof o.outTag=="undefined"&&(o.outTag=""),typeof o.style=="undefined"&&(o.style=""),typeof o.items=="undefined"&&(o.items=[]),h=f.changed&&f.changes[e.field]?w2utils.stripTags(f.changes[e.field]):w2utils.stripTags(f[e.field]),(h==null||typeof h=="undefined")&&(h=""),typeof i!="undefined"&&i!=null&&(h=i),v=typeof e.style!="undefined"?e.style+";":"",$.inArray(e.render,["number","int","float","money","percent"])!=-1&&(v+="text-align: right;"),c.addClass("w2ui-editable").html('"+o.outTag);c.find("input").w2field(o.type).on("blur",function(){if(u.parseField(f,e.field)!=this.value){var r=u.trigger({phase:"before",type:"change",target:u.name,input_id:this.id,recid:n,column:t,value_new:this.value,value_previous:f.changes?f.changes[e.field]:u.parseField(f,e.field),value_original:u.parseField(f,e.field)});r.isCancelled===!0||(f.changed=!0,f.changes=f.changes||{},f.changes[e.field]=r.value_new,u.trigger($.extend(r,{phase:"after"})))}else f.changes&&delete f.changes[e.field],$.isEmptyObject(f.changes)&&delete f.changes;$(a).replaceWith(u.getRecordHTML(s,a.attr("line")))}).on("keydown",function(i){function a(n){var t=n+1;return u.columns.length==t?n:u.columns[t].hidden?a(t):t}function v(n){var t=n-1;return t<0?n:u.columns[t].hidden?v(t):t}function c(n){var t=n+1;return u.records.length==t?n:t}function l(n){var t=n-1;return t<0?n:t}var o=!1,r,h;switch(i.keyCode){case 9:o=!0,r=i.shiftKey?v(t):a(t),r!=t&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:n,column:r})):u.editField(n,r,null,i)},1));break;case 13:o=!0,r=i.shiftKey?l(s):c(s),r!=s&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:u.records[r].recid,column:t})):u.editField(u.records[r].recid,t,null,i)},1));break;case 38:o=!0,r=l(s),r!=s&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:u.records[r].recid,column:t})):u.editField(u.records[r].recid,t,null,i)},1));break;case 40:o=!0,r=c(s),r!=s&&(this.blur(),setTimeout(function(){u.selectType!="row"?(u.selectNone(),u.select({recid:u.records[r].recid,column:t})):u.editField(u.records[r].recid,t,null,i)},1));break;case 27:h=f.changed&&f.changes[e.field]?f.changes[e.field]:u.parseField(f,e.field),this.value=typeof h!="undefined"?h:"",this.blur(),setTimeout(function(){u.select({recid:n,column:t})},1)}o&&i.preventDefault&&i.preventDefault()});typeof i=="undefined"||i==null?c.find("input").focus():c.find("input").val("").focus().val(i),u.trigger($.extend(l,{phase:"after"}))}},"delete":function(n){var o=this,f=this.trigger({phase:"before",target:this.name,type:"delete",force:n}),t,e,u,r,i;if(f.isCancelled===!0)return!1;if(n=f.force,t=this.getSelection(),t.length!=0){if(this.msgDelete!=""&&!n){w2confirm(o.msgDelete,w2utils.lang("Delete Confirmation"),function(n){n=="Yes"&&w2ui[o.name].delete(!0)});return}if(e=typeof this.url!="object"?this.url:this.url.remove,e)this.request("delete-records");else if(typeof t[0]!="object")this.remove.apply(this,t);else{for(u in t)r=this.columns[t[u].column].field,i=this.get(t[u].recid,!0),i!=null&&r!="recid"&&(this.records[i][r]="",this.records[i].changed&&(this.records[i].changes[r]=""));this.refresh()}this.trigger($.extend(f,{phase:"after"}))}},click:function(n,t){var g=+new Date,i=null,b,c,nt,f,r,p,y,a,h,s,v,u,tt,e,k,o;if(typeof n=="object"&&(i=n.column,n=n.recid),w2utils.isInt(n)&&(n=parseInt(n)),typeof t=="undefined"&&(t={}),g-parseInt(this.last.click_time)<250&&t.type=="click"){this.dblClick(n,t);return}if(this.last.click_time=g,i==null&&t.target&&(u=t.target,u.tagName!="TD"&&(u=$(u).parents("td")[0]),typeof $(u).attr("col")!="undefined"&&(i=parseInt($(u).attr("col")))),b=this.trigger({phase:"before",target:this.name,type:"click",recid:n,column:i,originalEvent:t}),b.isCancelled===!0)return!1;c=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(n)).parents("tr"),c.length>0&&String(c.attr("id")).indexOf("expanded_row")!=-1&&(nt=c.parents(".w2ui-grid").attr("name"),w2ui[nt].selectNone(),c.parents(".w2ui-grid").find(".w2ui-expanded-row .w2ui-grid").each(function(n,t){var i=$(t).attr("name");w2ui[i]&&w2ui[i].selectNone()})),$(this.box).find(".w2ui-expanded-row .w2ui-grid").each(function(n,t){var i=$(t).attr("name");w2ui[i]&&w2ui[i].selectNone()}),f=this,r=this.getSelection(),$("#grid_"+this.name+"_check_all").prop("checked",!1);var d=this.get(n,!0),l=this.records[d],w=[];if(f.last.sel_ind=d,f.last.sel_col=i,f.last.sel_recid=n,f.last.sel_type="click",t.shiftKey&&r.length>0){if(r[0].recid)for(h=this.get(r[0].recid,!0),s=this.get(n,!0),i>r[0].column?(p=r[0].column,y=i):(p=i,y=r[0].column),a=p;a<=y;a++)w.push(a);else h=this.get(r[0],!0),s=this.get(n,!0);for(v=[],h>s&&(u=h,h=s,s=u),tt=typeof this.url!="object"?this.url:this.url.get,e=h;e<=s;e++)if(!(this.searchData.length>0)||tt||$.inArray(e,this.last.searchIds)!=-1)if(this.selectType=="row")v.push(this.records[e].recid);else for(k in w)v.push({recid:this.records[e].recid,column:w[k]});this.select.apply(this,v)}else(t.ctrlKey||t.shiftKey||t.metaKey)&&this.multiSelect||this.showSelectColumn?(o=l.selected,this.selectType!="row"&&$.inArray(i,l.selectedColumns)==-1&&(o=!1),o===!0?this.unselect({recid:n,column:i}):this.select({recid:l.recid,column:i}),setTimeout(function(){window.getSelection&&window.getSelection().removeAllRanges()},10)):(o=l.selected,this.selectType!="row"&&$.inArray(i,l.selectedColumns)==-1&&(o=!1),r.length>300?this.selectNone():this.unselect.apply(this,r),o===!0?this.unselect({recid:n,column:i}):this.select({recid:n,column:i}));this.status(),f.last.selected=this.getSelection(),f.initResize(),this.trigger($.extend(b,{phase:"after"}))},columnClick:function(n,t){var i=this.trigger({phase:"before",type:"columnClick",target:this.name,field:n,originalEvent:t});if(i.isCancelled===!0)return!1;this.sort(n,null,t&&(t.ctrlKey||t.metaKey)?!0:!1),this.trigger($.extend(i,{phase:"after"}))},keydown:function(n){function st(n){if(n+10&&n0)for(;;){if($.inArray(n,t.last.searchIds)!=-1||n>t.records.length)break;n++}return n}return null}function ht(n){if(n>0&&t.last.searchIds.length==0||t.last.searchIds.length>0&&n>t.last.searchIds[0]){if(n--,t.last.searchIds.length>0)for(;;){if($.inArray(n,t.last.searchIds)!=-1||n<0)break;n--}return n}return null}function et(n){var i=n+1;return t.columns.length==i?n:t.columns[i].hidden?findNext(i):i}function ot(n){var i=n-1;return i<0?n:t.columns[i].hidden?findPrev(i):i}function g(){if(t.last.sel_type!="click")return!1;if(t.selectType!="row"){if(t.last.sel_type="key",i.length>1){for(var n in i)if(i[n].recid==t.last.sel_recid&&i[n].column==t.last.sel_col){i.splice(n,1);break}return t.unselect.apply(t,i),!0}return!1}return(t.last.sel_type="key",i.length>1)?(i.splice(i.indexOf(t.records[t.last.sel_ind].recid),1),t.unselect.apply(t,i),!0):!1}var t=this,it,b,i,c,y,d,a,v,h,l,f,o,rt,e,u;if(t.keyboard===!0){if(it=t.trigger({phase:"before",type:"keydown",target:t.name,originalEvent:n}),it.isCancelled===!0)return!1;if(i=t.getSelection(),i.length!=0){var ct=$("#grid_"+t.name+"_records"),f=i[0],r=[],ft=i[i.length-1];if(typeof f=="object"){for(f=i[0].recid,r=[],b=0;;){if(!i[b]||i[b].recid!=f)break;r.push(i[b].column),b++}ft=i[i.length-1].recid}var p=t.get(f,!0),w=t.get(ft,!0),ut=t.get(f),k=$("#grid_"+t.name+"_rec_"+w2utils.escapeId(t.records[p].recid)),s=!1;switch(n.keyCode){case 8:case 46:t.delete(),s=!0,n.stopPropagation();break;case 27:i=t.getSelection(),t.selectNone(),i.length>0&&(typeof i[0]=="object"?t.select({recid:i[0].recid,column:i[0].column}):t.select(i[0])),s=!0;break;case 13:case 32:r.length==0&&r.push(0),t.editField(f,r[0],null,n),s=!0;break;case 65:if(!n.metaKey&&!n.ctrlKey)break;t.selectAll(),s=!0;break;case 70:if(!n.metaKey&&!n.ctrlKey)break;$("#grid_"+t.name+"_search_all").focus(),s=!0;break;case 13:if(this.selectType=="row"){if(k.length<=0||t.show.expandColumn!==!0)break;t.toggle(f,n),s=!0}else r.length==0&&r.push(0),t.editField(f,r[0],null,n),s=!0;break;case 37:if(l=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(t.records[p].recid)).parents("tr"),l.length>0&&String(l.attr("id")).indexOf("expanded_row")!=-1){f=l.prev().attr("recid"),o=l.parents(".w2ui-grid").attr("name"),t.selectNone(),w2utils.keyboard.active(o),w2ui[o].set(f,{expanded:!1}),w2ui[o].collapse(f),w2ui[o].click(f),s=!0;break}if(this.selectType=="row"){if(k.length<=0||ut.expanded!==!0)break;t.set(f,{expanded:!1},!0),t.collapse(f,n)}else if(c=ot(r[0]),c!=r[0])if(n.shiftKey){if(g())return;var u=[],tt=[],nt=[];if(r.indexOf(this.last.sel_col)==0&&r.length>1)for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),nt.push({recid:i[e].recid,column:r[r.length-1]});else for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),tt.push({recid:i[e].recid,column:c});t.unselect.apply(t,nt),t.select.apply(t,tt)}else t.click({recid:f,column:c},n);else if(!n.shiftKey)for(h=1;h1)for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),nt.push({recid:i[e].recid,column:r[0]});else for(e in i)u.indexOf(i[e].recid)==-1&&u.push(i[e].recid),tt.push({recid:i[e].recid,column:a});t.unselect.apply(t,nt),t.select.apply(t,tt)}else t.click({recid:f,column:a},n);else if(!n.shiftKey)for(h=0;h0&&w2ui[y.attr("name")])){t.selectNone(),o=y.attr("name"),d=w2ui[o].records,w2utils.keyboard.active(o),w2ui[o].click(d[d.length-1].recid),s=!0;break}if(n.shiftKey){if(g())return;if(t.selectType=="row")t.last.sel_ind>c&&t.last.sel_ind!=w?t.unselect(t.records[w].recid):t.select(t.records[c].recid);else if(t.last.sel_ind>c&&t.last.sel_ind!=w){c=w,u=[];for(v in r)u.push({recid:t.records[c].recid,column:r[v]});t.unselect.apply(t,u)}else{u=[];for(v in r)u.push({recid:t.records[c].recid,column:r[v]});t.select.apply(t,u)}}else t.selectNone(),t.click({recid:t.records[c].recid,column:r[0]},n);t.scrollIntoView(c),n.preventDefault&&n.preventDefault()}else{if(!n.shiftKey)for(h=1;h0&&String(l.attr("id")).indexOf("expanded_row")!=-1){f=l.prev().attr("recid"),o=l.parents(".w2ui-grid").attr("name"),t.selectNone(),w2utils.keyboard.active(o),w2ui[o].click(f),s=!0;break}}break;case 40:if(k.length<=0)break;if(t.records[w].expanded&&(y=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(t.records[w].recid)+"_expanded_row").find(".w2ui-grid"),y.length>0&&w2ui[y.attr("name")])){t.selectNone(),o=y.attr("name"),d=w2ui[o].records,w2utils.keyboard.active(o),w2ui[o].click(d[0].recid),s=!0;break}if(a=st(w),a!=null){if(n.shiftKey){if(g())return;if(t.selectType=="row")this.last.sel_ind0&&String(l.attr("id")).indexOf("expanded_row")!=-1){f=l.next().attr("recid"),o=l.parents(".w2ui-grid").attr("name"),t.selectNone(),w2utils.keyboard.active(o),w2ui[o].click(f),s=!0;break}}break;case 86:(n.ctrlKey||n.metaKey)&&($("body").append(''),$("#_tmp_copy_data").focus(),setTimeout(function(){t.paste($("#_tmp_copy_data").val()),$("#_tmp_copy_data").remove()},50));break;case 88:(n.ctrlKey||n.metaKey)&&setTimeout(function(){t.delete(!0)},100);case 67:(n.ctrlKey||n.metaKey)&&(rt=t.copy(),$("body").append('"),$("#_tmp_copy_data").focus().select(),setTimeout(function(){$("#_tmp_copy_data").remove()},50))}for(u=[187,189],e=48;e<=90;e++)u.push(e);u.indexOf(n.keyCode)==-1||n.ctrlKey||n.metaKey||s||(r.length==0&&r.push(0),u=String.fromCharCode(n.keyCode),n.keyCode==187&&(u="="),n.keyCode==189&&(u="-"),n.shiftKey||(u=u.toLowerCase()),t.editField(f,r[0],u,n),s=!0),s&&n.preventDefault&&n.preventDefault(),t.trigger($.extend(it,{phase:"after"}))}}},scrollIntoView:function(n){var f,t,r,i,u;if(typeof n=="undefined"){if(f=this.getSelection(),f.length==0)return;n=this.get(f[0],!0)}(t=$("#grid_"+this.name+"_records"),t.length!=0)&&((r=this.last.searchIds.length,t.height()>this.recordHeight*(r>0?r:this.records.length))||(r>0&&(n=this.last.searchIds.indexOf(n)),i=Math.floor(t[0].scrollTop/this.recordHeight),u=i+Math.floor(t.height()/this.recordHeight),n==i&&t.animate({scrollTop:t.scrollTop()-t.height()/1.3}),n==u&&t.animate({scrollTop:t.scrollTop()+t.height()/1.3}),(nu)&&t.animate({scrollTop:(n-1)*this.recordHeight})))},dblClick:function(n,t){var i,r,f,u;if(window.getSelection&&window.getSelection().removeAllRanges(),i=null,typeof n=="object"&&(i=n.column,n=n.recid),typeof t=="undefined"&&(t={}),i==null&&t.target&&(r=t.target,r.tagName!="TD"&&(r=$(r).parents("td")[0]),i=parseInt($(r).attr("col"))),f=this.trigger({phase:"before",target:this.name,type:"dblClick",recid:n,column:i,originalEvent:t}),f.isCancelled===!0)return!1;this.selectNone(),u=this.columns[i],u&&$.isPlainObject(u.editable)?this.editField(n,i,null,t):(this.select({recid:n,column:i}),this.last.selected=this.getSelection()),this.trigger($.extend(f,{phase:"after"}))},toggle:function(n){var t=this.get(n);return t.expanded===!0?this.collapse(n):this.expand(n)},expand:function(n){function u(){var r=$("#grid_"+i.name+"_rec_"+t+"_expanded"),u=$("#grid_"+i.name+"_rec_"+t+"_expanded_row .w2ui-expanded1 > div");r.height()<5||(r.css("opacity",1),u.show().css("opacity",1),$("#grid_"+i.name+"_cell_"+i.get(n,!0)+"_expand div").html("-"))}var e=this.get(n),i=this,t=w2utils.escapeId(n),o,f,r;return $("#grid_"+this.name+"_rec_"+t+"_expanded_row").length>0?!1:e.expanded=="none"?!1:(o=1+(this.show.selectColumn?1:0),f="",$("#grid_"+this.name+"_rec_"+t).after(''+(this.show.lineNumbers?' | ':"")+'\t | \t\t\t\t |
'),r=this.trigger({phase:"before",type:"expand",target:this.name,recid:n,box_id:"grid_"+this.name+"_rec_"+t+"_expanded",ready:u}),r.isCancelled===!0)?($("#grid_"+this.name+"_rec_"+t+"_expanded_row").remove(),!1):($("#grid_"+this.name+"_rec_"+t).attr("expanded","yes").addClass("w2ui-expanded"),$("#grid_"+this.name+"_rec_"+t+"_expanded_row").show(),$("#grid_"+this.name+"_cell_"+this.get(n,!0)+"_expand div").html(''),e.expanded=!0,setTimeout(u,300),this.trigger($.extend(r,{phase:"after"})),this.resizeRecords(),!0)},collapse:function(n){var u=this.get(n),i=this,t=w2utils.escapeId(n),r;return $("#grid_"+this.name+"_rec_"+t+"_expanded_row").length==0?!1:(r=this.trigger({phase:"before",type:"collapse",target:this.name,recid:n,box_id:"grid_"+this.name+"_rec_"+t+"_expanded"}),r.isCancelled===!0)?!1:($("#grid_"+this.name+"_rec_"+t).removeAttr("expanded").removeClass("w2ui-expanded"),$("#grid_"+this.name+"_rec_"+t+"_expanded").css("opacity",0),$("#grid_"+this.name+"_cell_"+this.get(n,!0)+"_expand div").html("+"),setTimeout(function(){$("#grid_"+i.name+"_rec_"+t+"_expanded").height("0px"),setTimeout(function(){$("#grid_"+i.name+"_rec_"+t+"_expanded_row").remove(),delete u.expanded,i.trigger($.extend(r,{phase:"after"})),i.resizeRecords()},300)},200),!0)},sort:function(n,t,i){var f=this.trigger({phase:"before",type:"sort",target:this.name,field:n,direction:t,multiField:i}),r,u,e;if(f.isCancelled===!0)return!1;if(typeof n!="undefined"){r=this.sortData.length;for(u in this.sortData)if(this.sortData[u].field==n){r=u;break}if(typeof t=="undefined"||t==null)if(typeof this.sortData[r]=="undefined")t="asc";else switch(String(this.sortData[r].direction)){case"asc":t="desc";break;case"desc":t="asc";break;default:t="asc"}this.multiSort===!1&&(this.sortData=[],r=0),i!=!0&&(this.sortData=[],r=0),typeof this.sortData[r]=="undefined"&&(this.sortData[r]={}),this.sortData[r].field=n,this.sortData[r].direction=t}else this.sortData=[];e=typeof this.url!="object"?this.url:this.url.get,e?(this.trigger($.extend(f,{phase:"after"})),this.last.xhr_offset=0,this.reload()):(this.localSort(),this.searchData.length>0&&this.localSearch(!0),this.trigger($.extend(f,{phase:"after"})),this.refresh())},copy:function(){var t=this.getSelection(),n,c,i,f,r,o,e;if(t.length==0)return"";if(n="",typeof t[0]=="object"){var s=t[0].column,h=t[0].column,u=[];for(i in t)t[i].columnh&&(h=t[i].column),u.indexOf(t[i].index)==-1&&u.push(t[i].index);u.sort();for(c in u){for(f=u[c],r=s;r<=h;r++)(o=this.columns[r],o.hidden!==!0)&&(n+=w2utils.stripTags(this.getCellHTML(f,r))+"\t");n=n.substr(0,n.length-1),n+="\n"}}else for(i in t){f=this.get(t[i],!0);for(r in this.columns)(o=this.columns[r],o.hidden!==!0)&&(n+=w2utils.stripTags(this.getCellHTML(f,r))+"\t");n=n.substr(0,n.length-1),n+="\n"}return(n=n.substr(0,n.length-1),e=this.trigger({phase:"before",type:"copy",target:this.name,text:n}),e.isCancelled===!0)?"":(n=e.text,this.trigger($.extend(e,{phase:"after"})),n)},paste:function(n){var e=this.getSelection(),o=this.get(e[0].recid,!0),u=e[0].column,i=this.trigger({phase:"before",type:"paste",target:this.name,text:n,index:o,column:u}),s,n,a,l,c,h;if(i.isCancelled!==!0){if(n=i.text,this.selectType=="row"||e.length==0){console.log("ERROR: You can paste only if grid.selectType = 'cell' and when at least one cell selected."),this.trigger($.extend(i,{phase:"after"}));return}s=[],n=n.split("\n");for(a in n){var v=n[a].split("\t"),r=0,t=this.records[o],f=[];for(l in v)this.columns[u+r]&&(c=this.columns[u+r].field,t.changed=!0,t.changes=t.changes||{},t.changes[c]=v[l],f.push(u+r),r++);for(h in f)s.push({recid:t.recid,column:f[h]});o++}this.selectNone(),this.select.apply(this,s),this.refresh(),this.trigger($.extend(i,{phase:"after"}))}},resize:function(){var t=this,i=+new Date,n;if(window.getSelection&&window.getSelection().removeAllRanges(),this.box&&$(this.box).attr("name")==this.name)return($(this.box).find("> div").css("width",$(this.box).width()).css("height",$(this.box).height()),n=this.trigger({phase:"before",type:"resize",target:this.name}),n.isCancelled===!0)?!1:(t.resizeBoxes(),t.resizeRecords(),this.trigger($.extend(n,{phase:"after"})),+new Date-i)},refresh:function(){var n=this,h=+new Date,c=typeof this.url!="object"?this.url:this.url.get,o,u,t,r,f,i,e,s;if(this.total<=0&&!c&&this.searchData.length==0&&(this.total=this.records.length,this.buffered=this.total),window.getSelection&&window.getSelection().removeAllRanges(),this.toolbar.disable("edit","delete"),this.box){if(o=this.trigger({phase:"before",target:this.name,type:"refresh"}),o.isCancelled===!0)return!1;this.show.header?$("#grid_"+this.name+"_header").html(this.header+" ").show():$("#grid_"+this.name+"_header").hide(),this.show.toolbar?this.toolbar&&this.toolbar.get("column-on-off")&&this.toolbar.get("column-on-off").checked||($("#grid_"+this.name+"_toolbar").show(),typeof this.toolbar=="object"&&(this.toolbar.refresh(),t=$("#grid_"+n.name+"_search_all"),t.val(this.last.search))):$("#grid_"+this.name+"_toolbar").hide(),this.searchClose(),u=$("#grid_"+n.name+"_search_all"),this.searches.length==0&&(this.last.field="all"),!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(i in this.searches)this.searches[i].field==this.last.field&&(this.last.caption=this.searches[i].caption);if(this.last.multi?u.attr("placeholder","["+w2utils.lang("Multiple Fields")+"]"):u.attr("placeholder",this.last.caption),this._focus_when_refreshed===!0&&(clearTimeout(n._focus_timer),n._focus_timer=setTimeout(function(){u.length>0&&u[0].focus(),delete n._focus_when_refreshed,delete n._focus_timer},600)),t=this.find({summary:!0},!0),t.length>0){for(r in t)this.summary.push(this.records[t[r]]);for(r=t.length-1;r>=0;r--)this.records.splice(t[r],1);this.total=this.total-t.length,this.buffered=this.buffered-t.length}if(f="",f+='"+this.getRecordsHTML()+'
\t
'+this.getColumnsHTML()+"
",$("#grid_"+this.name+"_body").html(f),this.summary.length>0?$("#grid_"+this.name+"_summary").html(this.getSummaryHTML()).show():$("#grid_"+this.name+"_summary").hide(),this.show.footer?$("#grid_"+this.name+"_footer").html(this.getFooterHTML()).show():$("#grid_"+this.name+"_footer").hide(),this.last.selected.length>0)for(i in this.last.selected)this.get(this.last.selected[i])!=null&&this.select(this.get(this.last.selected[i]).recid);this.searchData.length>0?$("#grid_"+this.name+"_searchClear").show():$("#grid_"+this.name+"_searchClear").hide(),$("#grid_"+this.name+"_check_all").prop("checked",!0),$("#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",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),e=n.find({expanded:!0},!0);for(s in e)n.records[e[s]].expanded=!1;return setTimeout(function(){var t=$.trim($("#grid_"+n.name+"_search_all").val());t!=""&&$(n.box).find(".w2ui-grid-data > div").w2marker(t)},50),this.trigger($.extend(o,{phase:"after"})),n.resize(),n.addRange("selection"),setTimeout(function(){n.resize(),n.scroll()},1),+new Date-h}},render:function(n){function e(n){if(!t.last.move||t.last.move.type!="expand"){t.last.move={x:n.screenX,y:n.screenY,divX:0,divY:0,recid:$(n.target).parents("tr").attr("recid"),column:n.target.tagName=="TD"?$(n.target).attr("col"):$(n.target).parents("td").attr("col"),type:"select",start:!0};$(document).on("mousemove",r);$(document).on("mouseup",u)}}function r(n){var i,y,o,v,u,s,r,e,f;if(t.last.move&&t.last.move.type=="select"&&(t.last.move.divX=n.screenX-t.last.move.x,t.last.move.divY=n.screenY-t.last.move.y,!(Math.abs(t.last.move.divX)<=1)||!(Math.abs(t.last.move.divY)<=1))&&(t.last.move.start&&t.last.move.recid&&(t.selectNone(),t.last.move.start=!1),i=[],y=n.target.tagName=="TR"?$(n.target).attr("recid"):$(n.target).parents("tr").attr("recid"),typeof y!="undefined")){var h=t.get(t.last.move.recid,!0),l=t.get(y,!0),a=parseInt(t.last.move.column),c=parseInt(n.target.tagName=="TD"?$(n.target).attr("col"):$(n.target).parents("td").attr("col"));if(h>l&&(u=h,h=l,l=u),u="ind1:"+h+",ind2;"+l+",col1:"+a+",col2:"+c,t.last.move.range!=u){for(t.last.move.range=u,o=h;o<=l;o++)if(!(t.last.searchIds.length>0)||t.last.searchIds.indexOf(o)!=-1)if(t.selectType!="row")for(a>c&&(u=a,a=c,c=u),u=[],v=a;v<=c;v++)t.columns[v].hidden||i.push({recid:t.records[o].recid,column:parseInt(v)});else i.push(t.records[o].recid);if(t.selectType!="row"){r=t.getSelection(),u=[];for(e in i){s=!1;for(f in r)i[e].recid==r[f].recid&&i[e].column==r[f].column&&(s=!0);s||u.push({recid:i[e].recid,column:i[e].column})}t.select.apply(t,u),u=[];for(f in r){s=!1;for(e in i)i[e].recid==r[f].recid&&i[e].column==r[f].column&&(s=!0);s||u.push({recid:r[f].recid,column:r[f].column})}t.unselect.apply(t,u)}else if(t.multiSelect){r=t.getSelection();for(e in i)r.indexOf(i[e])==-1&&t.select(i[e]);for(f in r)i.indexOf(r[f])==-1&&t.unselect(r[f])}}}}function u(){t.last.move&&t.last.move.type=="select"&&(delete t.last.move,$(document).off("mousemove",r),$(document).off("mouseup",u))}var t=this,f=+new Date,i;if(window.getSelection&&window.getSelection().removeAllRanges(),typeof n!="undefined"&&n!=null&&($(this.box).find("#grid_"+this.name+"_body").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html(""),this.box=n),this.box){if(this.last.sortData==null&&(this.last.sortData=this.sortData),i=this.trigger({phase:"before",target:this.name,type:"render",box:n}),i.isCancelled===!0)return!1;$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-grid").html(''),this.selectType!="row"&&$(this.box).addClass("w2ui-ss"),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),this.initToolbar(),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",e);$(this.box).on("selectstart",function(){return!1});if(this.trigger($.extend(i,{phase:"after"})),$(".w2ui-layout").length==0){this.tmp_resize=function(){w2ui[t.name].resize()};$(window).off("resize",this.tmp_resize).on("resize",this.tmp_resize)}return+new Date-f}},destroy:function(){var n=this.trigger({phase:"before",target:this.name,type:"destroy"});if(n.isCancelled===!0)return!1;$(window).off("resize",this.tmp_resize),typeof this.toolbar=="object"&&this.toolbar.destroy&&this.toolbar.destroy(),$(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(n,{phase:"after"}))},initColumnOnOff:function(){var i,n,t,r,u;if(this.show.toolbarColumns){i=this,n='",this.toolbar.get("column-on-off").html=n}},columnOnOff:function(n,t,i,r){var h=this.trigger({phase:"before",target:this.name,type:"columnOnOff",checkbox:n,field:i,originalEvent:t}),o,s,e,u,f;if(h.isCancelled===!0)return!1;o=this;for(s in this.records)this.records[s].expanded===!0&&(this.records[s].expanded=!1);if(e=!0,i=="line-numbers")this.show.lineNumbers=!this.show.lineNumbers,this.refresh();else if(i=="skip")w2utils.isInt(r)||(r=0),o.skip(r);else if(i=="resize"){for(u in this.columns)typeof this.columns[u].sizeOriginal!="undefined"&&(this.columns[u].size=this.columns[u].sizeOriginal);this.initResize(),this.resize()}else f=this.getColumn(i),f.hidden?($(n).prop("checked",!0),this.showColumn(f.field)):($(n).prop("checked",!1),this.hideColumn(f.field)),e=!1;this.initColumnOnOff(),e&&setTimeout(function(){$().w2overlay(),o.toolbar.uncheck("column-on-off")},100),this.trigger($.extend(h,{phase:"after"}))},initToolbar:function(){var t,i,r,n;if(typeof this.toolbar.render=="undefined"){t=this.toolbar.items,this.toolbar.items=[],this.toolbar=$().w2toolbar($.extend(!0,{},this.toolbar,{name:this.name+"_toolbar",owner:this})),this.show.toolbarReload&&this.toolbar.items.push($.extend(!0,{},this.buttons.reload)),this.show.toolbarColumns&&(this.toolbar.items.push($.extend(!0,{},this.buttons.columns)),this.initColumnOnOff()),(this.show.toolbarReload||this.show.toolbarColumn)&&this.toolbar.items.push({type:"break",id:"break0"}),this.show.toolbarSearch&&(i='",this.toolbar.items.push({type:"html",id:"search",html:i}),this.multiSearch&&this.searches.length>0&&this.toolbar.items.push($.extend(!0,{},this.buttons["search-go"]))),this.show.toolbarSearch&&(this.show.toolbarAdd||this.show.toolbarEdit||this.show.toolbarDelete||this.show.toolbarSave)&&this.toolbar.items.push({type:"break",id:"break1"}),this.show.toolbarAdd&&this.toolbar.items.push($.extend(!0,{},this.buttons.add)),this.show.toolbarEdit&&this.toolbar.items.push($.extend(!0,{},this.buttons.edit)),this.show.toolbarDelete&&this.toolbar.items.push($.extend(!0,{},this.buttons["delete"])),this.show.toolbarSave&&((this.show.toolbarAdd||this.show.toolbarDelete||this.show.toolbarEdit)&&this.toolbar.items.push({type:"break",id:"break2"}),this.toolbar.items.push($.extend(!0,{},this.buttons.save)));for(r in t)this.toolbar.items.push(t[r]);n=this;this.toolbar.on("click",function(t){var i=n.trigger({phase:"before",type:"toolbar",target:t.target,originalEvent:t}),r,s,h,u,f,c,e,o;if(i.isCancelled===!0)return!1;r=t.target;switch(r){case"reload":if(s=n.trigger({phase:"before",type:"reload",target:n.name}),s.isCancelled===!0)return!1;h=typeof n.url!="object"?n.url:n.url.get,h?n.clear(!0):(n.last.scrollTop=0,n.last.scrollLeft=0,n.last.range_start=null,n.last.range_end=null),n.reload(),n.trigger($.extend(s,{phase:"after"}));break;case"column-on-off":for(u in n.columns)n.columns[u].hidden?$("#grid_"+n.name+"_column_"+u+"_check").prop("checked",!1):$("#grid_"+n.name+"_column_"+u+"_check").prop("checked",!0);n.initResize(),n.resize();break;case"search-advanced":if(f=this,c=this.get(r),c.checked)n.searchClose(),setTimeout(function(){f.uncheck(r)},1);else{n.searchOpen(),t.originalEvent.stopPropagation();function l(){f.uncheck(r),$(document).off("click","body",l)}$(document).on("click","body",l)}break;case"add":i=n.trigger({phase:"before",target:n.name,type:"add",recid:null}),n.trigger($.extend(i,{phase:"after"}));break;case"edit":e=n.getSelection(),o=null,e.length==1&&(o=e[0]),i=n.trigger({phase:"before",target:n.name,type:"edit",recid:o}),n.trigger($.extend(i,{phase:"after"}));break;case"delete":n.delete();break;case"save":n.save()}n.trigger($.extend(i,{phase:"after"}))})}return},initSearches:function(){var o=this,t,n,r,e,i,u,f;for(t in this.searches){n=this.searches[t],r=this.getSearchData(n.field);switch(String(n.type).toLowerCase()){case"alphaNumeric":case"text":$("#grid_"+this.name+"_operator_"+t).val("begins with");break;case"int":case"float":case"hex":case"money":case"date":$("#grid_"+this.name+"_field_"+t).w2field("clear").w2field(n.type),$("#grid_"+this.name+"_field2_"+t).w2field("clear").w2field(n.type);break;case"list":e='';for(i in n.items)$.isPlainObject(n.items[i])?(u=n.items[i].id,f=n.items[i].text,typeof u=="undefined"&&typeof n.items[i].value!="undefined"&&(u=n.items[i].value),typeof f=="undefined"&&typeof n.items[i].caption!="undefined"&&(f=n.items[i].caption),u==null&&(u=""),e+='"):e+='";$("#grid_"+this.name+"_field_"+t).html(e)}r!=null&&($("#grid_"+this.name+"_operator_"+t).val(r.operator).trigger("change"),$.isArray(r.value)?r.operator=="in"?$("#grid_"+this.name+"_field_"+t).val(r.value).trigger("change"):($("#grid_"+this.name+"_field_"+t).val(r.value[0]).trigger("change"),$("#grid_"+this.name+"_field2_"+t).val(r.value[1]).trigger("change")):typeof r.value!="udefined"&&$("#grid_"+this.name+"_field_"+t).val(r.value).trigger("change"))}$("#w2ui-overlay .w2ui-grid-searches *[rel=search]").on("keypress",function(n){n.keyCode==13&&o.search()})},initResize:function(){var n=this;$(this.box).find(".w2ui-resizer").off("click").on("click",function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0,n.preventDefault&&n.preventDefault()}).off("mousedown").on("mousedown",function(t){var r,i,f,u;t||(t=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),n.resizing=!0,n.last.tmp={x:t.screenX,y:t.screenY,gx:t.screenX,gy:t.screenY,col:parseInt($(this).attr("name"))},t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault&&t.preventDefault();for(r in n.columns)typeof n.columns[r].sizeOriginal=="undefined"&&(n.columns[r].sizeOriginal=n.columns[r].size),n.columns[r].size=n.columns[r].sizeCalculated;i={phase:"before",type:"columnResize",target:n.name,column:n.last.tmp.col,field:n.columns[n.last.tmp.col].field},i=n.trigger($.extend(i,{resizeBy:0,originalEvent:t})),f=function(t){if(n.resizing==!0){if(t||(t=window.event),i=n.trigger($.extend(i,{resizeBy:t.screenX-n.last.tmp.gx,originalEvent:t})),i.isCancelled===!0){i.isCancelled=!1;return}n.last.tmp.x=t.screenX-n.last.tmp.x,n.last.tmp.y=t.screenY-n.last.tmp.y,n.columns[n.last.tmp.col].size=parseInt(n.columns[n.last.tmp.col].size)+n.last.tmp.x+"px",n.resizeRecords(),n.last.tmp.x=t.screenX,n.last.tmp.y=t.screenY}},u=function(t){delete n.resizing,$(document).off("mousemove","body"),$(document).off("mouseup","body"),n.resizeRecords(),n.trigger($.extend(i,{phase:"after",originalEvent:t}))};$(document).on("mousemove","body",f);$(document).on("mouseup","body",u)}).each(function(n,t){var i=$(t).parent();$(t).css({height:"25px","margin-left":i.width()-3+"px"})})},resizeBoxes:function(){var o=$(this.box).find("> div"),n=$("#grid_"+this.name+"_header"),i=$("#grid_"+this.name+"_toolbar"),r=$("#grid_"+this.name+"_summary"),t=$("#grid_"+this.name+"_footer"),u=$("#grid_"+this.name+"_body"),e=$("#grid_"+this.name+"_columns"),f=$("#grid_"+this.name+"_records");this.show.header&&n.css({top:"0px",left:"0px",right:"0px"}),this.show.toolbar&&i.css({top:0+(this.show.header?w2utils.getSize(n,"height"):0)+"px",left:"0px",right:"0px"}),this.show.footer&&t.css({bottom:"0px",left:"0px",right:"0px"}),this.summary.length>0&&r.css({bottom:0+(this.show.footer?w2utils.getSize(t,"height"):0)+"px",left:"0px",right:"0px"}),u.css({top:0+(this.show.header?w2utils.getSize(n,"height"):0)+(this.show.toolbar?w2utils.getSize(i,"height"):0)+"px",bottom:0+(this.show.footer?w2utils.getSize(t,"height"):0)+(this.summary.length>0?w2utils.getSize(r,"height"):0)+"px",left:"0px",right:"0px"})},resizeRecords:function(){var i=this,rt,c,h,d,y,e,s,b,u,t,n;$(this.box).find(".w2ui-empty-record").remove();var g=$(this.box),v=$(this.box).find("> div"),nt=$("#grid_"+this.name+"_header"),tt=$("#grid_"+this.name+"_toolbar"),a=$("#grid_"+this.name+"_summary"),it=$("#grid_"+this.name+"_footer"),l=$("#grid_"+this.name+"_body"),r=$("#grid_"+this.name+"_columns"),f=$("#grid_"+this.name+"_records");if(this.fixedBody?(rt=v.height()-(this.show.header?w2utils.getSize(nt,"height"):0)-(this.show.toolbar?w2utils.getSize(tt,"height"):0)-(a.css("display")!="none"?w2utils.getSize(a,"height"):0)-(this.show.footer?w2utils.getSize(it,"height"):0),l.css("height",rt)):setTimeout(function(){var n=w2utils.getSize(r,"height")+w2utils.getSize($("#grid_"+i.name+"_records table"),"height");i.height=n+w2utils.getSize(v,"+height")+(i.show.header?w2utils.getSize(nt,"height"):0)+(i.show.toolbar?w2utils.getSize(tt,"height"):0)+(a.css("display")!="none"?w2utils.getSize(a,"height"):0)+(i.show.footer?w2utils.getSize(it,"height"):0),v.css("height",i.height),l.css("height",n),g.css("height",w2utils.getSize(v,"height")+w2utils.getSize(g,"+height"))},1),c=!1,h=!1,l.width()<$(f).find(">table").width()&&(c=!0),l.height()-r.height()<$(f).find(">table").height()+(c?w2utils.scrollBarSize():0)&&(h=!0),this.fixedBody||(h=!1,c=!1),c||h?(r.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show(),f.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(r,"height")+"px","-webkit-overflow-scrolling":"touch","overflow-x":c?"auto":"hidden","overflow-y":h?"auto":"hidden"})):(r.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").hide(),f.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(r,"height")+"px",overflow:"hidden"}),f.length>0&&(this.last.scrollTop=0,this.last.scrollLeft=0)),this.show.emptyRecords&&!h&&(d=Math.floor(f.height()/this.recordHeight)+1,this.fixedBody))for(y=this.buffered;y<=d;y++){for(e="",e+='',this.show.lineNumbers&&(e+=' | '),this.show.selectColumn&&(e+=' | '),this.show.expandColumn&&(e+=' | '),s=0;!0&&this.columns.length>0;){if(n=this.columns[s],n.hidden)if(s++,typeof this.columns[s]=="undefined")break;else continue;if(e+=' | ',s++,typeof this.columns[s]=="undefined")break}e+=' | ',e+="
",$("#grid_"+this.name+"_records > table").append(e)}if(l.length>0){var p=parseInt(l.width())-(h?w2utils.scrollBarSize():0)-(this.show.lineNumbers?34:0)-(this.show.selectColumn?26:0)-(this.show.expandColumn?26:0),k=p,o=0,w=!1;for(t=0;tk&&n.hidden!==!0&&(n.hidden=!0,w=!0),n.gridMinWidth0)for(t=0;tparseInt(n.max)&&(n.sizeCalculated=n.max+"px"),b+=parseInt(n.sizeCalculated));if(u=parseInt(k)-parseInt(b),u>0&&o>0)for(t=0;;){if(n=this.columns[t],typeof n=="undefined"){t=0;continue}if(n.hidden||n.sizeType=="px"){t++;continue}if(n.sizeCalculated=parseInt(n.sizeCalculated)+1+"px",u--,u==0)break;t++}else u>0&&r.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show();r.find("> table > tbody > tr:nth-child(1) td").each(function(n,t){var r=$(t).attr("col");typeof r!="undefined"&&i.columns[r]&&$(t).css("width",i.columns[r].sizeCalculated),$(t).hasClass("w2ui-head-last")&&$(t).css("width",w2utils.scrollBarSize()+(u>0&&o==0?u:0)+"px")}),r.find("> table > tbody > tr").length==3&&r.find("> table > tbody > tr:nth-child(1) td").html("").css({height:"0px",border:"0px",padding:"0px",margin:"0px"}),f.find("> table > tbody > tr:nth-child(1) td").each(function(n,t){var r=$(t).attr("col");typeof r!="undefined"&&i.columns[r]&&$(t).css("width",i.columns[r].sizeCalculated),$(t).hasClass("w2ui-grid-data-last")&&$(t).css("width",(u>0&&o==0?u:0)+"px")}),a.find("> table > tbody > tr:nth-child(1) td").each(function(n,t){var r=$(t).attr("col");typeof r!="undefined"&&i.columns[r]&&$(t).css("width",i.columns[r].sizeCalculated),$(t).hasClass("w2ui-grid-data-last")&&$(t).css("width",w2utils.scrollBarSize()+(u>0&&o==0?u:0)+"px")}),this.initResize(),this.refreshRanges(),this.last.scrollTop!=""&&f.length>0&&(r.prop("scrollLeft",this.last.scrollLeft),f.prop("scrollTop",this.last.scrollTop),f.prop("scrollLeft",this.last.scrollLeft))},getSearchesHTML:function(){for(var i='',f=!1,n,u,r,t=0;t",f=!0),typeof n.inTag=="undefined"&&(n.inTag=""),typeof n.outTag=="undefined"&&(n.outTag=""),typeof n.type=="undefined"&&(n.type="text"),n.type=="text"&&(r='"),(n.type=="int"||n.type=="float"||n.type=="date")&&(r='"),n.type=="list"&&(r='is '),i+='\t'+u+' | \t'+n.caption+' | \t'+r+' | \t';switch(n.type){case"alphaNumeric":case"text":i+='";break;case"int":case"float":case"hex":case"money":case"date":i+=' - ";break;case"list":i+='"}i+=n.outTag+"\t |
"}return i+='\t\t\t \t\t\t\t\t\t \t |
'},getColumnsHTML:function(){function r(){var i="",u,f,t,r,e,o,s;for(n.columnGroups[n.columnGroups.length-1].caption!=""&&n.columnGroups.push({caption:""}),n.show.lineNumbers&&(i+='\t | '),n.show.selectColumn&&(i+='\t | '),n.show.expandColumn&&(i+='\t | '),u=0,f=0;f'),i+='"+s+'\t '+(r.caption==""?" ":r.caption)+"\t | "}else i+='\t '+(t.caption==""?" ":t.caption)+"\t | ";u+=t.span}return i+="
"}function t(t){var u="",f,s,r,i,c,e,o,h;for(n.show.lineNumbers&&(u+='\t # | "),n.show.selectColumn&&(u+='\t \t\t\t | "),n.show.expandColumn&&(u+='\t | '),f=0,s=0,r=0;r'),u+='"+h+'\t '+(i.caption==""?" ":i.caption)+"\t | ")}return u+=' | ',u+="
"}var n=this,i="";return this.show.columnHeaders&&(i=this.columnGroups.length>0?t(!0)+r()+t(!1):t(!0)),i},getRecordsHTML:function(){var r,i,n,t;for(this.show_extra=this.buffered>300?30:300,r=$("#grid_"+this.name+"_records"),i=Math.floor(r.height()/this.recordHeight)+this.show_extra+1,this.fixedBody||(i=this.buffered),n=""+this.getRecordHTML(-1,0),n+='\t |
',t=0;t\t | \t |
',this.last.range_start=0,this.last.range_end=i,n},getSummaryHTML:function(){var t,n;if(this.summary.length!=0){for(t="",n=0;n"}},scroll:function(){function d(){i.markSearchResults!==!1&&(clearTimeout(i.last.marker_timer),i.last.marker_timer=setTimeout(function(){var n=[],r,t;for(r in i.searchData)t=i.searchData[r],$.inArray(t.value,n)==-1&&n.push(t.value);n.length>0&&$(i.box).find(".w2ui-grid-data > div").w2marker(n)},50))}var nt=+new Date,i=this,t=$("#grid_"+this.name+"_records"),l,v,p,f,e,h,s,y,k,u,o,r,g,a,b,w,c;if(this.records.length!=0&&t.length!=0&&t.height()!=0){if(this.show_extra=this.buffered>300?30:300,t.height()0&&this.refresh();return}if(l=Math.floor(t[0].scrollTop/this.recordHeight+1),v=Math.floor(t[0].scrollTop/this.recordHeight+1)+Math.round(t.height()/this.recordHeight),l>this.buffered&&(l=this.buffered),v>this.buffered&&(v=this.buffered),p=typeof this.url!="object"?this.url:this.url.get,$("#grid_"+this.name+"_footer .w2ui-footer-right").html(w2utils.formatNumber(this.offset+l)+"-"+w2utils.formatNumber(this.offset+v)+" "+w2utils.lang("of")+" "+w2utils.formatNumber(this.total)+(p?" ("+w2utils.lang("buffered")+" "+w2utils.formatNumber(this.buffered)+(this.offset>0?", skip "+w2utils.formatNumber(this.offset):"")+")":"")),p||this.fixedBody&&!(this.total<=300)){if(f=Math.floor(t[0].scrollTop/this.recordHeight)-this.show_extra,e=f+Math.floor(t.height()/this.recordHeight)+this.show_extra*2+1,f<1&&(f=1),e>this.total&&(e=this.total),h=t.find("#grid_"+this.name+"_rec_top"),s=t.find("#grid_"+this.name+"_rec_bottom"),String(h.next().prop("id")).indexOf("_expanded_row")!=-1&&h.next().remove(),String(s.prev().prop("id")).indexOf("_expanded_row")!=-1&&s.prev().remove(),y=parseInt(h.next().attr("line")),k=parseInt(s.prev().attr("line")),y=y-this.show_extra+2&&f>1)return;for(;;){if(u=t.find("#grid_"+this.name+"_rec_bottom").prev(),u.attr("line")=="top")break;if(parseInt(u.attr("line"))>e)u.remove();else break}for(u=t.find("#grid_"+this.name+"_rec_top").next(),o=u.attr("line"),o=="bottom"&&(o=e),r=parseInt(o)-1;r>=f;r--)this.records[r-1]&&(this.records[r-1].expanded===!0&&(this.records[r-1].expanded=!1),h.after(this.getRecordHTML(r-1,r)));d(),setTimeout(function(){i.refreshRanges()},0)}if(g=(f-1)*i.recordHeight,a=(this.buffered-e)*i.recordHeight,a<0&&(a=0),h.css("height",g+"px"),s.css("height",a+"px"),i.last.range_start=f,i.last.range_end=e,b=Math.floor(t[0].scrollTop/this.recordHeight),w=b+Math.floor(t.height()/this.recordHeight),w+10>this.buffered&&this.last.pull_more!==!0&&this.buffered'),i.last.pull_more=!0,i.last.xhr_offset+=i.limit,i.request("get-records")});c.find("td").text().indexOf("Load")==-1&&c.find("td").html("Load "+i.limit+" More...
")}this.buffered>=this.total-this.offset&&$("#grid_"+this.name+"_rec_more").hide();return}}},getRecordHTML:function(n,t,i){var r="",c,a,v,o,e,u,f,s,l;if(n==-1){r+='',this.show.lineNumbers&&(r+=' | '),this.show.selectColumn&&(r+=' | '),this.show.expandColumn&&(r+=' | ');for(c in this.columns)this.columns[c].hidden||(r+=' | ');return r+=' | ',r+="
"}if(a=typeof this.url!="object"?this.url:this.url.get,i!==!0)if(this.searchData.length>0&&!a){if(n>=this.last.searchIds.length)return"";n=this.last.searchIds[n],record=this.records[n]}else{if(n>=this.records.length)return"";record=this.records[n]}else{if(n>=this.summary.length)return"";record=this.summary[n]}if(!record)return"";for(v=w2utils.escapeId(record.recid),o=!1,record.selected&&this.selectType=="row"&&(o=!0),r+='",this.show.lineNumbers&&(r+=''+(i!==!0?" "+t+" ":"")+" | "),this.show.selectColumn&&(r+=''+(i!==!0?'\t \t\t\t ":"")+" | "),this.show.expandColumn&&(e="",e=record.expanded===!0?"-":"+",record.expanded=="none"&&(e=""),record.expanded=="spinner"&&(e=''),r+=''+(i!==!0?'\t \t\t"+e+" ":"")+" | "),u=0;;){if(f=this.columns[u],f.hidden)if(u++,typeof this.columns[u]=="undefined")break;else continue;var y=record.changed&&record.changes[f.field],p=this.getCellHTML(n,u,i),h="";if(typeof f.render=="string"&&(s=f.render.toLowerCase().split(":"),$.inArray(s[0],["number","int","float","money","percent"])!=-1&&(h="text-align: right"),$.inArray(s[0],["date"])!=-1&&(h="text-align: right")),l=!1,record.selected&&$.inArray(u,record.selectedColumns)!=-1&&(l=!0),r+='"+p+" | ",u++,typeof this.columns[u]=="undefined")break}return r+=' | ',r+="
"},getCellHTML:function(n,t,i){var f=this.columns[t],e=i!==!0?this.records[n]:this.summary[n],r=this.parseField(e,f.field),c=e.changed&&typeof e.changes[f.field]!="undefined",s;if(c&&(r=e.changes[f.field]),(r==null||typeof r=="undefined")&&(r=""),typeof f.render!="undefined"){if(typeof f.render=="function"&&(r=f.render.call(this,e,n,t),r.length>=4&&r.substr(0,4)!=""+r+"
")),typeof f.render=="object"&&(r=""+f.render[r]+"
"),typeof f.render=="string"){var u=f.render.toLowerCase().split(":"),h="",o="";$.inArray(u[0],["number","int","float","money","percent"])!=-1&&(typeof u[1]!="undefined"&&w2utils.isInt(u[1])||(u[1]=0),u[1]>20&&(u[1]=20),u[1]<0&&(u[1]=0),u[0]=="money"&&(u[1]=2,h=w2utils.settings.currencySymbol),u[0]=="percent"&&(o="%",u[1]!=="0"&&(u[1]=1)),u[0]=="int"&&(u[1]=0),r=""+h+w2utils.formatNumber(Number(r).toFixed(u[1]))+o+"
"),u[0]=="date"&&((typeof u[1]=="undefined"||u[1]=="")&&(u[1]=w2utils.settings.date_display),r=""+h+w2utils.formatDate(r,u[1])+o+"
"),u[0]=="age"&&(r=""+h+w2utils.age(r)+o+"
")}}else this.show.recordTitles?(s=String(r).replace(/"/g,"''"),typeof f.title!="undefined"&&(typeof f.title=="function"&&(s=f.title.call(this,e,n,t)),typeof f.title=="string"&&(s=f.title)),r=''+r+"
"):r=""+r+"
";return(r==null||typeof r=="undefined")&&(r=""),r},getFooterHTML:function(){return'\t\t\t
'},status:function(n){var r,t,i;typeof n!="undefined"?$("#grid_"+this.name+"_footer").find(".w2ui-footer-left").html(n):(r="",t=this.getSelection(),t.length>0&&(r=String(t.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1,")+" "+w2utils.lang("selected"),i=t[0],typeof i=="object"&&(i=i.recid+", "+w2utils.lang("Column")+": "+i.column),t.length==1&&(r=w2utils.lang("Record ID")+": "+i+" ")),$("#grid_"+this.name+"_footer .w2ui-footer-left").html(r),t.length==1?this.toolbar.enable("edit"):this.toolbar.disable("edit"),t.length>=1?this.toolbar.enable("delete"):this.toolbar.disable("delete"))},lock:function(n,t){var i=$(this.box).find("> div:first-child");setTimeout(function(){w2utils.lock(i,n,t)},10)},unlock:function(){var n=this.box;setTimeout(function(){w2utils.unlock(n)},25)},parseField:function(n,t){var i="",r,u;try{i=n,r=String(t).split(".");for(u in r)i=i[r[u]]}catch(f){i=""}return i}},$.extend(w2grid.prototype,w2utils.event),w2obj.grid=w2grid}(jQuery),function(n){var t=function(t){this.box=null,this.name=null,this.panels=[],this.tmp={},this.padding=1,this.resizer=4,this.style="",this.onShow=null,this.onHide=null,this.onResizing=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,n.extend(!0,this,w2obj.layout,t)};n.fn.w2layout=function(i){function s(t,i,r){var u=t.get(i);return(u!=null&&typeof r=="undefined"&&(r=u.tabs),u==null||r==null)?!1:(n.isArray(r)&&(r={tabs:r}),n().w2destroy(t.name+"_"+i+"_tabs"),u.tabs=n().w2tabs(n.extend({},r,{owner:t,name:t.name+"_"+i+"_tabs"})),u.show.tabs=!0,!0)}function o(t,i,r){var u=t.get(i);return(u!=null&&typeof r=="undefined"&&(r=u.toolbar),u==null||r==null)?!1:(n.isArray(r)&&(r={items:r}),n().w2destroy(t.name+"_"+i+"_toolbar"),u.toolbar=n().w2toolbar(n.extend({},r,{owner:t,name:t.name+"_"+i+"_toolbar"})),u.show.toolbar=!0,!0)}var f,r,u,e;if(typeof i!="object"&&i){if(w2ui[n(this).attr("name")])return e=w2ui[n(this).attr("name")],e[i].apply(e,Array.prototype.slice.call(arguments,1)),this;console.log("ERROR: Method "+i+" does not exist on jQuery.w2layout")}else{if(!i||typeof i.name=="undefined"){console.log('ERROR: The parameter "name" is required but not supplied in $().w2layout().');return}if(typeof w2ui[i.name]!="undefined"){console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+i.name+").");return}if(!w2utils.isAlphaNumeric(i.name)){console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). ');return}f=i.panels,r=new t(i),n.extend(r,{handlers:[],panels:[]});for(u in f)r.panels[u]=n.extend(!0,{},t.prototype.panel,f[u]),(n.isPlainObject(r.panels[u].tabs)||n.isArray(r.panels[u].tabs))&&s(r,f[u].type),(n.isPlainObject(r.panels[u].toolbar)||n.isArray(r.panels[u].toolbar))&&o(r,f[u].type);for(u in{top:"",left:"",main:"",preview:"",right:"",bottom:""})r.get(u)==null&&(r.panels[u]=n.extend(!0,{},t.prototype.panel,{type:u,hidden:!0,size:50}));return n(this).length>0&&r.render(n(this)[0]),w2ui[r.name]=r,r}},t.prototype={panel:{type:null,size:100,minSize:20,hidden:!1,resizable:!1,overflow:"auto",style:"",content:"",tabs:null,toolbar:null,width:null,height:null,show:{toolbar:!1,tabs:!1},onRefresh:null,onShow:null,onHide:null},html:function(n,t,i){return this.content(n,t,i)},content:function(t,i,r){var s=this,u=this.get(t),o,h,c,e,f;return t=="css"?(n("#layout_"+s.name+"_panel_css").html(""),!0):u==null?!1:n("#layout_"+this.name+"_panel2_"+u.type).length>0?!1:(n("#layout_"+this.name+"_panel_"+u.type).scrollTop(0),i==null||typeof i=="undefined")?u.content:i instanceof jQuery?(console.log("ERROR: You can not pass jQuery object to w2layout.content() method"),!1):(o=n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-content"),h=n(o).position().top,o.attr("class","w2ui-panel-content"),o.length>0&&typeof u.style!="undefined"&&(o[0].style.cssText=u.style),u.content==""?(u.content=i,u.hidden||this.refresh(t)):(u.content=i,u.hidden||(r!=null&&r!=""&&typeof r!="undefined"?(c="layout_"+this.name+"_panel_"+u.type,e=n("#"+c+" > .w2ui-panel-content"),e.after(''),f=n("#"+c+" > .w2ui-panel-content.new-panel"),e.css("top",h),f.css("top",h),typeof i=="object"?(i.box=f[0],i.render()):f.html(i),w2utils.transition(e[0],f[0],r,function(){e.remove(),f.removeClass("new-panel"),f.css("overflow",u.overflow),window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){s.resize()},100)})):u.hidden||this.refresh(t))),window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){s.resize()},100),!0)},load:function(t,i,r,u){var f=this;return t=="css"?(n.get(i,function(n,i,r){f.content(t,r.responseText),u&&u()}),!0):this.get(t)!=null?(n.get(i,function(n,i,e){f.content(t,e.responseText,r),u&&u(),window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){f.resize()},100)}),!0):!1},sizeTo:function(t,i){var r=this,u=r.get(t);return u==null?!1:(n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":".35s","-moz-transition":".35s","-ms-transition":".35s","-o-transition":".35s"}),setTimeout(function(){r.set(t,{size:i})},1),setTimeout(function(){n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s"}),r.resize()},500),!0)},show:function(t,i){var r=this,f=this.trigger({phase:"before",type:"show",target:t,object:this.get(t),immediate:i}),u;return f.isCancelled===!0?!1:(u=r.get(t),u==null)?!1:(u.hidden=!1,i===!0?(n("#layout_"+r.name+"_panel_"+t).css({opacity:"1"}),u.resizabled&&n("#layout_"+r.name+"_resizer_"+t).show(),r.trigger(n.extend(f,{phase:"after"})),r.resize()):(u.resizabled&&n("#layout_"+r.name+"_resizer_"+t).show(),n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s"}),setTimeout(function(){r.resize()},1),setTimeout(function(){n("#layout_"+r.name+"_panel_"+t).css({opacity:"1"})},250),setTimeout(function(){n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s"}),r.trigger(n.extend(f,{phase:"after"})),r.resize()},500)),!0)},hide:function(t,i){var r=this,f=this.trigger({phase:"before",type:"hide",target:t,object:this.get(t),immediate:i}),u;return f.isCancelled===!0?!1:(u=r.get(t),u==null)?!1:(u.hidden=!0,i===!0?(n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),n("#layout_"+r.name+"_resizer_"+t).hide(),r.trigger(n.extend(f,{phase:"after"})),r.resize()):(n("#layout_"+r.name+"_resizer_"+t).hide(),n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":".2s","-moz-transition":".2s","-ms-transition":".2s","-o-transition":".2s"}),n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),setTimeout(function(){r.resize()},1),setTimeout(function(){n(r.box).find(" > div .w2ui-panel").css({"-webkit-transition":"0s","-moz-transition":"0s","-ms-transition":"0s","-o-transition":"0s"}),r.trigger(n.extend(f,{phase:"after"})),r.resize()},500)),!0)},toggle:function(n,t){var i=this.get(n);return i==null?!1:i.hidden?this.show(n,t):this.hide(n,t)},set:function(t,i){var r=this.get(t,!0);return r==null?!1:(n.extend(this.panels[r],i),this.refresh(t),this.resize(),!0)},get:function(n,t){var r=null,i;for(i in this.panels)if(this.panels[i].type==n)return t===!0?i:this.panels[i];return null},el:function(t){var i=n("#layout_"+this.name+"_panel_"+t+" .w2ui-panel-content");return i.length!=1?null:i[0]},hideToolbar:function(t){var i=this.get(t);i&&(i.show.toolbar=!1,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-toolbar").hide(),this.resize())},showToolbar:function(t){var i=this.get(t);i&&(i.show.toolbar=!0,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-toolbar").show(),this.resize())},toggleToolbar:function(n){var t=this.get(n);t&&(t.show.toolbar?this.hideToolbar(n):this.showToolbar(n))},hideTabs:function(t){var i=this.get(t);i&&(i.show.tabs=!1,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-tabs").hide(),this.resize())},showTabs:function(t){var i=this.get(t);i&&(i.show.tabs=!0,n("#layout_"+this.name+"_panel_"+t+" > .w2ui-panel-tabs").show(),this.resize())},toggleTabs:function(n){var t=this.get(n);t&&(t.show.tabs?this.hideTabs(n):this.showTabs(n))},render:function(t){function a(){i.tmp.events={resize:function(){w2ui[i.name].resize()},resizeStart:c,mousemove:h,mouseup:s};n(window).on("resize",i.tmp.events.resize);n(document).on("mousemove",i.tmp.events.mousemove);n(document).on("mouseup",i.tmp.events.mouseup)}function c(t,r){i.box&&(r||(r=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),i.tmp.resize={type:t,x:r.screenX,y:r.screenY,div_x:0,div_y:0,value:0},(t=="left"||t=="right")&&(i.tmp.resize.value=parseInt(n("#layout_"+i.name+"_resizer_"+t)[0].style.left)),(t=="top"||t=="preview"||t=="bottom")&&(i.tmp.resize.value=parseInt(n("#layout_"+i.name+"_resizer_"+t)[0].style.top)))}function s(t){var u,f;if(i.box&&(t||(t=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),typeof i.tmp.resize!="undefined")){if(i.tmp.div_x!=0||i.tmp.resize.div_y!=0){var e=i.get("top"),o=i.get("bottom"),r=i.get(i.tmp.resize.type),h=parseInt(n(i.box).height()),c=parseInt(n(i.box).width()),s=String(r.size);switch(i.tmp.resize.type){case"top":u=parseInt(r.sizeCalculated)+i.tmp.resize.div_y,f=0;break;case"bottom":u=parseInt(r.sizeCalculated)-i.tmp.resize.div_y,f=0;break;case"preview":u=parseInt(r.sizeCalculated)-i.tmp.resize.div_y,f=(e&&!e.hidden?e.sizeCalculated:0)+(o&&!o.hidden?o.sizeCalculated:0);break;case"left":u=parseInt(r.sizeCalculated)+i.tmp.resize.div_x,f=0;break;case"right":u=parseInt(r.sizeCalculated)-i.tmp.resize.div_x,f=0}r.size=s.substr(s.length-1)=="%"?Math.floor(u*100/(r.type=="left"||r.type=="right"?c:h-f)*100)/100+"%":u,i.resize()}n("#layout_"+i.name+"_resizer_"+i.tmp.resize.type).removeClass("active"),delete i.tmp.resize}}function h(t){var f,u,r;if(i.box&&(t||(t=window.event),typeof i.tmp.resize!="undefined")){if(f=i.get(i.tmp.resize.type),u=i.trigger({phase:"before",type:"resizing",target:i.tmp.resize.type,object:f,originalEvent:t}),u.isCancelled===!0)return!1;r=n("#layout_"+i.name+"_resizer_"+i.tmp.resize.type),r.hasClass("active")||r.addClass("active"),i.tmp.resize.div_x=t.screenX-i.tmp.resize.x,i.tmp.resize.div_y=t.screenY-i.tmp.resize.y,i.tmp.resizing=="left"&&i.get("left").minSize-i.tmp.resize.div_x>i.get("left").width&&(i.tmp.resize.div_x=i.get("left").minSize-i.get("left").width),i.tmp.resize.type=="left"&&i.get("main").minSize+i.tmp.resize.div_x>i.get("main").width&&(i.tmp.resize.div_x=i.get("main").width-i.get("main").minSize),i.tmp.resize.type=="right"&&i.get("right").minSize+i.tmp.resize.div_x>i.get("right").width&&(i.tmp.resize.div_x=i.get("right").width-i.get("right").minSize),i.tmp.resize.type=="right"&&i.get("main").minSize-i.tmp.resize.div_x>i.get("main").width&&(i.tmp.resize.div_x=i.get("main").minSize-i.get("main").width),i.tmp.resize.type=="top"&&i.get("top").minSize-i.tmp.resize.div_y>i.get("top").height&&(i.tmp.resize.div_y=i.get("top").minSize-i.get("top").height),i.tmp.resize.type=="top"&&i.get("main").minSize+i.tmp.resize.div_y>i.get("main").height&&(i.tmp.resize.div_y=i.get("main").height-i.get("main").minSize),i.tmp.resize.type=="bottom"&&i.get("bottom").minSize+i.tmp.resize.div_y>i.get("bottom").height&&(i.tmp.resize.div_y=i.get("bottom").height-i.get("bottom").minSize),i.tmp.resize.type=="bottom"&&i.get("main").minSize-i.tmp.resize.div_y>i.get("main").height&&(i.tmp.resize.div_y=i.get("main").minSize-i.get("main").height),i.tmp.resize.type=="preview"&&i.get("preview").minSize+i.tmp.resize.div_y>i.get("preview").height&&(i.tmp.resize.div_y=i.get("preview").height-i.get("preview").minSize),i.tmp.resize.type=="preview"&&i.get("main").minSize-i.tmp.resize.div_y>i.get("main").height&&(i.tmp.resize.div_y=i.get("main").minSize-i.get("main").height);switch(i.tmp.resize.type){case"top":case"preview":case"bottom":i.tmp.resize.div_x=0,r.length>0&&(r[0].style.top=i.tmp.resize.value+i.tmp.resize.div_y+"px");break;case"left":case"right":i.tmp.resize.div_y=0,r.length>0&&(r[0].style.left=i.tmp.resize.value+i.tmp.resize.div_x+"px")}i.trigger(n.extend(u,{phase:"after"}))}}var i=this,o,f,r,u,l,e;if((window.getSelection&&window.getSelection().removeAllRanges(),o=+new Date,f=i.trigger({phase:"before",type:"render",target:i.name,box:t}),f.isCancelled===!0)||(typeof t!="undefined"&&t!=null&&(n(i.box).find("#layout_"+i.name+"_panel_main").length>0&&n(i.box).removeAttr("name").removeClass("w2ui-layout").html(""),i.box=t),!i.box))return!1;n(i.box).attr("name",i.name).addClass("w2ui-layout").html(""),n(i.box).length>0&&(n(i.box)[0].style.cssText+=i.style),r=["top","left","main","preview","right","bottom"];for(u in r)l=i.get(r[u]),e='',n(i.box).find(" > div").append(e);return n(i.box).find(" > div").append('0&&(f.css("overflow",i.overflow)[0].style.cssText+=";"+i.style),i.resizable===!0?n("#layout_"+this.name+"_resizer_"+t).show():n("#layout_"+this.name+"_resizer_"+t).hide(),typeof i.content=="object"&&i.content.render?(i.content.box=n("#layout_"+r.name+"_panel_"+i.type+" > .w2ui-panel-content")[0],i.content.render()):n("#layout_"+r.name+"_panel_"+i.type+" > .w2ui-panel-content").html(i.content),u=n(r.box).find("#layout_"+r.name+"_panel_"+i.type+" .w2ui-panel-tabs"),i.show.tabs?u.find("[name="+i.tabs.name+"]").length==0&&i.tabs!=null?u.w2render(i.tabs):i.tabs.refresh():u.html("").removeClass("w2ui-tabs").hide(),u=n(r.box).find("#layout_"+r.name+"_panel_"+i.type+" .w2ui-panel-toolbar"),i.show.toolbar?u.find("[name="+i.toolbar.name+"]").length==0&&i.toolbar!=null?u.w2render(i.toolbar):i.toolbar.refresh():u.html("").removeClass("w2ui-toolbar").hide()}else{if(n("#layout_"+r.name+"_panel_main").length<=0){r.render();return}r.resize();for(i in this.panels)r.refresh(this.panels[i].type)}return r.trigger(n.extend(e,{phase:"after"})),+new Date-o}},resize:function(){var ut,nt,y,h,u,tt,b,a,p;if((window.getSelection&&window.getSelection().removeAllRanges(),!this.box)||(ut=+new Date,nt=this.trigger({phase:"before",type:"resize",target:this.name,panel:this.tmp.resizing}),nt.isCancelled===!0))return!1;this.padding<0&&(this.padding=0),y=parseInt(n(this.box).width()),h=parseInt(n(this.box).height()),n(this.box).find(" > div").css({width:y+"px",height:h+"px"});var p=this,it=this.get("main"),l=this.get("preview"),s=this.get("left"),c=this.get("right"),r=this.get("top"),f=this.get("bottom"),et=!0,ft=l!=null&&l.hidden!=!0?!0:!1,d=s!=null&&s.hidden!=!0?!0:!1,rt=c!=null&&c.hidden!=!0?!0:!1,w=r!=null&&r.hidden!=!0?!0:!1,g=f!=null&&f.hidden!=!0?!0:!1;for(a in{top:"",left:"",right:"",bottom:"",preview:""})u=this.get(a),tt=String(u.size),u&&tt.substr(tt.length-1)=="%"?(b=h,u.type=="preview"&&(b=b-(r&&!r.hidden?r.sizeCalculated:0)-(f&&!f.hidden?f.sizeCalculated:0)),u.sizeCalculated=parseInt((u.type=="left"||u.type=="right"?y:b)*parseFloat(u.size)/100)):u.sizeCalculated=parseInt(u.size),u.sizeCalculatedthis.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_top").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ns-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("top",n),!1}))}else n("#layout_"+this.name+"_panel_top").hide();if(s!=null&&s.hidden!=!0){var o=0,e=0+(w?r.sizeCalculated+this.padding:0),t=s.sizeCalculated,i=h-(w?r.sizeCalculated+this.padding:0)-(g?f.sizeCalculated+this.padding:0),v=n("#layout_"+this.name+"_panel_left");window.navigator.userAgent.indexOf("MSIE")>0&&v.length>0&&v[0].clientHeightthis.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_left").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ew-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("left",n),!1}))}else n("#layout_"+this.name+"_panel_left").hide(),n("#layout_"+this.name+"_resizer_left").hide();if(c!=null&&c.hidden!=!0){var o=y-c.sizeCalculated,e=0+(w?r.sizeCalculated+this.padding:0),t=c.sizeCalculated,i=h-(w?r.sizeCalculated+this.padding:0)-(g?f.sizeCalculated+this.padding:0);n("#layout_"+this.name+"_panel_right").css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px"}).show(),c.width=t,c.height=i,c.resizable&&(o=o-this.padding,t=this.resizer>this.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_right").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ew-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("right",n),!1}))}else n("#layout_"+this.name+"_panel_right").hide();if(f!=null&&f.hidden!=!0){var o=0,e=h-f.sizeCalculated,t=y,i=f.sizeCalculated;n("#layout_"+this.name+"_panel_bottom").css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px"}).show(),f.width=t,f.height=i,f.resizable&&(e=e-(this.padding==0?0:this.padding),i=this.resizer>this.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_bottom").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ns-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("bottom",n),!1}))}else n("#layout_"+this.name+"_panel_bottom").hide();var o=0+(d?s.sizeCalculated+this.padding:0),e=0+(w?r.sizeCalculated+this.padding:0),t=y-(d?s.sizeCalculated+this.padding:0)-(rt?c.sizeCalculated+this.padding:0),i=h-(w?r.sizeCalculated+this.padding:0)-(g?f.sizeCalculated+this.padding:0)-(ft?l.sizeCalculated+this.padding:0),v=n("#layout_"+this.name+"_panel_main");if(window.navigator.userAgent.indexOf("MSIE")>0&&v.length>0&&v[0].clientHeight0&&v.length>0&&v[0].clientHeightthis.padding?this.resizer:this.padding,n("#layout_"+this.name+"_resizer_preview").show().css({display:"block",left:o+"px",top:e+"px",width:t+"px",height:i+"px",cursor:"ns-resize"}).bind("mousedown",function(n){return w2ui[p.name].tmp.events.resizeStart("preview",n),!1}))}else n("#layout_"+this.name+"_panel_preview").hide();for(a in{top:"",left:"",main:"",preview:"",right:"",bottom:""}){var k=this.get(a),u="#layout_"+this.name+"_panel_"+a+" > .w2ui-panel-",h=0;k.show.tabs&&(k.tabs!=null&&w2ui[this.name+"_"+a+"_tabs"]&&w2ui[this.name+"_"+a+"_tabs"].resize(),h+=w2utils.getSize(n(u+"tabs").css({display:"block"}),"height")),k.show.toolbar&&(k.toolbar!=null&&w2ui[this.name+"_"+a+"_toolbar"]&&w2ui[this.name+"_"+a+"_toolbar"].resize(),h+=w2utils.getSize(n(u+"toolbar").css({top:h+"px",display:"block"}),"height")),n(u+"content").css({display:"block"}).css({top:h+"px"})}return p=this,clearTimeout(this._resize_timer),this._resize_timer=setTimeout(function(){var t,i;for(t in w2ui)typeof w2ui[t].resize=="function"&&(w2ui[t].panels=="undefined"&&w2ui[t].resize(),i=n(w2ui[t].box).parents(".w2ui-layout"),i.length>0&&i.attr("name")==p.name&&w2ui[t].resize())},100),this.trigger(n.extend(nt,{phase:"after"})),+new Date-ut},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});return t.isCancelled===!0?!1:typeof w2ui[this.name]=="undefined"?!1:(n(this.box).find("#layout_"+this.name+"_panel_main").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-layout").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"})),this.tmp.events&&this.tmp.events.resize&&n(window).off("resize",this.tmp.events.resize),this.tmp.events&&this.tmp.events.mousemove&&n(document).off("mousemove",this.tmp.events.mousemove),this.tmp.events&&this.tmp.events.mouseup&&n(document).off("mouseup",this.tmp.events.mouseup),!0)},lock:function(t,i,r){if(n.inArray(String(t),["left","right","top","bottom","preview","main"])==-1){console.log("ERROR: First parameter needs to be the a valid panel name.");return}var u="#layout_"+this.name+"_panel_"+t;w2utils.lock(u,i,r)},unlock:function(t){if(n.inArray(String(t),["left","right","top","bottom","preview","main"])==-1){console.log("ERROR: First parameter needs to be the a valid panel name.");return}var i="#layout_"+this.name+"_panel_"+t;w2utils.unlock(i)}},n.extend(t.prototype,w2utils.event),w2obj.layout=t}(jQuery),w2popup={},function(n){n.fn.w2popup=function(t,i){typeof t=="undefined"&&(i={},t="open"),n.isPlainObject(t)&&(i=t,t="open"),t=t.toLowerCase(),t=="load"&&typeof i=="string"&&(i={url:i}),t=="open"&&typeof i.url!="undefined"&&(t="load"),typeof i=="undefined"&&(i={});var r={};return n(this).length>0&&(n(this).find("div[rel=title], div[rel=body], div[rel=buttons]").length>0?(n(this).find("div[rel=title]").length>0&&(r.title=n(this).find("div[rel=title]").html()),n(this).find("div[rel=body]").length>0&&(r.body=n(this).find("div[rel=body]").html(),r.style=n(this).find("div[rel=body]")[0].style.cssText),n(this).find("div[rel=buttons]").length>0&&(r.buttons=n(this).find("div[rel=buttons]").html())):(r.title=" ",r.body=n(this).html()),parseInt(n(this).css("width"))!=0&&(r.width=parseInt(n(this).css("width"))),parseInt(n(this).css("height"))!=0&&(r.height=parseInt(n(this).css("height")))),w2popup[t](n.extend({},r,i))},w2popup={defaults:{title:"",body:"",buttons:"",style:"",color:"#000",opacity:.4,speed:.3,modal:!1,maximized:!1,keyboard:!0,width:500,height:300,showClose:!0,showMax:!1,transition:null},handlers:[],onOpen:null,onClose:null,onMax:null,onMin:null,onKeydown:null,open:function(t){function w(n){if(n||(n=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),i.resizing=!0,i.tmp_x=n.screenX,i.tmp_y=n.screenY,n.stopPropagation?n.stopPropagation():n.cancelBubble=!0,n.preventDefault)n.preventDefault();else return!1}function c(t){i.resizing==!0&&(t||(t=window.event),i.tmp_div_x=t.screenX-i.tmp_x,i.tmp_div_y=t.screenY-i.tmp_y,n("#w2ui-popup").css({"-webkit-transition":"none","-webkit-transform":"translate3d("+i.tmp_div_x+"px, "+i.tmp_div_y+"px, 0px)","-moz-transition":"none","-moz-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)","-ms-transition":"none","-ms-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)","-o-transition":"none","-o-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)"}),n("#w2ui-panel").css({"-webkit-transition":"none","-webkit-transform":"translate3d("+i.tmp_div_x+"px, "+i.tmp_div_y+"px, 0px)","-moz-transition":"none","-moz-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)","-ms-transition":"none","-ms-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px","-o-transition":"none","-o-transform":"translate("+i.tmp_div_x+"px, "+i.tmp_div_y+"px)"}))}function h(t){i.resizing==!0&&(t||(t=window.event),i.tmp_div_x=t.screenX-i.tmp_x,i.tmp_div_y=t.screenY-i.tmp_y,n("#w2ui-popup").css({"-webkit-transition":"none","-webkit-transform":"translate3d(0px, 0px, 0px)","-moz-transition":"none","-moz-transform":"translate(0px, 0px)","-ms-transition":"none","-ms-transform":"translate(0px, 0px)","-o-transition":"none","-o-transform":"translate(0px, 0px)",left:parseInt(n("#w2ui-popup").css("left"))+parseInt(i.tmp_div_x)+"px",top:parseInt(n("#w2ui-popup").css("top"))+parseInt(i.tmp_div_y)+"px"}),n("#w2ui-panel").css({"-webkit-transition":"none","-webkit-transform":"translate3d(0px, 0px, 0px)","-moz-transition":"none","-moz-transform":"translate(0px, 0px)","-ms-transition":"none","-ms-transform":"translate(0px, 0px)","-o-transition":"none","-o-transform":"translate(0px, 0px)",left:parseInt(n("#w2ui-panel").css("left"))+parseInt(i.tmp_div_x)+"px",top:parseInt(n("#w2ui-panel").css("top"))+parseInt(i.tmp_div_y)+"px"}),i.resizing=!1)}var p=this,o=n("#w2ui-popup").data("options"),t=n.extend({},this.defaults,{body:""},o,t),e,f,v,y,r,u,a,l,s,i;if(n("#w2ui-popup").length==0&&(w2popup.handlers=[],w2popup.onMax=null,w2popup.onMin=null,w2popup.onOpen=null,w2popup.onClose=null,w2popup.onKeydown=null),t.onOpen&&(w2popup.onOpen=t.onOpen),t.onClose&&(w2popup.onClose=t.onClose),t.onMax&&(w2popup.onMax=t.onMax),t.onMin&&(w2popup.onMin=t.onMin),t.onKeydown&&(w2popup.onKeydown=t.onKeydown),window.innerHeight==undefined?(e=document.documentElement.offsetWidth,f=document.documentElement.offsetHeight,w2utils.engine=="IE7"&&(e+=21,f+=4)):(e=window.innerWidth,f=window.innerHeight),parseInt(e)-10