// @require jQuery // @require variables: // if ('undefined' === typeof UNIQ_HASH) throw "Missing UNIQ_HASH"; // $this->_htmlID (function($) { var TableAjaxGeomField = function() { var priv = {}; //private api var publ = {}; //public api priv.options = {}; var defaults = { recordID: '', fieldValue: '', hasValueClassName: 'TableAjaxGeomField-hasValue', linkClassNamePrefix: 'TableAjaxGeomField', linkSelectClassName: 'select', linkSelectAddClassNames: '', // 'glyphicon glyphicon-map-marker' getCsvUrl: '', linkGetCsvAddClassNames: '', // 'glyphicon glyphicon-download' linkRemoveClassName: 'remove', linkRemoveAddClassNames: '', // 'glyphicon glyphicon-remove' onSelect: null, onRemove: null, debug: false }; priv.init = function() { priv.render(); }; priv.render = function() { var state = priv.options; var cellMapSelect = jQuery(''); cellMapSelect.addClass(state.linkClassNamePrefix + '-' + state.linkSelectClassName); if (state.linkSelectAddClassNames) { cellMapSelect.addClass(state.linkSelectAddClassNames); } cellMapSelect.on('click', {recordID: priv.options.recordID, fieldValue: priv.options.fieldValue}, function(e) { if (typeof state.onSelect == "function") { state.onSelect.call(this, e.data.recordID, e.data.fieldValue); } }); var cellMapRemove = jQuery(''); cellMapRemove.addClass(state.linkClassNamePrefix + '-' + state.linkRemoveClassName); if (state.linkRemoveAddClassNames) { cellMapRemove.addClass(state.linkRemoveAddClassNames); } cellMapRemove.on('click', {recordID: state.recordID, fieldValue: state.fieldValue}, function(e) { if (typeof state.onRemove == "function") { state.onRemove.call(this, publ, e.data.recordID, e.data.fieldValue); } }); var cellMapGetCsv = jQuery(''); var node = $(state.id); node.empty(); node.addClass(state.linkClassNamePrefix); node.removeClass(state.hasValueClassName); if (state.fieldValue) { node.addClass(state.hasValueClassName); } node.append(cellMapSelect); if (state.fieldValue) node.append(cellMapGetCsv); node.append(cellMapRemove); }; publ.setValue = function(value) { if (priv.options.debug) console.log('TEST setValue: ', value, 'this', this); priv.options.fieldValue = value; priv.render(); }; publ.init = function(options) { if (priv.options.debug) console.log('TableAjaxGeomField initialization...', options); //merge supplied options with defaults $.extend(priv.options, defaults, options); priv.init(); return publ; }; return publ; }; $.fn.TableAjaxGeomFieldSetValue = function(value) { return this.each(function() { var tblAjaxMapGeomFld = $(this).data('TableAjaxGeomField'); if (tblAjaxMapGeomFld) { tblAjaxMapGeomFld.setValue(value); } }); return this; }; $.fn.TableAjaxGeomField = function(options) { options = options || {}; return this.each(function() { options.id = this; if (!$(this).data('TableAjaxGeomField')) { $(this).data('TableAjaxGeomField', new TableAjaxGeomField().init(options)); } }); return this; }; }(jQuery)); // global['...'] = ...