if (!URI_BASE) throw "Missing URI_BASE"; // => Request::getPathUri() if (!URI_WPS) throw "Missing URI_WPS"; if (!global.jQuery) throw "Missing jQuery" var $ = global.jQuery var RENDER_AS_REACT = Boolean(RENDER_AS_REACT) || false var DBG = DBG || false; var DBG1 = true; if (!global.p5VendorJs) throw "Missing p5 Vendor js libs"; if (!global.p5VendorJs.Redux) throw "Missing p5 Vendor js lib: Redux"; if (!global.createTableFiltersStateObject) throw "Missing createTableFiltersStateObject"; if (!global.createTableSelectedStateObject) throw "Missing createTableSelectedStateObject"; var createReactClass = global.p5VendorJs.createReactClass; var h = global.p5VendorJs.React.createElement; var ReactDOM = global.p5VendorJs.ReactDOM; var Redux = global.p5VendorJs.Redux; var ReduxThunk = global.p5VendorJs.ReduxThunk; var createStoreWithThunkMiddleware = Redux.applyMiddleware(ReduxThunk)(Redux.createStore); // TODO: to vendor.js var p5UI__FieldCheckboxSearch = global.p5VendorJs['p5UI__FieldCheckboxSearch']; var p5UI__FieldCheckboxLoading = global.p5VendorJs['p5UI__FieldCheckboxLoading']; var p5UI__TableAjax = global.p5VendorJs['p5UI__TableAjax']; var P5UI__TableAjaxSortableLabel = global.p5VendorJs['P5UI__TableAjaxSortableLabel']; var P5UI__TableAjaxRowCheckbox = global.p5VendorJs['P5UI__TableAjaxRowCheckbox']; var P5UI__TableAjaxSelectedInfo = global.p5VendorJs['P5UI__TableAjaxSelectedInfo']; if (!String.prototype.startsWith) { // TODO: to global js utils String.prototype.startsWith = function(search, pos) { return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search; }; } p5WfsRefFilter = (function () { // convert GET param key ogc filter for ref return { parse: function (filterKey) { if (filterKey.startsWith('Ref_From_')) return { type: 'From', idInstance: filterKey.substr('Ref_From_'.length) }; if (filterKey.startsWith('Ref_To_')) return { type: 'To', idInstance: filterKey.substr('Ref_To_'.length) }; return null; } }; })(); function p5Utils__mapToQuery(map, callback) { var mapCallback = ('function' === typeof callback) ? callback : function (key) { return '' + key + '=' + encodeURIComponent(map.get(key)); }; return Array.from(map.keys()).sort() .map(mapCallback) .join('&') } function p5Utils__mapToQueryWithKeyPrefix(map, keyPrefix, callback) { var mapCallback = ('function' === typeof callback) ? callback : function (key) { return '' + (keyPrefix || '') + key + '=' + encodeURIComponent(map.get(key)); }; return p5Utils__mapToQuery(map, mapCallback) } function p5Utils__objectToQueryWithKeyPrefix(obj, prefix, callback) { if (!obj) return ''; var mapCallback = ('function' === typeof callback) ? callback : function (key) { return '' + key + '=' + encodeURIComponent(obj[key]); }; return Object.keys(obj).sort() .map(mapCallback) .join('&') } global['P5UI__TableAjaxSpecialFilter'] = createReactClass({ // props.store: Redux store with state: { isLoading bool, selected array of strings } // props.actions: Redux store actions // props.name: PropTypes.string.isRequired // props.values: PropTypes.array.isRequired // props.icon: PropTypes.string.isRequired // props.label: PropTypes.string getStateFromStore: function () { var state = this.props.store.getState(); DBG && console.log('DBG::P5UI__TableAjaxSpecialFilter::getStateFromStore (name:'+this.props.name+')', { store: state, name: this.props.name, selected: state.specialFilter.get(this.props.name) }); return { selected: state.specialFilter.get(this.props.name), }; }, getInitialState: function () { return this.getStateFromStore(); }, componentDidMount: function () { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilter::componentDidMount (name:'+this.props.name+')'); this.unsubscribe = this.props.store.subscribe(this.storeUpdated) }, componentWillUnmount: function () { this.unsubscribe() }, storeUpdated: function () { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilter::storeUpdated (name:'+this.props.name+')'); this.setState(this.getStateFromStore()) }, shouldComponentUpdate: function (nextProps, nextState) { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilter::shouldComponentUpdate (name:'+this.props.name+')', { state: this.state, nextState}); return ( this.state.selected !== nextState.selected ); }, handleRemoveFilter: function (event) { this.props.store.dispatch( this.props.actions.setSpecialFilter(this.props.name, '') ); }, handleSetFilter: function (value) { this.props.store.dispatch( this.props.actions.setSpecialFilter(this.props.name, value) ); }, renderButton: function (buttonKey) { var option = buttonKey; var props = this.props.values[option]; var value = props.value || ''; var state = this.props.store.getState(); DBG && console.warn('DBG:renderButton state', { state, props, value }); var active = (value === this.state.selected); return h('button', { className: "btn btn-xs btn-default" + ( active ? " active" : "" ), onClick: function (event) { DBG && console.warn('DBG:renderButton click', { value }); this.handleSetFilter(value); }.bind(this), }, option); }, render: function () { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilter::render (name:'+this.props.name+')', { state: this.state, props: this.props }); var label = this.props.label || this.props.name; return h('div', { className: "btn-group", style: { margin: '0 4px 0 0' } }, [ h('button', { className: "btn btn-xs btn-default", title: label, }, [ h('i', { className: this.props.icon }) ]) ].concat( Object.keys(this.props.values).map(this.renderButton) ).concat( [ h('button', { className: "btn btn-xs btn-default", title: "Kasuj filtr", disabled: !this.state.selected, onClick: this.handleRemoveFilter, style: { color: !this.state.selected ? '#bbb' : '#f00' } }, [ h('i', { className: "glyphicon glyphicon-remove" }) ]) ] ) ); } }); global['P5UI__TableAjaxSpecialFilterRelations'] = createReactClass({ // props.store: Redux store with state: { isLoading bool, selected array of strings } // props.actions: Redux store actions // props.name: PropTypes.string.isRequired // props.values: PropTypes.array.isRequired // props.icon: PropTypes.string.isRequired // props.label: PropTypes.string // props.availableBackRefs: PropTypes.array.isRequired // array of objects { id, namespace, label } // props.availableChildRefs: PropTypes.array.isRequired // array of objects { id, namespace, label } getStateFromStore: function () { var state = this.props.store.getState(); DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::getStateFromStore (name:'+this.props.name+')', { store: state, name: this.props.name, selected: state.specialFilter.get(this.props.name) }); var selected = []; // Array of { idInstance, primaryKey } state.specialFilter.forEach(function (value, key) { var refInfo = p5WfsRefFilter.parse(key); // null | { type: 'From' | 'To', idInstance: int } if (refInfo) { selected.push(Object.assign(refInfo, { primaryKey: value, filterKey: key })) } }) DBG && console.log('TODO: DBG::P5UI__TableAjaxSpecialFilterRelations::getStateFromStore (name:'+this.props.name+')', { store: state, name: this.props.name, selected }); return { selected: selected, }; }, getInitialState: function () { return this.getStateFromStore(); }, componentDidMount: function () { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::componentDidMount (name:'+this.props.name+')'); this.unsubscribe = this.props.store.subscribe(this.storeUpdated) }, componentWillUnmount: function () { this.unsubscribe() }, storeUpdated: function () { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::storeUpdated (name:'+this.props.name+')'); this.setState(this.getStateFromStore()) }, shouldComponentUpdate: function (nextProps, nextState) { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::shouldComponentUpdate (name:'+this.props.name+')', { state: this.state, nextState}); return ( this.state.selected !== nextState.selected ); }, handleRemoveFilter: function (event) { this.props.store.dispatch( this.props.actions.setSpecialFilter(this.props.name, '') ); }, handleSetFilter: function (value) { this.props.store.dispatch( this.props.actions.setSpecialFilter(this.props.name, value) ); }, handleCreate: function () { // TODO: save swal reference to variable to avoid open twice? var inputOptions = {}; if (this.props.availableBackRefs) this.props.availableBackRefs.forEach(function (instanceInfo) { inputOptions[ 'From_' + instanceInfo.id ] = "z " + instanceInfo.label || instanceInfo.namespace; }); if (this.props.availableChildRefs) this.props.availableChildRefs.forEach(function (instanceInfo) { inputOptions[ 'To_' + instanceInfo.id ] = "do " + instanceInfo.label || instanceInfo.namespace; }); swal({ title: "Wybierz rodzaj relacji", input: 'select', inputOptions: inputOptions, inputPlaceholder: "Wybierz", showCancelButton: true, cancelButtonText: "Anuluj", animation: false, inputValidator: function (value) { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::inputValidator', value); return new Promise(function (resolve) { if (!value) { resolve('Nie wybrano obiektu'); } else { resolve(); } }); }, }).then(this.handleInstanceCreate) // args: { value: ... } }, handleInstanceCreate: function (result) { if (!result.value) return; // cancel when result = { dismiss: "cancel" } var idInstance = ''; var type = ''; var instanceLabel = ''; if ('From_' === result.value.substr(0, 'From_'.length)) { type = 'From'; idInstance = result.value.substr('From_'.length); if (this.props.availableBackRefs) this.props.availableBackRefs.forEach(function (instanceInfo) { if (idInstance == instanceInfo.id) instanceLabel = instanceInfo.label || instanceInfo.namespace; }); } else if ('To_' === result.value.substr(0, 'To_'.length)) { type = 'To'; idInstance = result.value.substr('To_'.length); if (this.props.availableChildRefs) this.props.availableChildRefs.forEach(function (instanceInfo) { if (idInstance == instanceInfo.id) instanceLabel = instanceInfo.label || instanceInfo.namespace; }); } DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::handleInstanceCreate (name:'+this.props.name+') selected instance('+idInstance+')', { result: result, state: this.state, props: this.props, availableBackRefs: this.props.availableBackRefs }); swal({ title: "Wybierz obiekt", html: (instanceLabel) ? "typu: " + instanceLabel : "", input: 'text', inputPlaceholder: "Wybierz obiekt", showCancelButton: true, cancelButtonText: "Anuluj", animation: false, inputValidator: function (value) { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::inputValidator', value); return new Promise(function (resolve) { if (!value) { resolve('Nie podano obiektu'); } else { resolve(); } }); }, preConfirm: function (value) { return { type: type, idInstance: idInstance, primaryKey: value, } } }).then(this.handleInstancePrimaryKeySelected) // args: { value: { idInstance, primaryKey } } }, handleInstancePrimaryKeySelected: function (result) { if (!result.value) return; // cancel when result = { dismiss: "cancel" } var type = result.value.type; var idInstance = result.value.idInstance; var primaryKey = result.value.primaryKey; DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::handleInstancePrimaryKeySelected (name:'+this.props.name+') selected featureID('+idInstance+'.'+primaryKey+')', { result: result, state: this.state, props: this.props, availableBackRefs: this.props.availableBackRefs }); this.props.store.dispatch( this.props.actions.setSpecialFilter('Ref_' + type + '_' + idInstance, primaryKey) ); }, renderButton: function (buttonKey) { var option = buttonKey; var props = this.props.values[option]; var value = props.value || ''; var state = this.props.store.getState(); DBG && console.warn('DBG:renderButton state', { state, props, value }); var active = (value === this.state.selected); return h('button', { className: "btn btn-xs btn-default" + ( active ? " active" : "" ), onClick: function (event) { DBG && console.warn('DBG:renderButton click', { value }); this.handleSetFilter(value); }.bind(this), }, option); }, renderLabel: function () { var label = this.props.label || this.props.name; return h('button', { className: "btn btn-xs btn-default", title: label, style: { color: '#31708f', backgroundColor: '#d9edf7', } }, [ h('i', { className: this.props.icon }), " Filtr relacji: ", ]); }, renderListSelected: function () { // @return array of react nodes DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::this.props.availableBackRefs (name:'+this.props.name+')', { state: this.state, props: this.props, availableBackRefs: this.props.availableBackRefs }); return this.state.selected.map(this.renderSelected); }, renderSelected: function (selected) { // @selected: { type: 'From' | 'To', filterKey, idInstance, primaryKey }, @return react node var filterKey = selected.filterKey; var type = selected.type; // From | To - backRef | childRef var idInstance = selected.idInstance; var primaryKey = selected.primaryKey; var namespace = idInstance; var label = "" + idInstance + "." + primaryKey + ""; if ('From' === type) { var foundInstanceInfo = this.props.availableBackRefs.filter(function (instanceInfo) { return ( parseInt(idInstance) === parseInt(instanceInfo.id) ); }); if (foundInstanceInfo.length > 0) label = 'z ' + foundInstanceInfo[0].label + "." + primaryKey; if (foundInstanceInfo.length > 0) namespace = foundInstanceInfo[0].namespace; } else if ('To' === type) { var foundInstanceInfo = this.props.availableChildRefs.filter(function (instanceInfo) { return ( parseInt(idInstance) === parseInt(instanceInfo.id) ); }); if (foundInstanceInfo.length > 0) label = 'do ' + foundInstanceInfo[0].label + "." + primaryKey; if (foundInstanceInfo.length > 0) namespace = foundInstanceInfo[0].namespace; } return h(P5UI__TableAjaxSpecialFilterRelationFrom, { filterKey: filterKey, label: label, namespace: namespace, primaryKey: primaryKey, store: this.props.store, actions: this.props.actions, }); }, renderBackRef: function () { // @return react node - button with dropdown to select primaryKey from parent instance + remove button if selected return null; }, renderCreateButton: function () { return h('button', { className: "btn btn-xs btn-default", title: "Dodaj nowy filtr relacji", onClick: this.handleCreate, }, [ h('i', { className: 'glyphicon glyphicon-plus' }) ]); }, render: function () { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::render (name:'+this.props.name+')', { state: this.state, props: this.props }); return h('div', { className: "btn-group", style: { margin: '0 4px 0 0' } }, [ this.renderLabel(), ].concat( this.renderListSelected() ).concat([ this.renderCreateButton() ]) // Object.keys(this.props.values).map(this.renderButton) // ).concat( // [ // h('button', { // className: "btn btn-xs btn-default", // title: "Kasuj filtr", // disabled: !this.state.selected, // onClick: this.handleRemoveFilter, // style: { color: !this.state.selected ? '#bbb' : '#f00' } // }, [ // h('i', { className: "glyphicon glyphicon-remove" }) // ]) // ] ); } }); global['P5UI__TableAjaxSpecialFilterRelationFrom'] = createReactClass({ handleRemoveFilter: function (event) { this.props.store.dispatch( this.props.actions.setSpecialFilter(this.props.filterKey, '') ); }, render: function () { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelationFrom::render (filterKey:'+this.props.filterKey+')', { state: this.state, props: this.props }); var refInfo = p5WfsRefFilter.parse(this.props.filterKey); // null | { type: 'From' | 'To', idInstance: int } return h('button', { className: "btn btn-xs btn-default active", title: "Powiązane" + ( 'From' === refInfo.type ? " z " : " do " ) + this.props.namespace + " " + this.props.primaryKey, // onClick: this.handleUpdate, // TODO: paste param }, [ this.props.label, h('i', { className: 'glyphicon glyphicon-remove', style: { color: '#f00', opacity: 0.5, marginLeft: "3px", }, onClick: this.handleRemoveFilter, }) ]); } }); global['P5UI__TableAjaxSpecialFilters'] = createReactClass({ // props.store: Redux store with state: { isLoading bool, selected array of strings } // props.actions: Redux store actions // props.namespace: PropTypes.string.isRequired // props.specialFilters: PropTypes.object.isRequired // props.specialFilters: // [Msgs] => stdClass Object // [icon] => glyphicon glyphicon-envelope // [label] => Wiadomości // [btns] => Array: // [WIADOMOSCI] => stdClass Object // [value] => HAS_MSGS // [NOWE] => stdClass Object // [value] => NEW_MSGS // [BRAK_WIAD.] => stdClass Object // [value] => NO_MSGS // [Status] => stdClass Object // [icon] => glyphicon glyphicon-question-sign // [btns] => Array: // [OCZEKUJACY] => stdClass Object // [value] => WAITING // [AKTYWNI] => stdClass Object // [value] => AKTYWNI // handleClick: function (event) { // DBG && console.log('DBG::P5UI__TableAjaxSpecialFilters::handleChange (ns:'+this.props.namespace+')', { checked: checked }); // this.props.store.dispatch( this.props.actions.unselectAll( this.props.namespace ) ) // }, renderSpecialFilter: function (key) { var props = this.props.specialFilters[key]; DBG && console.log('DBG::P5UI__TableAjaxSpecialFilters::renderSpecialFilter (ns:'+this.props.namespace+')', { key: key, props, state: this.state }); if ('RELATIONS' === props.type) { DBG && console.warn('DBG::P5UI__TableAjaxSpecialFilters::renderSpecialFilter TODO render RELATIONS filter (ns:'+this.props.namespace+')', { props, state: this.state }); return h(P5UI__TableAjaxSpecialFilterRelations, { store: this.props.store, actions: this.props.actions, name: key, icon: props.icon, label: props.label, availableBackRefs: props.availableBackRefs, availableChildRefs: props.availableChildRefs, }); } return h(P5UI__TableAjaxSpecialFilter, { store: this.props.store, actions: this.props.actions, name: key, icon: props.icon, label: props.label, values: props.btns, }); }, render: function () { DBG && console.log('DBG::P5UI__TableAjaxSpecialFilters::render (ns:'+this.props.namespace+')', { props: this.props, state: this.state }); return h('div', {}, Object.keys(this.props.specialFilters).map(this.renderSpecialFilter)) } }); global['P5UI__TableAjaxFieldCheckboxSearch'] = createReactClass({ // props.namespace: PropTypes.string.isRequired // props.fieldName: PropTypes.string.isRequired // props.store: Redux store with state: { isLoading bool, selected array of strings } // props.actions: Redux store actions getStateFromStore: function () { var state = this.props.store.getState(); // selected = || 2 // 0 - unchecked, 1 - checked, 2 - indeterminate var selected = ''; if (state.filter.has(this.props.fieldName)) { selected = state.filter.get(this.props.fieldName) } return { disabled: this.props.disabled ? true : false, selected: selected, active: ('YES' === selected || 'NO' === selected), // isLoading: (-1 !== state.loading.indexOf(this.props.fieldName)), // checked: (-1 !== state.selected.indexOf(this.props.fieldName)) }; }, getInitialState: function() { return this.getStateFromStore(); }, componentDidMount: function () { DBG && console.log('DBG::P5UI__TableAjaxFieldCheckboxSearch::componentDidMount (f:'+this.props.fieldName+')'); this.unsubscribe = this.props.store.subscribe(this.storeUpdated) }, componentWillUnmount: function () { this.unsubscribe() }, storeUpdated: function () { DBG && console.log('DBG::P5UI__TableAjaxFieldCheckboxSearch::storeUpdated (f:'+this.props.fieldName+')', this.getStateFromStore()); this.setState(this.getStateFromStore()) }, shouldComponentUpdate: function (nextProps, nextState) { DBG && console.log('DBG::P5UI__TableAjaxFieldCheckboxSearch::shouldComponentUpdate (f:'+this.props.fieldName+')', { state: this.state, nextState}); return ( this.state.disabled !== nextState.disabled || this.state.selected !== nextState.selected ); }, handleChange: function (selected) { // selected: 0 - not checked, 1 - checked, 2 - indeterminate DBG && console.log('DBG::P5UI__TableAjaxFieldCheckboxSearch::handleChange (f:'+this.props.fieldName+')', { selected: selected, state: this.state }); if (0 === selected) { this.props.store.dispatch( this.props.actions.setFilter(this.props.fieldName, 'NO') ); } else if (1 === selected) { this.props.store.dispatch( this.props.actions.setFilter(this.props.fieldName, 'YES') ); } else if (2 === selected) { this.props.store.dispatch( this.props.actions.setFilter(this.props.fieldName, '') ); } }, mapSelectedToValue: function (selected) { switch (selected) { case 'YES': return 1; case 'NO': return 0; default: return 2; } }, render: function () { DBG && console.log('DBG::P5UI__TableAjaxFieldCheckboxSearch::render (f:'+this.props.fieldName+')', { props: this.props, state: this.state, state_sel: this.state.selected, sel: this.mapSelectedToValue(this.state.selected) }); return h('div', { style: { boxSizing: 'border-box', width: '100%', height: '21px', padding: '0 5px', borderTop: 0, borderBottom: '2px solid ' + ( this.state.active ? '#00ACCC' : 'transparent' ), }, }, [ h(p5UI__FieldCheckboxSearch, { size: 19, color: '#888', staticLabel: ["Pokaż:", "wszystkie,", "wybrane,", "niewybrane"].join("\n"), fieldName: this.props.fieldName, selected: this.mapSelectedToValue(this.state.selected), onChange: this.handleChange // checked: this.state.checked, // disabled: this.state.disabled, // isLoading: this.state.isLoading, }), ] ); } }); global['p5UI__FieldInputFilterSearch'] = createReactClass({ // props.fieldName: PropTypes.string.isRequired // props.type: PropTypes.string.isRequired // props.store: Redux store with state: { } // props.actions: Redux store actions // props.disabled: PropTypes.bool // props.lagacyProps: PropTypes.object getStateFromStore: function () { var storeState = this.props.store.getState(); return { value: storeState.filter.get(this.props.fieldName) || '', active: storeState.filter.has(this.props.fieldName) }; }, getInitialState: function() { return this.getStateFromStore(); }, componentDidMount: function () { DBG && console.log('DBG::p5UI__FieldInputFilterSearch::componentDidMount (f:'+this.props.fieldName+')'); this.unsubscribe = this.props.store.subscribe(this.storeUpdated) }, componentWillUnmount: function () { this.unsubscribe() }, storeUpdated: function () { DBG && console.log('DBG::p5UI__FieldInputFilterSearch::storeUpdated (f:'+this.props.fieldName+')', this.getStateFromStore()); this.setState(this.getStateFromStore()) }, shouldComponentUpdate: function (nextProps, nextState) { DBG && console.log('DBG::p5UI__FieldInputFilterSearch::shouldComponentUpdate (f:'+this.props.fieldName+')', { state: this.state, nextState}); return ( this.state.value !== nextState.value || this.state.active !== nextState.active ); }, handleChange: function (event) { // handleChange: function (event) { var value = event.target.value; DBG && console.log('DBG::p5UI__FieldInputFilterSearch::handleChange (f:'+this.props.fieldName+')', { value }); this.setState({ value: value }); this.props.onChange(this.props.fieldName, value); // this.props.store.dispatch( this.props.actions.toggle( this.props.namespace, this.props.primaryKey, checked ) ) }, render: function () { DBG && console.log('DBG::p5UI__FieldInputFilterSearch::render (f:'+this.props.fieldName+',v:'+this.state.value+')', { props: this.props, state: this.state }); switch (this.props.type) { case "number": case "date": case "bool": case "p5:price": case "p5:www_link": case "p5:string": case "string": return this.renderInput(); case "special": return this.renderEmpty(); case "simpleLink": return this.renderEmpty(); case "geom": return this.renderInput(); case "none": return this.renderEmpty(); case "ref": return this.renderEmpty(); default: return this.renderEmpty(); } }, renderEmpty: function () { return h('div', {}, " "); }, renderInput: function () { return h('input', { className: "filter", // + ( this.state.active ? " filter-active" : "" ), placeholder: !this.props.disabled ? "%" : "", type: "text", disabled: this.props.disabled || false, style: { boxSizing: 'border-box', width: '100%', height: '21px', borderTop: 0, borderBottom: '2px solid ' + ( this.state.active ? '#00ACCC' : 'transparent' ), }, value: this.state.value, onChange: this.handleChange }); } }); global['p5UI__TableAjaxClearAllFilters'] = createReactClass({ // props.store: Redux store with state: { } // props.actions: Redux store actions getStateFromStore: function () { var storeState = this.props.store.getState(); return { isFiltersEmpty: ( 0 === storeState.filter.size && 0 === storeState.specialFilter.size ) }; }, getInitialState: function() { return this.getStateFromStore(); }, componentDidMount: function () { DBG && console.log('DBG::p5UI__TableAjaxClearAllFilters::componentDidMount (f:'+this.props.fieldName+')'); this.unsubscribe = this.props.store.subscribe(this.storeUpdated) }, componentWillUnmount: function () { this.unsubscribe() }, storeUpdated: function () { DBG && console.log('DBG::p5UI__TableAjaxClearAllFilters::storeUpdated (f:'+this.props.fieldName+')', this.getStateFromStore()); this.setState(this.getStateFromStore()) }, // shouldComponentUpdate: function (nextProps, nextState) { // DBG && console.log('DBG::p5UI__TableAjaxClearAllFilters::shouldComponentUpdate (f:'+this.props.fieldName+')', { state: this.state, nextState}); // return ( // this.state.value !== nextState.value // || this.state.active !== nextState.active // ); // }, handleClick: function (event) { DBG && console.log('DBG::p5UI__TableAjaxClearAllFilters::handleClick (clearAllFilters)'); this.props.store.dispatch( this.props.actions.clearAllFilters() ) }, render: function () { DBG && console.log('DBG::p5UI__TableAjaxClearAllFilters::render (clearAllFilters)', { props: this.props, state: this.state }); return h('i', { title: this.props.title || "Kasuj wszystkie filtry", className: "glyphicon glyphicon-remove", style: Object.assign( { opacity: '0.5', lineHeight: '20px', padding: '0 3px', cursor: 'pointer', }, this.state.isFiltersEmpty ? { color: '#777' } : { color: '#f00' } ), onClick: this.handleClick }); } }); var TableAjax = function() { var priv = {}; //private api var publ = {}; //public api priv.options = {}; var defaults = { namespace: '', url: '', //webservice url urlPost: false, //use POST instead of GET selectAllByFilterUrl: '', getCsvTheGeomAjaxUrl: '', removeTheGeomAjaxUrl: '', moreFunctionsCellAjaxUrl: '', editInlineSaveUrl: '', theGeomSaveUrl: '', pageSizeSave: '', hiddenColsSaveUrl: '', editInlineUrl: '', addUserTableFilterAjaxUrl: '', rmUserTableFilterAjaxUrl: '', hasAdditionalLayers: 0, labelHtml: '', debug: false, //prints debug info to console filter: false, //show filter row filterInit: false,// init filters data forceFilterInit: false, columnPicker: false, //show columnpicker checkboxes: false, //show body checkboxes actions: '', //holds action links pageSize: 10, //current pagesize pageSizes: [10, 20, 30, 40, 50, 'All'], //available pagesizes hidePagerOnEmpty: false, //removes pager if no rows types: { //type specific options string: {}, number: {}, bool: {}, date: {} }, rowFunctions: false, tblFunctions: false, specialFilterFunctions: false, filtersClean: false, router: false, longDesc: false, exportFields: [], mapEditor: false, // mapEditor visible or not mapEditorContainer: 'window' // 'window' or 'dock' }; var _reactUITableNode; // TODO: react table node var _uiNodeCont; // container holding table var _uiNodeSelectedInfo; var _uiNodeSpecialFilters; var _uiNode$Table; // the table node var _head; // table header var _headSort; // table header sorting row var _headFilter; // table header columns filter row var _headSpecialFilter; // table header special filter row var _bodyNode; // table body var _body; // TODO: table body need render? var _foot; // table footer var _inlineEditBox; // inline edit box with form var _popoverCell; // inline popover cell var _popoverCellCurrent; // inline popover cell var _popoverCellAjaxXhr; var _mapEditor; // map editor node var _mapEditorWrap; // map editor wrapper node var _mapEditorDialog; // map editor jquery ui dialog node var _state = {};// state - to replace variables below (date, ...) var _data; //columns and rows var _totalPages; // total pages var _currDpOp; // clicked datetimepicker operator var _filterTimeout; // timer for delayed filtering var _checkToggleChecked = false; // check-all toggle state var _exportFieldsSelect = {}; var _tableWidth; var _fieldWidgets = {}; /* initialize the plugin. */ priv.init = function() { _uiNodeCont = priv.options.id; //
Pobieranie funkcji...
'); priv.ajaxLoadMoreFunctionsCell(rowPK); }); _popoverCellCurrent.popover('show'); return; }; priv.ajaxLoadMoreFunctionsCell = function(rowPK) { var dbg = (priv.options.debug || DBG); if (_popoverCellAjaxXhr) { _popoverCellAjaxXhr.abort(); } _popoverCellAjaxXhr = $.ajax({ type: 'GET', url: priv.options.moreFunctionsCellAjaxUrl + '&ID=' + rowPK, dataType: 'json', contentType: "application/json; charset=utf-8", data: '' }) .done(function(data, textStatus, jqXHR){ if (data && 'success' === data.type) { var popoverCellContent, rowFunctions = [], funcNodesToUpdate = [] ; if (data.rowFunctions && data.rowFunctions.length > 0) { rowFunctions = data.rowFunctions; } if (rowFunctions.length > 0) { var popoverCellContent = $('
Brak dodatkowych funkcji
'; } //_popoverCell.append(popoverCellContent);// cache if (_popoverCellCurrent) { var popoverNodeId = _popoverCellCurrent.attr('aria-describedby'); if (popoverNodeId) { var popoverNode = jQuery('#' + popoverNodeId), popoverCntNode = popoverNode.find('.popoverCellContent'), popoverRowFuncNode = popoverNode.find('.popoverRowFunctions'); ; {// fix generated row Functions by loaded from ajax call if(dbg) console.log('popoverRowFunctions. popoverRowFuncNode', popoverRowFuncNode); if(dbg) console.log('popoverRowFunctions. funcNodesToUpdate', funcNodesToUpdate); funcNodesToUpdate.forEach(function(funcNodeInfo) { var className = 'func_name-' + funcNodeInfo.id, foundRowFuncNode = null ; if(dbg) console.log('popoverRowFunctions. funcNodesToUpdate loop:', funcNodeInfo); popoverRowFuncNode.find('li > a').each(function(ind, n) { var n$ = $(n); if(dbg) console.log('popoverRowFunctions loop(',ind,'):', n, 'data(func_name)', n$.data('func_name'), 'data', n$.data()); if (n$.hasClass(className)) { foundRowFuncNode = n$; } }); if (foundRowFuncNode) { foundRowFuncNode.replaceWith(funcNodeInfo.node); } else { var funcItemNode = $('').appendTo(popoverCellContent); funcItemNode.append(foundRowFuncNode); } }); } popoverCntNode.empty().append(popoverCellContent); if (rowFunctions.length <= 0) { popoverCntNode.find('p.text-muted').delay(600).hide(300); } } } } }); }; priv.renderRowEmptyNode = function() { var rowNode = $('Wiersze od {0} do {1} z {2}
', [fromRow + 1, toRow, total])).appendTo(node); } else { $('Brak wierszy pasujących do kryteriów wyszukiwania
').appendTo(node); } currentNode.replaceWith(node); }; priv.renderFooterPagination = function() { var nodeClass = 'tblAjax__' + 'footer__toolbar__pagination', currentNode = $(_uiNodeCont).next('.foot').find('.' + nodeClass), node; var currPage = _state.page; var totalPages = Math.ceil(_data.total / _state.pageSize); if (priv.options.debug || DBG) console.log('Render: ', nodeClass, '_data.total', _data.total, 'currPage', currPage); if (_data.total > 0) { node = $(''); var lowerPage = currPage - 2; var upperPage = currPage + 2; if (upperPage > totalPages) { var diff = upperPage - totalPages; upperPage = totalPages; lowerPage -= diff; } if (lowerPage < 1) lowerPage = 1; if (upperPage < 5) upperPage = 5; //$(p5Utils__format('