| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- // @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('<i title="Pokaż/utwórz obiekt na mapie"></i>');
- 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('<i title="Usuń obiekt z mapy"></i>');
- 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('<a href="'+priv.options.getCsvUrl+'&id='+priv.options.recordID+'"><i title="Pobierz punkty referencyjne w CSV" class="'+priv.options.linkGetCsvAddClassNames+'"></i></a>');
- 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['...'] = ...
|