django-quickapi
Advanced tools
| /* | ||
| * quicktable.less | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| .table-col-1-hidden th:nth-child(1), | ||
| .table-col-1-hidden td:nth-child(1) { | ||
| display: none; | ||
| } | ||
| .table-col-2-hidden th:nth-child(2), | ||
| .table-col-2-hidden td:nth-child(2) { | ||
| display: none; | ||
| } | ||
| .table-col-3-hidden th:nth-child(3), | ||
| .table-col-3-hidden td:nth-child(3) { | ||
| display: none; | ||
| } | ||
| .table-col-4-hidden th:nth-child(4), | ||
| .table-col-4-hidden td:nth-child(4) { | ||
| display: none; | ||
| } | ||
| .table-col-5-hidden th:nth-child(5), | ||
| .table-col-5-hidden td:nth-child(5) { | ||
| display: none; | ||
| } | ||
| .table-col-6-hidden th:nth-child(6), | ||
| .table-col-6-hidden td:nth-child(6) { | ||
| display: none; | ||
| } | ||
| .table-col-7-hidden th:nth-child(7), | ||
| .table-col-7-hidden td:nth-child(7) { | ||
| display: none; | ||
| } | ||
| .table-col-8-hidden th:nth-child(8), | ||
| .table-col-8-hidden td:nth-child(8) { | ||
| display: none; | ||
| } | ||
| .table-col-9-hidden th:nth-child(9), | ||
| .table-col-9-hidden td:nth-child(9) { | ||
| display: none; | ||
| } | ||
| .table-col-10-hidden th:nth-child(10), | ||
| .table-col-10-hidden td:nth-child(10) { | ||
| display: none; | ||
| } | ||
| .table-col-11-hidden th:nth-child(11), | ||
| .table-col-11-hidden td:nth-child(11) { | ||
| display: none; | ||
| } | ||
| .table-col-12-hidden th:nth-child(12), | ||
| .table-col-12-hidden td:nth-child(12) { | ||
| display: none; | ||
| } | ||
| .table-col-13-hidden th:nth-child(13), | ||
| .table-col-13-hidden td:nth-child(13) { | ||
| display: none; | ||
| } | ||
| .table-col-14-hidden th:nth-child(14), | ||
| .table-col-14-hidden td:nth-child(14) { | ||
| display: none; | ||
| } | ||
| .table-col-15-hidden th:nth-child(15), | ||
| .table-col-15-hidden td:nth-child(15) { | ||
| display: none; | ||
| } | ||
| .table-col-16-hidden th:nth-child(16), | ||
| .table-col-16-hidden td:nth-child(16) { | ||
| display: none; | ||
| } | ||
| .table-col-17-hidden th:nth-child(17), | ||
| .table-col-17-hidden td:nth-child(17) { | ||
| display: none; | ||
| } | ||
| .table-col-18-hidden th:nth-child(18), | ||
| .table-col-18-hidden td:nth-child(18) { | ||
| display: none; | ||
| } | ||
| .table-col-19-hidden th:nth-child(19), | ||
| .table-col-19-hidden td:nth-child(19) { | ||
| display: none; | ||
| } | ||
| .table-col-20-hidden th:nth-child(20), | ||
| .table-col-20-hidden td:nth-child(20) { | ||
| display: none; | ||
| } | ||
| .table-col-21-hidden th:nth-child(21), | ||
| .table-col-21-hidden td:nth-child(21) { | ||
| display: none; | ||
| } | ||
| .table-col-22-hidden th:nth-child(22), | ||
| .table-col-22-hidden td:nth-child(22) { | ||
| display: none; | ||
| } | ||
| .table-col-23-hidden th:nth-child(23), | ||
| .table-col-23-hidden td:nth-child(23) { | ||
| display: none; | ||
| } | ||
| .table-col-24-hidden th:nth-child(24), | ||
| .table-col-24-hidden td:nth-child(24) { | ||
| display: none; | ||
| } | ||
| .table-col-25-hidden th:nth-child(25), | ||
| .table-col-25-hidden td:nth-child(25) { | ||
| display: none; | ||
| } | ||
| .table-col-26-hidden th:nth-child(26), | ||
| .table-col-26-hidden td:nth-child(26) { | ||
| display: none; | ||
| } | ||
| .table-col-27-hidden th:nth-child(27), | ||
| .table-col-27-hidden td:nth-child(27) { | ||
| display: none; | ||
| } | ||
| .table-col-28-hidden th:nth-child(28), | ||
| .table-col-28-hidden td:nth-child(28) { | ||
| display: none; | ||
| } | ||
| .table-col-29-hidden th:nth-child(29), | ||
| .table-col-29-hidden td:nth-child(29) { | ||
| display: none; | ||
| } | ||
| .table-col-30-hidden th:nth-child(30), | ||
| .table-col-30-hidden td:nth-child(30) { | ||
| display: none; | ||
| } | ||
| /* | ||
| * Sorting | ||
| */ | ||
| th.sorting { | ||
| cursor: pointer; | ||
| background: url('../img/tables/sort_both.png') no-repeat center right; | ||
| } | ||
| th.sorting-asc { | ||
| cursor: pointer; | ||
| background: url('../img/tables/sort_asc.png') no-repeat center right; | ||
| } | ||
| th.sorting-desc { | ||
| cursor: pointer; | ||
| background: url('../img/tables/sort_desc.png') no-repeat center right; | ||
| } | ||
| th.sorting-n0 { | ||
| background-color: #FFE6E6; | ||
| } | ||
| th.sorting-n1 { | ||
| background-color: #FFF9E6; | ||
| } | ||
| th.sorting-n2 { | ||
| background-color: #F3FFE6; | ||
| } | ||
| th.sorting-n3 { | ||
| background-color: #E6FFED; | ||
| } | ||
| th.sorting-n4 { | ||
| background-color: #E6FFFF; | ||
| } |
| .table-col-1-hidden th:nth-child(1),.table-col-1-hidden td:nth-child(1){display:none}.table-col-2-hidden th:nth-child(2),.table-col-2-hidden td:nth-child(2){display:none}.table-col-3-hidden th:nth-child(3),.table-col-3-hidden td:nth-child(3){display:none}.table-col-4-hidden th:nth-child(4),.table-col-4-hidden td:nth-child(4){display:none}.table-col-5-hidden th:nth-child(5),.table-col-5-hidden td:nth-child(5){display:none}.table-col-6-hidden th:nth-child(6),.table-col-6-hidden td:nth-child(6){display:none}.table-col-7-hidden th:nth-child(7),.table-col-7-hidden td:nth-child(7){display:none}.table-col-8-hidden th:nth-child(8),.table-col-8-hidden td:nth-child(8){display:none}.table-col-9-hidden th:nth-child(9),.table-col-9-hidden td:nth-child(9){display:none}.table-col-10-hidden th:nth-child(10),.table-col-10-hidden td:nth-child(10){display:none}.table-col-11-hidden th:nth-child(11),.table-col-11-hidden td:nth-child(11){display:none}.table-col-12-hidden th:nth-child(12),.table-col-12-hidden td:nth-child(12){display:none}.table-col-13-hidden th:nth-child(13),.table-col-13-hidden td:nth-child(13){display:none}.table-col-14-hidden th:nth-child(14),.table-col-14-hidden td:nth-child(14){display:none}.table-col-15-hidden th:nth-child(15),.table-col-15-hidden td:nth-child(15){display:none}.table-col-16-hidden th:nth-child(16),.table-col-16-hidden td:nth-child(16){display:none}.table-col-17-hidden th:nth-child(17),.table-col-17-hidden td:nth-child(17){display:none}.table-col-18-hidden th:nth-child(18),.table-col-18-hidden td:nth-child(18){display:none}.table-col-19-hidden th:nth-child(19),.table-col-19-hidden td:nth-child(19){display:none}.table-col-20-hidden th:nth-child(20),.table-col-20-hidden td:nth-child(20){display:none}.table-col-21-hidden th:nth-child(21),.table-col-21-hidden td:nth-child(21){display:none}.table-col-22-hidden th:nth-child(22),.table-col-22-hidden td:nth-child(22){display:none}.table-col-23-hidden th:nth-child(23),.table-col-23-hidden td:nth-child(23){display:none}.table-col-24-hidden th:nth-child(24),.table-col-24-hidden td:nth-child(24){display:none}.table-col-25-hidden th:nth-child(25),.table-col-25-hidden td:nth-child(25){display:none}.table-col-26-hidden th:nth-child(26),.table-col-26-hidden td:nth-child(26){display:none}.table-col-27-hidden th:nth-child(27),.table-col-27-hidden td:nth-child(27){display:none}.table-col-28-hidden th:nth-child(28),.table-col-28-hidden td:nth-child(28){display:none}.table-col-29-hidden th:nth-child(29),.table-col-29-hidden td:nth-child(29){display:none}.table-col-30-hidden th:nth-child(30),.table-col-30-hidden td:nth-child(30){display:none}th.sorting{cursor:pointer;background:url('../img/tables/sort_both.png') no-repeat center right}th.sorting-asc{cursor:pointer;background:url('../img/tables/sort_asc.png') no-repeat center right}th.sorting-desc{cursor:pointer;background:url('../img/tables/sort_desc.png') no-repeat center right}th.sorting-n0{background-color:#ffe6e6}th.sorting-n1{background-color:#fff9e6}th.sorting-n2{background-color:#f3ffe6}th.sorting-n3{background-color:#e6ffed}th.sorting-n4{background-color:#e6ffff} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| <!-- Created with Inkscape (http://www.inkscape.org/) --> | ||
| <svg | ||
| xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
| xmlns:cc="http://creativecommons.org/ns#" | ||
| xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
| xmlns:svg="http://www.w3.org/2000/svg" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | ||
| xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | ||
| width="512" | ||
| height="512" | ||
| id="svg2" | ||
| version="1.1" | ||
| inkscape:version="0.48.3.1 r9886" | ||
| sodipodi:docname="Новый документ 1"> | ||
| <defs | ||
| id="defs4" /> | ||
| <sodipodi:namedview | ||
| id="base" | ||
| pagecolor="#ffffff" | ||
| bordercolor="#666666" | ||
| borderopacity="1.0" | ||
| inkscape:pageopacity="0.0" | ||
| inkscape:pageshadow="2" | ||
| inkscape:zoom="0.98994949" | ||
| inkscape:cx="151.81944" | ||
| inkscape:cy="110.42142" | ||
| inkscape:document-units="px" | ||
| inkscape:current-layer="layer1" | ||
| showgrid="false" | ||
| inkscape:window-width="1920" | ||
| inkscape:window-height="1007" | ||
| inkscape:window-x="0" | ||
| inkscape:window-y="25" | ||
| inkscape:window-maximized="1" /> | ||
| <metadata | ||
| id="metadata7"> | ||
| <rdf:RDF> | ||
| <cc:Work | ||
| rdf:about=""> | ||
| <dc:format>image/svg+xml</dc:format> | ||
| <dc:type | ||
| rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> | ||
| <dc:title></dc:title> | ||
| </cc:Work> | ||
| </rdf:RDF> | ||
| </metadata> | ||
| <g | ||
| inkscape:label="Layer 1" | ||
| inkscape:groupmode="layer" | ||
| id="layer1" | ||
| transform="translate(0,-540.36218)"> | ||
| <text | ||
| xml:space="preserve" | ||
| style="font-size:45.36851882999999930px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans" | ||
| x="565.0733" | ||
| y="467.22543" | ||
| id="text2985" | ||
| sodipodi:linespacing="125%" | ||
| transform="matrix(0,1.0020188,0.99798526,0,0,0)"><tspan | ||
| sodipodi:role="line" | ||
| id="tspan2987" | ||
| x="565.0733" | ||
| y="467.22543" | ||
| style="font-size:580.71704102000001058px;fill:#000000">Q</tspan></text> | ||
| <text | ||
| xml:space="preserve" | ||
| style="font-size:38.25341797px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans" | ||
| x="102.27046" | ||
| y="846.42297" | ||
| id="text2996" | ||
| sodipodi:linespacing="125%" | ||
| transform="scale(0.98903946,1.011082)"><tspan | ||
| sodipodi:role="line" | ||
| id="tspan2998" | ||
| x="102.27046" | ||
| y="846.42297" | ||
| style="font-size:172.14039612px;font-weight:bold;fill:#000000;-inkscape-font-specification:Sans Bold">API</tspan></text> | ||
| </g> | ||
| </svg> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| /** | ||
| * jquery.quickapi.js - jQuery plugin for QuickAPI application | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| (function ($) { | ||
| /* Общая функция для работы с django-quickapi | ||
| * | ||
| * Документация: | ||
| * https://docs.rosix.ru/django-quickapi/wiki/jquery.html#quickapi | ||
| * | ||
| */ | ||
| $.quickAPI = function(opts) { | ||
| var data, options = opts || new Object(); | ||
| // `args` is deprecation option | ||
| if (!options.data) options.data = options.args || { method: "quickapi.test" }; | ||
| if (options.simple || options.type == 'GET') { | ||
| data = options.data; | ||
| if (!data.language) data.language = options.language || window.LANGUAGE_CODE | ||
| } else { | ||
| data = { | ||
| jsonData: $.toJSON(options.data), | ||
| language: options.language || window.LANGUAGE_CODE | ||
| } | ||
| } | ||
| var jqxhr, | ||
| settings = { | ||
| type: options.type || "POST", | ||
| async: options.sync === true ? false : options.async === false ? false : true, | ||
| timeout: options.timeout || window.AJAX_TIMEOUT || 3000, | ||
| url: options.url || window.QUICKAPI_URL || location.pathname, | ||
| data: data, | ||
| dataType: 'json', | ||
| }, | ||
| callback = options.callback || function(json, status, xhr) {}, | ||
| showAlert = options.handlerShowAlert || window.handlerShowAlert || function(head, msg, cls, cb) { | ||
| var match; | ||
| if ($.type(msg) == 'object') { | ||
| msg = $.toJSON(msg) | ||
| .replace(/\,\"/g, ', "') | ||
| .replace(/\"\:/g, '": ') | ||
| } | ||
| else if (msg.match(/<\!DOCTYPE/)) { | ||
| match = msg.match(/<[title,TITLE]+>(.*)<\/[title,TITLE]+>/); | ||
| if (match) head = match[1]; | ||
| match = msg.match(/<[body,BODY]+>([^+]*)<\/[body,BODY]+>/); | ||
| if (match) { | ||
| msg = match[1] | ||
| .replace(/<\/?[^>]+>/g, '') | ||
| .replace(/ [ ]+/g, ' ') | ||
| .replace(/\n[\n]+/g, '\n') | ||
| } else { | ||
| msg = ''; | ||
| } | ||
| } | ||
| if (msg.length > 512) { | ||
| msg = msg.substring(0, 512) + ' ...' | ||
| }; | ||
| alert(head +'\n'+ msg); | ||
| if (cb) { return cb() }; | ||
| return null | ||
| }; | ||
| jqxhr = $.ajax(settings) | ||
| // Обработка ошибок протокола HTTP | ||
| .fail(function(xhr, status, err) { | ||
| // Если есть переадресация, то выполняем её | ||
| if (xhr.getResponseHeader('Location')) { | ||
| location.replace(xhr.getResponseHeader('Location')); | ||
| } else if (xhr.responseText) { | ||
| // Иначе извещаем пользователя ответом и в консоль | ||
| console.error("ERROR:", xhr.responseText); | ||
| showAlert("ERROR:", xhr.responseText, 'alert-danger') | ||
| } | ||
| }) | ||
| // Обработка полученных данных | ||
| .done(function(json, status, xhr) { | ||
| if (options.log && window.DEBUG) {console.debug(options.log)}; | ||
| /* При переадресации нужно отобразить сообщение на некоторое время, | ||
| * а затем выполнить переход по ссылке | ||
| */ | ||
| if ((json.status >=300) && (json.status <400) && (json.data.Location != undefined)) { | ||
| var loc = json.data.Location, redirect; | ||
| redirect = function() { location.replace(loc) }; | ||
| console.info("REDIRECT:" + loc); | ||
| if (json.message) { | ||
| showAlert("REDIRECT:", json.message, 'alert-danger', redirect) | ||
| } else { | ||
| redirect() | ||
| } | ||
| } | ||
| /* При ошибках извещаем пользователя полученным сообщением */ | ||
| else if (json.status >=400) { | ||
| showAlert("ERROR:", json.message, 'alert-danger'); | ||
| } | ||
| /* При нормальном возврате в debug-режиме выводим в консоль | ||
| * сообщение | ||
| */ | ||
| else { | ||
| if (window.DEBUG) { | ||
| console.debug($.toJSON(json.message)); | ||
| if (options.data.method == "quickapi.test") { | ||
| console.debug(json.data) | ||
| } | ||
| }; | ||
| return callback(json, status, xhr) | ||
| } | ||
| }); | ||
| return jqxhr | ||
| } | ||
| }(jQuery)); | ||
| /* | ||
| * jquery.quicktable.js - jQuery plugin for QuickAPI application | ||
| * | ||
| * depends: | ||
| * jquery.quickapi.js - jQuery plugin for QuickAPI | ||
| * recommends: | ||
| * Twitter bootstrap >= 3.0 | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| (function ($) { | ||
| /* Плагин для работы с QuickTable из состава django-quickapi | ||
| * | ||
| * Документация: | ||
| * https://docs.rosix.ru/django-quickapi/wiki/jquery.html#quicktable | ||
| * | ||
| */ | ||
| var pluginName = "quickTable"; | ||
| $.fn[pluginName] = function(options) { | ||
| if (!this.size()) { console.error('The selector found nothing'); return undefined }; | ||
| if (!options.method) { | ||
| console.error( | ||
| "Not valid options for "+pluginName, | ||
| { method:options.method }, | ||
| 'method must be defined!' | ||
| ); | ||
| }; | ||
| if ($.type(options.columns) != 'array' || $.isEmptyObject(options.columns)) { | ||
| console.error( | ||
| "Not valid options for "+pluginName, | ||
| { columns:options.columns }, | ||
| 'columns must be not empty array!' | ||
| ); | ||
| console.info('EXAMPLE:\n', | ||
| 'columns = [ {name:"id", hidden:true, notmanaged:true}, {name:"name", title:"Name"} ]\n', | ||
| 'where `name` - object attribute, `hidden` - hidden column,', | ||
| ' `notmanaged` - the column is not managed, `title` - title of column.' | ||
| ); | ||
| }; | ||
| var table = this[0], id, opts; | ||
| id = $(table).attr('id'); | ||
| if (!id) { return this }; // not valid | ||
| opts = $.extend({ | ||
| //url: undefined, | ||
| //method: undefined, | ||
| //columns: undefined, | ||
| //handlerShowAlert: undefined, | ||
| timeout: 10000, | ||
| async: true, | ||
| autoload: true, | ||
| autorender_settings: true, | ||
| delay: 500, | ||
| page: 1, | ||
| limit: 25, | ||
| limit_list: [25, 50, 75, 100], | ||
| filters: {}, | ||
| ordering: [], | ||
| multiordering: false, | ||
| table_type: 'table', // variants: 'stack' or 'pager' | ||
| text_pager_prev: '«', | ||
| text_pager_next: '»', | ||
| // the following variables are strongly advised not to change | ||
| _selector_filtering: '[data-filtering='+id+']', | ||
| _selector_ordering: '#'+id+' th[class^=sorting][name]', | ||
| _selector_limiting: 'input[data-limiting='+id+']:checked, select[data-limiting='+id+']', | ||
| _selector_colswitcher: 'input[data-colswitcher='+id+']', | ||
| _selector_settings: '#'+id+'_settings', | ||
| _selector_pager: '#'+id+'_pager', | ||
| _selector_pager_links: '#'+id+'_pager li:not(.disabled) a:not(.disabled)', | ||
| _selector_info: '#'+id+'_info', | ||
| _selector_thead: '#'+id+' thead', | ||
| _selector_tbody: '#'+id+' tbody', | ||
| _selector_alert_not_found: '[data-notfound='+id+']', | ||
| _default_filter_key: '_search_', | ||
| _managed_columns: [], | ||
| _column_names: {}, | ||
| }, options); | ||
| table.opts = opts; // link | ||
| table.request = null; // current jqxhr | ||
| table.fn = {}; // storage for functions | ||
| opts.replace = true; // append or overwrite tbody | ||
| $.each(opts.columns, function(i, col) { | ||
| opts._column_names[col.name] = col; | ||
| if (col.hidden) $(table).addClass('table-col-'+(i+1)+'-hidden'); | ||
| }); | ||
| /*** START FUNCTIONS ***/ | ||
| /* Delay for keyup in filters */ | ||
| table.fn.delay = (function(){ | ||
| var tid = 0; | ||
| return function(callback, ms){ | ||
| clearTimeout(tid); | ||
| tid = setTimeout(callback, ms); | ||
| }; | ||
| })(); | ||
| /* Twitter bootstrap .pager as stack */ | ||
| table.fn._render_bs_stack = function(page, num_pages) { | ||
| var p = opts._selector_pager, a = opts._selector_pager_links; | ||
| if (page < num_pages) { | ||
| $(a).data('page', (page+1)); | ||
| $(p).show(); | ||
| } else { | ||
| $(a).data('page', ''); | ||
| $(p).hide(); | ||
| } | ||
| }; | ||
| /* Twitter bootstrap .pager inner HTML */ | ||
| table.fn._render_bs_pager = function(page, num_pages, hide_prev) { | ||
| var html = '', tp = opts.text_pager_prev, tn = opts.text_pager_next; | ||
| if (page >1 && !hide_prev) { | ||
| html += '<li><a href="#" data-page="'+(page-1)+'">'+tp+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+tp+'</span></li>'; | ||
| } | ||
| if (page < num_pages) { | ||
| html += '<li><a href="#" data-page="'+(page+1)+'">'+tn+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+tn+'</span></li>'; | ||
| } | ||
| $(opts._selector_pager).html(html); | ||
| }; | ||
| /* Twitter bootstrap .pagination inner HTML */ | ||
| table.fn._render_bs_pagination = function(page, num_pages, on_each_side, on_ends) { | ||
| var html = '', | ||
| on_each_side=on_each_side||3, | ||
| on_ends=on_ends||2, | ||
| dot='.', | ||
| page_range = [], | ||
| _push; | ||
| if (page >1) { | ||
| html += '<li><a href="#" data-page="'+(page-1)+'">'+opts.text_pager_prev+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+opts.text_pager_prev+'</span></li>'; | ||
| } | ||
| _push = function(s, e) { for(var i=s; i<e; i++) { page_range.push(i) } }; | ||
| if (num_pages > 9) { | ||
| if (page > (on_each_side + on_ends)) { | ||
| _push(1, on_each_side); | ||
| page_range.push(dot); | ||
| _push(page+1-on_each_side, page+1); | ||
| } else { | ||
| _push(1, page+1) | ||
| } | ||
| if (page < (num_pages - on_each_side - on_ends + 1)) { | ||
| _push(page+1, page+on_each_side); | ||
| page_range.push(dot); | ||
| _push(num_pages-on_ends+1, num_pages+1); | ||
| } else { | ||
| _push(page+1, num_pages+1) | ||
| } | ||
| } else { | ||
| page_range = $.map($(Array(num_pages)), function(val, i) { return i+1; }) | ||
| }; | ||
| $.each(page_range, function(i, item) { | ||
| if (item == dot) { | ||
| html += '<li class="disabled"><span>...</span></li>'; | ||
| } else if (item == page) { | ||
| html += '<li class="active"><span>'+page+'</span></li>'; | ||
| } else { | ||
| html += '<li><a href="#" data-page="'+item+'">'+item+'</a></li>'; | ||
| } | ||
| }); | ||
| if (page < num_pages) { | ||
| html += '<li><a href="#" data-page="'+(page+1)+'">'+opts.text_pager_next+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+opts.text_pager_next+'</span></li>'; | ||
| } | ||
| $(opts._selector_pager).html(html); | ||
| }; | ||
| /* Use default pagination */ | ||
| table.fn.render_pager = function(page, num_pages) { | ||
| if (opts.table_type == 'stack') { | ||
| return table.fn._render_bs_stack(page, num_pages) | ||
| } | ||
| else if (opts.table_type == 'pager') { | ||
| return table.fn._render_bs_pager(page, num_pages, true) | ||
| } | ||
| return table.fn._render_bs_pagination(page, num_pages); | ||
| } | ||
| /* Show/hide not found text */ | ||
| table.fn.alert_not_found = function(show) { | ||
| var $alert = $(opts._selector_alert_not_found); | ||
| show ? $alert.show() : $alert.hide(); | ||
| }; | ||
| /* Rendering information */ | ||
| table.fn.render_info = function(html) { | ||
| $(opts._selector_info).html(html); | ||
| }; | ||
| /* Rendering settings */ | ||
| table.fn.render_settings = function() { | ||
| var html = ''; | ||
| $.each(opts.columns, function(i, col) { | ||
| if (!col.notmanaged) { | ||
| html += '<label>' | ||
| +'<input type="checkbox" name="'+id+'_colswitcher" value="'+(i+1)+'" ' | ||
| +(!col.hidden ? ' checked' : '')+'/>' | ||
| +(col.title||col.name) | ||
| +'</label>' | ||
| } | ||
| }); | ||
| html += '<div class="btn-group" data-toggle="buttons">' | ||
| $.each(opts.limit_list, function(i, limit) { | ||
| html += '<label class="btn'+(opts.limit == limit ? ' active': '')+'">' | ||
| +'<input type="checkbox" name="'+id+'_limit" ' | ||
| +(opts.limit == limit ? ' checked': '')+'>' | ||
| + limit | ||
| +'</label>' | ||
| }); | ||
| html += '</div>' | ||
| $(opts._selector_settings).html(html); | ||
| }; | ||
| /* Returns class for <tr> */ | ||
| table.fn.get_class_tr = function(object) { return object ? '' : 'danger' }; | ||
| /* Rendering one object */ | ||
| table.fn.render_object = function(index, object) { | ||
| if (object == null) return; | ||
| var html = ''; | ||
| html += '<tr class="'+table.fn.get_class_tr(object)+'">'; | ||
| $.each(opts.columns, function(i, col) { | ||
| html += '<td>'+object[col.name]+'</td>'; | ||
| }); | ||
| html += '</tr>'; | ||
| $(opts._selector_tbody).append(html); | ||
| }; | ||
| /* Callback of jqxhr. Rendering all objects, pagination, etc. */ | ||
| table.fn.render = function(json, replace) { | ||
| var data = json.data; | ||
| if (replace) $(opts._selector_tbody).html(''); | ||
| if ($.isEmptyObject(data.objects)) { | ||
| table.fn.alert_not_found(true) | ||
| } else { | ||
| table.fn.alert_not_found(false) | ||
| $.each(data.objects, function(i, item) { | ||
| table.fn.render_object(i, item) | ||
| }) | ||
| } | ||
| table.fn.render_pager(data.page, data.num_pages); | ||
| if (data.info) table.fn.render_info(data.info); | ||
| }; | ||
| /* Request to server on quickAPI. Returns jqxhr. */ | ||
| table.fn.get = function(filters) { | ||
| var replace = opts['replace'], F = filters || {}; | ||
| if (table.request) table.request.abort(); | ||
| table.request = $.quickAPI({ | ||
| url: opts.url, | ||
| timeout: opts.timeout, | ||
| //type: 'POST', | ||
| async: opts.async, | ||
| args: { | ||
| method: opts.method, | ||
| kwargs: { | ||
| filters: $.extend({}, opts.filters, F), | ||
| ordering: opts.ordering, | ||
| page: opts.page, | ||
| limit: opts.limit, | ||
| }, | ||
| }, | ||
| callback: function(json, status, xhr) { return table.fn.render(json, replace) }, | ||
| handlerShowAlert: opts.handlerShowAlert, | ||
| }) | ||
| .always(function() {table.request = null}); | ||
| return table.request | ||
| }; | ||
| /* Request to server from first page by force. */ | ||
| table.fn.get_first_page = function(filters) { | ||
| opts.page = 1; | ||
| opts.replace = true; | ||
| return table.fn.get(filters); | ||
| }; | ||
| /*** END FUNCTIONS ***/ | ||
| /*** START BINDING TABLE CONTROLLERS ON DOCUMENT BODY ***/ | ||
| $('body') | ||
| /* Keyup on character filters */ | ||
| .off('keyup', opts._selector_filtering+':not(input[type=checkbox])') | ||
| .on('keyup', opts._selector_filtering+':not(input[type=checkbox])', function(e) { | ||
| var fname = this.name || opts._default_filter_key, | ||
| old = opts.filters[fname], | ||
| min = Number($(this).data('minimum')) || 0, // minimum chars for query | ||
| len = this.value.length; | ||
| if (this.value != old && (!len || len >= min)) { | ||
| opts.filters[fname] = this.value; | ||
| table.fn.delay(table.fn.get_first_page, opts.delay); | ||
| } | ||
| }) | ||
| /* change on boolean filters */ | ||
| .off('change', opts._selector_filtering+'[type=checkbox]') | ||
| .on('change', opts._selector_filtering+'[type=checkbox]', function(e) { | ||
| var fname = this.name; | ||
| if (fname && this.checked != opts.filters[fname]) { | ||
| opts.filters[fname] = this.checked; | ||
| table.fn.delay(table.fn.get_first_page, 0); | ||
| } | ||
| }) | ||
| /* Change limit on page */ | ||
| .off('change', opts._selector_limiting) | ||
| .on('change', opts._selector_limiting, function(e) { | ||
| opts.limit = this.value; | ||
| table.fn.get_first_page(); | ||
| }) | ||
| /* Change visible of column */ | ||
| .off('change', opts._selector_colswitcher) | ||
| .on('change', opts._selector_colswitcher, function(e) { | ||
| var n = this.value, | ||
| cls = 'table-col-'+n+'-hidden'; | ||
| if (!n) return; | ||
| if (this.checked) { | ||
| $(table).removeClass(cls); | ||
| opts.columns[n-1].hidden = false; | ||
| } else { | ||
| $(table).addClass(cls); | ||
| opts.columns[n-1].hidden = true; | ||
| } | ||
| }) | ||
| /* Change ordering on columns */ | ||
| .off('click', opts._selector_ordering) | ||
| .on('click', opts._selector_ordering, function(e) { | ||
| var column = $(this).attr('name'), L, i; | ||
| if (!column) return; | ||
| L = opts.ordering; | ||
| i = $.inArray(column, L); | ||
| if (!opts.multiordering) { | ||
| $(opts._selector_ordering).removeClass('sorting-asc') | ||
| .removeClass('sorting-desc') | ||
| .addClass('sorting'); | ||
| } | ||
| if (i > -1) { | ||
| //~ console.debug('exists', i, column); | ||
| if (!opts.multiordering) { | ||
| L = ['-'+column]; | ||
| } else { | ||
| L[i] = '-'+column; | ||
| } | ||
| $(this).removeClass('sorting').addClass('sorting-desc'); | ||
| } else { | ||
| //~ console.debug('not exists', i, column); | ||
| i = $.inArray('-'+column, L); | ||
| if (i > -1) { | ||
| //~ console.debug('remove', i, '-'+column); | ||
| if (!opts.multiordering) { | ||
| L = []; | ||
| } else { | ||
| L = L.slice(0,i).concat(L.slice(i+1)); | ||
| } | ||
| $(this).removeClass('sorting-desc').addClass('sorting'); | ||
| } | ||
| } | ||
| if (i == -1){ | ||
| //~ console.debug('not exists', i, '-'+column); | ||
| if (!opts.multiordering) { | ||
| L = [column]; | ||
| } else { | ||
| L.push(column); | ||
| } | ||
| $(this).removeClass('sorting').addClass('sorting-asc'); | ||
| } | ||
| opts.ordering = L; | ||
| table.fn.get_first_page(); | ||
| }) | ||
| /* Click on pagination */ | ||
| .off('click', opts._selector_pager_links) | ||
| .on('click', opts._selector_pager_links, function(e) { | ||
| e.preventDefault(); | ||
| opts.page = $(this).data('page'); | ||
| if (opts.table_type == 'stack') { opts.replace = false }; | ||
| table.fn.get(); | ||
| }); | ||
| /*** END BINDING TABLE CONTROLLERS ***/ | ||
| /* Starting table */ | ||
| if (opts.autorender_settings) table.fn.render_settings(); | ||
| if (opts.autoload) table.fn.get_first_page(); | ||
| return table; | ||
| }; | ||
| }(jQuery)); | ||
| (function(a){a.quickAPI=function(d){var f,b=d||new Object();if(!b.data){b.data=b.args||{method:"quickapi.test"}}if(b.simple||b.type=="GET"){f=b.data;if(!f.language){f.language=b.language||window.LANGUAGE_CODE}}else{f={jsonData:a.toJSON(b.data),language:b.language||window.LANGUAGE_CODE}}var g,c={type:b.type||"POST",async:b.sync===true?false:b.async===false?false:true,timeout:b.timeout||window.AJAX_TIMEOUT||3000,url:b.url||window.QUICKAPI_URL||location.pathname,data:f,dataType:"json",},h=b.callback||function(j,i,k){},e=b.handlerShowAlert||window.handlerShowAlert||function(l,m,j,i){var k;if(a.type(m)=="object"){m=a.toJSON(m).replace(/\,\"/g,', "').replace(/\"\:/g,'": ')}else{if(m.match(/<\!DOCTYPE/)){k=m.match(/<[title,TITLE]+>(.*)<\/[title,TITLE]+>/);if(k){l=k[1]}k=m.match(/<[body,BODY]+>([^+]*)<\/[body,BODY]+>/);if(k){m=k[1].replace(/<\/?[^>]+>/g,"").replace(/ [ ]+/g," ").replace(/\n[\n]+/g,"\n")}else{m=""}}}if(m.length>512){m=m.substring(0,512)+" ..."}alert(l+"\n"+m);if(i){return i()}return null};g=a.ajax(c).fail(function(k,i,j){if(k.getResponseHeader("Location")){location.replace(k.getResponseHeader("Location"))}else{if(k.responseText){console.error("ERROR:",k.responseText);e("ERROR:",k.responseText,"alert-danger")}}}).done(function(j,i,l){if(b.log&&window.DEBUG){console.debug(b.log)}if((j.status>=300)&&(j.status<400)&&(j.data.Location!=undefined)){var k=j.data.Location,m;m=function(){location.replace(k)};console.info("REDIRECT:"+k);if(j.message){e("REDIRECT:",j.message,"alert-danger",m)}else{m()}}else{if(j.status>=400){e("ERROR:",j.message,"alert-danger")}else{if(window.DEBUG){console.debug(a.toJSON(j.message));if(b.data.method=="quickapi.test"){console.debug(j.data)}}return h(j,i,l)}}});return g}}(jQuery));(function(b){var a="quickTable";b.fn[a]=function(c){if(!this.size()){console.error("The selector found nothing");return undefined}if(!c.method){console.error("Not valid options for "+a,{method:c.method},"method must be defined!")}if(b.type(c.columns)!="array"||b.isEmptyObject(c.columns)){console.error("Not valid options for "+a,{columns:c.columns},"columns must be not empty array!");console.info("EXAMPLE:\n",'columns = [ {name:"id", hidden:true, notmanaged:true}, {name:"name", title:"Name"} ]\n',"where `name` - object attribute, `hidden` - hidden column,"," `notmanaged` - the column is not managed, `title` - title of column.")}var e=this[0],f,d;f=b(e).attr("id");if(!f){return this}d=b.extend({timeout:10000,async:true,autoload:true,autorender_settings:true,delay:500,page:1,limit:25,limit_list:[25,50,75,100],filters:{},ordering:[],multiordering:false,table_type:"table",text_pager_prev:"«",text_pager_next:"»",_selector_filtering:"[data-filtering="+f+"]",_selector_ordering:"#"+f+" th[class^=sorting][name]",_selector_limiting:"input[data-limiting="+f+"]:checked, select[data-limiting="+f+"]",_selector_colswitcher:"input[data-colswitcher="+f+"]",_selector_settings:"#"+f+"_settings",_selector_pager:"#"+f+"_pager",_selector_pager_links:"#"+f+"_pager li:not(.disabled) a:not(.disabled)",_selector_info:"#"+f+"_info",_selector_thead:"#"+f+" thead",_selector_tbody:"#"+f+" tbody",_selector_alert_not_found:"[data-notfound="+f+"]",_default_filter_key:"_search_",_managed_columns:[],_column_names:{},},c);e.opts=d;e.request=null;e.fn={};d.replace=true;b.each(d.columns,function(h,g){d._column_names[g.name]=g;if(g.hidden){b(e).addClass("table-col-"+(h+1)+"-hidden")}});e.fn.delay=(function(){var g=0;return function(i,h){clearTimeout(g);g=setTimeout(i,h)}})();e.fn._render_bs_stack=function(i,h){var j=d._selector_pager,g=d._selector_pager_links;if(i<h){b(g).data("page",(i+1));b(j).show()}else{b(g).data("page","");b(j).hide()}};e.fn._render_bs_pager=function(k,j,h){var i="",l=d.text_pager_prev,g=d.text_pager_next;if(k>1&&!h){i+='<li><a href="#" data-page="'+(k-1)+'">'+l+"</a></li>"}else{i+='<li class="disabled"><span>'+l+"</span></li>"}if(k<j){i+='<li><a href="#" data-page="'+(k+1)+'">'+g+"</a></li>"}else{i+='<li class="disabled"><span>'+g+"</span></li>"}b(d._selector_pager).html(i)};e.fn._render_bs_pagination=function(n,m,k,l){var j="",k=k||3,l=l||2,h=".",i=[],g;if(n>1){j+='<li><a href="#" data-page="'+(n-1)+'">'+d.text_pager_prev+"</a></li>"}else{j+='<li class="disabled"><span>'+d.text_pager_prev+"</span></li>"}g=function(p,q){for(var o=p;o<q;o++){i.push(o)}};if(m>9){if(n>(k+l)){g(1,k);i.push(h);g(n+1-k,n+1)}else{g(1,n+1)}if(n<(m-k-l+1)){g(n+1,n+k);i.push(h);g(m-l+1,m+1)}else{g(n+1,m+1)}}else{i=b.map(b(Array(m)),function(p,o){return o+1})}b.each(i,function(o,p){if(p==h){j+='<li class="disabled"><span>...</span></li>'}else{if(p==n){j+='<li class="active"><span>'+n+"</span></li>"}else{j+='<li><a href="#" data-page="'+p+'">'+p+"</a></li>"}}});if(n<m){j+='<li><a href="#" data-page="'+(n+1)+'">'+d.text_pager_next+"</a></li>"}else{j+='<li class="disabled"><span>'+d.text_pager_next+"</span></li>"}b(d._selector_pager).html(j)};e.fn.render_pager=function(h,g){if(d.table_type=="stack"){return e.fn._render_bs_stack(h,g)}else{if(d.table_type=="pager"){return e.fn._render_bs_pager(h,g,true)}}return e.fn._render_bs_pagination(h,g)};e.fn.alert_not_found=function(g){var h=b(d._selector_alert_not_found);g?h.show():h.hide()};e.fn.render_info=function(g){b(d._selector_info).html(g)};e.fn.render_settings=function(){var g="";b.each(d.columns,function(j,h){if(!h.notmanaged){g+='<label><input type="checkbox" name="'+f+'_colswitcher" value="'+(j+1)+'" '+(!h.hidden?" checked":"")+"/>"+(h.title||h.name)+"</label>"}});g+='<div class="btn-group" data-toggle="buttons">';b.each(d.limit_list,function(j,h){g+='<label class="btn'+(d.limit==h?" active":"")+'"><input type="checkbox" name="'+f+'_limit" '+(d.limit==h?" checked":"")+">"+h+"</label>"});g+="</div>";b(d._selector_settings).html(g)};e.fn.get_class_tr=function(g){return g?"":"danger"};e.fn.render_object=function(h,g){if(g==null){return}var i="";i+='<tr class="'+e.fn.get_class_tr(g)+'">';b.each(d.columns,function(k,j){i+="<td>"+g[j.name]+"</td>"});i+="</tr>";b(d._selector_tbody).append(i)};e.fn.render=function(h,g){var i=h.data;if(g){b(d._selector_tbody).html("")}if(b.isEmptyObject(i.objects)){e.fn.alert_not_found(true)}else{e.fn.alert_not_found(false);b.each(i.objects,function(j,k){e.fn.render_object(j,k)})}e.fn.render_pager(i.page,i.num_pages);if(i.info){e.fn.render_info(i.info)}};e.fn.get=function(i){var g=d.replace,h=i||{};if(e.request){e.request.abort()}e.request=b.quickAPI({url:d.url,timeout:d.timeout,async:d.async,args:{method:d.method,kwargs:{filters:b.extend({},d.filters,h),ordering:d.ordering,page:d.page,limit:d.limit,},},callback:function(k,j,l){return e.fn.render(k,g)},handlerShowAlert:d.handlerShowAlert,}).always(function(){e.request=null});return e.request};e.fn.get_first_page=function(g){d.page=1;d.replace=true;return e.fn.get(g)};b("body").off("keyup",d._selector_filtering+":not(input[type=checkbox])").on("keyup",d._selector_filtering+":not(input[type=checkbox])",function(j){var k=this.name||d._default_filter_key,h=d.filters[k],i=Number(b(this).data("minimum"))||0,g=this.value.length;if(this.value!=h&&(!g||g>=i)){d.filters[k]=this.value;e.fn.delay(e.fn.get_first_page,d.delay)}}).off("change",d._selector_filtering+"[type=checkbox]").on("change",d._selector_filtering+"[type=checkbox]",function(g){var h=this.name;if(h&&this.checked!=d.filters[h]){d.filters[h]=this.checked;e.fn.delay(e.fn.get_first_page,0)}}).off("change",d._selector_limiting).on("change",d._selector_limiting,function(g){d.limit=this.value;e.fn.get_first_page()}).off("change",d._selector_colswitcher).on("change",d._selector_colswitcher,function(h){var i=this.value,g="table-col-"+i+"-hidden";if(!i){return}if(this.checked){b(e).removeClass(g);d.columns[i-1].hidden=false}else{b(e).addClass(g);d.columns[i-1].hidden=true}}).off("click",d._selector_ordering).on("click",d._selector_ordering,function(k){var j=b(this).attr("name"),g,h;if(!j){return}g=d.ordering;h=b.inArray(j,g);if(!d.multiordering){b(d._selector_ordering).removeClass("sorting-asc").removeClass("sorting-desc").addClass("sorting")}if(h>-1){if(!d.multiordering){g=["-"+j]}else{g[h]="-"+j}b(this).removeClass("sorting").addClass("sorting-desc")}else{h=b.inArray("-"+j,g);if(h>-1){if(!d.multiordering){g=[]}else{g=g.slice(0,h).concat(g.slice(h+1))}b(this).removeClass("sorting-desc").addClass("sorting")}}if(h==-1){if(!d.multiordering){g=[j]}else{g.push(j)}b(this).removeClass("sorting").addClass("sorting-asc")}d.ordering=g;e.fn.get_first_page()}).off("click",d._selector_pager_links).on("click",d._selector_pager_links,function(g){g.preventDefault();d.page=b(this).data("page");if(d.table_type=="stack"){d.replace=false}e.fn.get()});if(d.autorender_settings){e.fn.render_settings()}if(d.autoload){e.fn.get_first_page()}return e}}(jQuery)); |
| /** | ||
| * jquery.quickapi.js - jQuery plugin for QuickAPI application | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| (function ($) { | ||
| /* Общая функция для работы с django-quickapi | ||
| * | ||
| * Документация: | ||
| * https://docs.rosix.ru/django-quickapi/wiki/jquery.html#quickapi | ||
| * | ||
| */ | ||
| $.quickAPI = function(opts) { | ||
| var data, options = opts || new Object(); | ||
| // `args` is deprecation option | ||
| if (!options.data) options.data = options.args || { method: "quickapi.test" }; | ||
| if (options.simple || options.type == 'GET') { | ||
| data = options.data; | ||
| if (!data.language) data.language = options.language || window.LANGUAGE_CODE | ||
| } else { | ||
| data = { | ||
| jsonData: $.toJSON(options.data), | ||
| language: options.language || window.LANGUAGE_CODE | ||
| } | ||
| } | ||
| var jqxhr, | ||
| settings = { | ||
| type: options.type || "POST", | ||
| async: options.sync === true ? false : options.async === false ? false : true, | ||
| timeout: options.timeout || window.AJAX_TIMEOUT || 3000, | ||
| url: options.url || window.QUICKAPI_URL || location.pathname, | ||
| data: data, | ||
| dataType: 'json', | ||
| }, | ||
| callback = options.callback || function(json, status, xhr) {}, | ||
| showAlert = options.handlerShowAlert || window.handlerShowAlert || function(head, msg, cls, cb) { | ||
| var match; | ||
| if ($.type(msg) == 'object') { | ||
| msg = $.toJSON(msg) | ||
| .replace(/\,\"/g, ', "') | ||
| .replace(/\"\:/g, '": ') | ||
| } | ||
| else if (msg.match(/<\!DOCTYPE/)) { | ||
| match = msg.match(/<[title,TITLE]+>(.*)<\/[title,TITLE]+>/); | ||
| if (match) head = match[1]; | ||
| match = msg.match(/<[body,BODY]+>([^+]*)<\/[body,BODY]+>/); | ||
| if (match) { | ||
| msg = match[1] | ||
| .replace(/<\/?[^>]+>/g, '') | ||
| .replace(/ [ ]+/g, ' ') | ||
| .replace(/\n[\n]+/g, '\n') | ||
| } else { | ||
| msg = ''; | ||
| } | ||
| } | ||
| if (msg.length > 512) { | ||
| msg = msg.substring(0, 512) + ' ...' | ||
| }; | ||
| alert(head +'\n'+ msg); | ||
| if (cb) { return cb() }; | ||
| return null | ||
| }; | ||
| jqxhr = $.ajax(settings) | ||
| // Обработка ошибок протокола HTTP | ||
| .fail(function(xhr, status, err) { | ||
| // Если есть переадресация, то выполняем её | ||
| if (xhr.getResponseHeader('Location')) { | ||
| location.replace(xhr.getResponseHeader('Location')); | ||
| } else if (xhr.responseText) { | ||
| // Иначе извещаем пользователя ответом и в консоль | ||
| console.error("ERROR:", xhr.responseText); | ||
| showAlert("ERROR:", xhr.responseText, 'alert-danger') | ||
| } | ||
| }) | ||
| // Обработка полученных данных | ||
| .done(function(json, status, xhr) { | ||
| if (options.log && window.DEBUG) {console.debug(options.log)}; | ||
| /* При переадресации нужно отобразить сообщение на некоторое время, | ||
| * а затем выполнить переход по ссылке | ||
| */ | ||
| if ((json.status >=300) && (json.status <400) && (json.data.Location != undefined)) { | ||
| var loc = json.data.Location, redirect; | ||
| redirect = function() { location.replace(loc) }; | ||
| console.info("REDIRECT:" + loc); | ||
| if (json.message) { | ||
| showAlert("REDIRECT:", json.message, 'alert-danger', redirect) | ||
| } else { | ||
| redirect() | ||
| } | ||
| } | ||
| /* При ошибках извещаем пользователя полученным сообщением */ | ||
| else if (json.status >=400) { | ||
| showAlert("ERROR:", json.message, 'alert-danger'); | ||
| } | ||
| /* При нормальном возврате в debug-режиме выводим в консоль | ||
| * сообщение | ||
| */ | ||
| else { | ||
| if (window.DEBUG) { | ||
| console.debug($.toJSON(json.message)); | ||
| if (options.data.method == "quickapi.test") { | ||
| console.debug(json.data) | ||
| } | ||
| }; | ||
| return callback(json, status, xhr) | ||
| } | ||
| }); | ||
| return jqxhr | ||
| } | ||
| }(jQuery)); | ||
| (function(a){a.quickAPI=function(d){var f,b=d||new Object();if(!b.data){b.data=b.args||{method:"quickapi.test"}}if(b.simple||b.type=="GET"){f=b.data;if(!f.language){f.language=b.language||window.LANGUAGE_CODE}}else{f={jsonData:a.toJSON(b.data),language:b.language||window.LANGUAGE_CODE}}var g,c={type:b.type||"POST",async:b.sync===true?false:b.async===false?false:true,timeout:b.timeout||window.AJAX_TIMEOUT||3000,url:b.url||window.QUICKAPI_URL||location.pathname,data:f,dataType:"json",},h=b.callback||function(j,i,k){},e=b.handlerShowAlert||window.handlerShowAlert||function(l,m,j,i){var k;if(a.type(m)=="object"){m=a.toJSON(m).replace(/\,\"/g,', "').replace(/\"\:/g,'": ')}else{if(m.match(/<\!DOCTYPE/)){k=m.match(/<[title,TITLE]+>(.*)<\/[title,TITLE]+>/);if(k){l=k[1]}k=m.match(/<[body,BODY]+>([^+]*)<\/[body,BODY]+>/);if(k){m=k[1].replace(/<\/?[^>]+>/g,"").replace(/ [ ]+/g," ").replace(/\n[\n]+/g,"\n")}else{m=""}}}if(m.length>512){m=m.substring(0,512)+" ..."}alert(l+"\n"+m);if(i){return i()}return null};g=a.ajax(c).fail(function(k,i,j){if(k.getResponseHeader("Location")){location.replace(k.getResponseHeader("Location"))}else{if(k.responseText){console.error("ERROR:",k.responseText);e("ERROR:",k.responseText,"alert-danger")}}}).done(function(j,i,l){if(b.log&&window.DEBUG){console.debug(b.log)}if((j.status>=300)&&(j.status<400)&&(j.data.Location!=undefined)){var k=j.data.Location,m;m=function(){location.replace(k)};console.info("REDIRECT:"+k);if(j.message){e("REDIRECT:",j.message,"alert-danger",m)}else{m()}}else{if(j.status>=400){e("ERROR:",j.message,"alert-danger")}else{if(window.DEBUG){console.debug(a.toJSON(j.message));if(b.data.method=="quickapi.test"){console.debug(j.data)}}return h(j,i,l)}}});return g}}(jQuery)); |
| /* | ||
| * jquery.quicktable.js - jQuery plugin for QuickAPI application | ||
| * | ||
| * depends: | ||
| * jquery.quickapi.js - jQuery plugin for QuickAPI | ||
| * recommends: | ||
| * Twitter bootstrap >= 3.0 | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| (function ($) { | ||
| /* Плагин для работы с QuickTable из состава django-quickapi | ||
| * | ||
| * Документация: | ||
| * https://docs.rosix.ru/django-quickapi/wiki/jquery.html#quicktable | ||
| * | ||
| */ | ||
| var pluginName = "quickTable"; | ||
| $.fn[pluginName] = function(options) { | ||
| if (!this.size()) { console.error('The selector found nothing'); return undefined }; | ||
| if (!options.method) { | ||
| console.error( | ||
| "Not valid options for "+pluginName, | ||
| { method:options.method }, | ||
| 'method must be defined!' | ||
| ); | ||
| }; | ||
| if ($.type(options.columns) != 'array' || $.isEmptyObject(options.columns)) { | ||
| console.error( | ||
| "Not valid options for "+pluginName, | ||
| { columns:options.columns }, | ||
| 'columns must be not empty array!' | ||
| ); | ||
| console.info('EXAMPLE:\n', | ||
| 'columns = [ {name:"id", hidden:true, notmanaged:true}, {name:"name", title:"Name"} ]\n', | ||
| 'where `name` - object attribute, `hidden` - hidden column,', | ||
| ' `notmanaged` - the column is not managed, `title` - title of column.' | ||
| ); | ||
| }; | ||
| var table = this[0], id, opts; | ||
| id = $(table).attr('id'); | ||
| if (!id) { return this }; // not valid | ||
| opts = $.extend({ | ||
| //url: undefined, | ||
| //method: undefined, | ||
| //columns: undefined, | ||
| //handlerShowAlert: undefined, | ||
| timeout: 10000, | ||
| async: true, | ||
| autoload: true, | ||
| autorender_settings: true, | ||
| delay: 500, | ||
| page: 1, | ||
| limit: 25, | ||
| limit_list: [25, 50, 75, 100], | ||
| filters: {}, | ||
| ordering: [], | ||
| multiordering: false, | ||
| table_type: 'table', // variants: 'stack' or 'pager' | ||
| text_pager_prev: '«', | ||
| text_pager_next: '»', | ||
| // the following variables are strongly advised not to change | ||
| _selector_filtering: '[data-filtering='+id+']', | ||
| _selector_ordering: '#'+id+' th[class^=sorting][name]', | ||
| _selector_limiting: 'input[data-limiting='+id+']:checked, select[data-limiting='+id+']', | ||
| _selector_colswitcher: 'input[data-colswitcher='+id+']', | ||
| _selector_settings: '#'+id+'_settings', | ||
| _selector_pager: '#'+id+'_pager', | ||
| _selector_pager_links: '#'+id+'_pager li:not(.disabled) a:not(.disabled)', | ||
| _selector_info: '#'+id+'_info', | ||
| _selector_thead: '#'+id+' thead', | ||
| _selector_tbody: '#'+id+' tbody', | ||
| _selector_alert_not_found: '[data-notfound='+id+']', | ||
| _default_filter_key: '_search_', | ||
| _managed_columns: [], | ||
| _column_names: {}, | ||
| }, options); | ||
| table.opts = opts; // link | ||
| table.request = null; // current jqxhr | ||
| table.fn = {}; // storage for functions | ||
| opts.replace = true; // append or overwrite tbody | ||
| $.each(opts.columns, function(i, col) { | ||
| opts._column_names[col.name] = col; | ||
| if (col.hidden) $(table).addClass('table-col-'+(i+1)+'-hidden'); | ||
| }); | ||
| /*** START FUNCTIONS ***/ | ||
| /* Delay for keyup in filters */ | ||
| table.fn.delay = (function(){ | ||
| var tid = 0; | ||
| return function(callback, ms){ | ||
| clearTimeout(tid); | ||
| tid = setTimeout(callback, ms); | ||
| }; | ||
| })(); | ||
| /* Twitter bootstrap .pager as stack */ | ||
| table.fn._render_bs_stack = function(page, num_pages) { | ||
| var p = opts._selector_pager, a = opts._selector_pager_links; | ||
| if (page < num_pages) { | ||
| $(a).data('page', (page+1)); | ||
| $(p).show(); | ||
| } else { | ||
| $(a).data('page', ''); | ||
| $(p).hide(); | ||
| } | ||
| }; | ||
| /* Twitter bootstrap .pager inner HTML */ | ||
| table.fn._render_bs_pager = function(page, num_pages, hide_prev) { | ||
| var html = '', tp = opts.text_pager_prev, tn = opts.text_pager_next; | ||
| if (page >1 && !hide_prev) { | ||
| html += '<li><a href="#" data-page="'+(page-1)+'">'+tp+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+tp+'</span></li>'; | ||
| } | ||
| if (page < num_pages) { | ||
| html += '<li><a href="#" data-page="'+(page+1)+'">'+tn+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+tn+'</span></li>'; | ||
| } | ||
| $(opts._selector_pager).html(html); | ||
| }; | ||
| /* Twitter bootstrap .pagination inner HTML */ | ||
| table.fn._render_bs_pagination = function(page, num_pages, on_each_side, on_ends) { | ||
| var html = '', | ||
| on_each_side=on_each_side||3, | ||
| on_ends=on_ends||2, | ||
| dot='.', | ||
| page_range = [], | ||
| _push; | ||
| if (page >1) { | ||
| html += '<li><a href="#" data-page="'+(page-1)+'">'+opts.text_pager_prev+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+opts.text_pager_prev+'</span></li>'; | ||
| } | ||
| _push = function(s, e) { for(var i=s; i<e; i++) { page_range.push(i) } }; | ||
| if (num_pages > 9) { | ||
| if (page > (on_each_side + on_ends)) { | ||
| _push(1, on_each_side); | ||
| page_range.push(dot); | ||
| _push(page+1-on_each_side, page+1); | ||
| } else { | ||
| _push(1, page+1) | ||
| } | ||
| if (page < (num_pages - on_each_side - on_ends + 1)) { | ||
| _push(page+1, page+on_each_side); | ||
| page_range.push(dot); | ||
| _push(num_pages-on_ends+1, num_pages+1); | ||
| } else { | ||
| _push(page+1, num_pages+1) | ||
| } | ||
| } else { | ||
| page_range = $.map($(Array(num_pages)), function(val, i) { return i+1; }) | ||
| }; | ||
| $.each(page_range, function(i, item) { | ||
| if (item == dot) { | ||
| html += '<li class="disabled"><span>...</span></li>'; | ||
| } else if (item == page) { | ||
| html += '<li class="active"><span>'+page+'</span></li>'; | ||
| } else { | ||
| html += '<li><a href="#" data-page="'+item+'">'+item+'</a></li>'; | ||
| } | ||
| }); | ||
| if (page < num_pages) { | ||
| html += '<li><a href="#" data-page="'+(page+1)+'">'+opts.text_pager_next+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+opts.text_pager_next+'</span></li>'; | ||
| } | ||
| $(opts._selector_pager).html(html); | ||
| }; | ||
| /* Use default pagination */ | ||
| table.fn.render_pager = function(page, num_pages) { | ||
| if (opts.table_type == 'stack') { | ||
| return table.fn._render_bs_stack(page, num_pages) | ||
| } | ||
| else if (opts.table_type == 'pager') { | ||
| return table.fn._render_bs_pager(page, num_pages, true) | ||
| } | ||
| return table.fn._render_bs_pagination(page, num_pages); | ||
| } | ||
| /* Show/hide not found text */ | ||
| table.fn.alert_not_found = function(show) { | ||
| var $alert = $(opts._selector_alert_not_found); | ||
| show ? $alert.show() : $alert.hide(); | ||
| }; | ||
| /* Rendering information */ | ||
| table.fn.render_info = function(html) { | ||
| $(opts._selector_info).html(html); | ||
| }; | ||
| /* Rendering settings */ | ||
| table.fn.render_settings = function() { | ||
| var html = ''; | ||
| $.each(opts.columns, function(i, col) { | ||
| if (!col.notmanaged) { | ||
| html += '<label>' | ||
| +'<input type="checkbox" name="'+id+'_colswitcher" value="'+(i+1)+'" ' | ||
| +(!col.hidden ? ' checked' : '')+'/>' | ||
| +(col.title||col.name) | ||
| +'</label>' | ||
| } | ||
| }); | ||
| html += '<div class="btn-group" data-toggle="buttons">' | ||
| $.each(opts.limit_list, function(i, limit) { | ||
| html += '<label class="btn'+(opts.limit == limit ? ' active': '')+'">' | ||
| +'<input type="checkbox" name="'+id+'_limit" ' | ||
| +(opts.limit == limit ? ' checked': '')+'>' | ||
| + limit | ||
| +'</label>' | ||
| }); | ||
| html += '</div>' | ||
| $(opts._selector_settings).html(html); | ||
| }; | ||
| /* Returns class for <tr> */ | ||
| table.fn.get_class_tr = function(object) { return object ? '' : 'danger' }; | ||
| /* Rendering one object */ | ||
| table.fn.render_object = function(index, object) { | ||
| if (object == null) return; | ||
| var html = ''; | ||
| html += '<tr class="'+table.fn.get_class_tr(object)+'">'; | ||
| $.each(opts.columns, function(i, col) { | ||
| html += '<td>'+object[col.name]+'</td>'; | ||
| }); | ||
| html += '</tr>'; | ||
| $(opts._selector_tbody).append(html); | ||
| }; | ||
| /* Callback of jqxhr. Rendering all objects, pagination, etc. */ | ||
| table.fn.render = function(json, replace) { | ||
| var data = json.data; | ||
| if (replace) $(opts._selector_tbody).html(''); | ||
| if ($.isEmptyObject(data.objects)) { | ||
| table.fn.alert_not_found(true) | ||
| } else { | ||
| table.fn.alert_not_found(false) | ||
| $.each(data.objects, function(i, item) { | ||
| table.fn.render_object(i, item) | ||
| }) | ||
| } | ||
| table.fn.render_pager(data.page, data.num_pages); | ||
| if (data.info) table.fn.render_info(data.info); | ||
| }; | ||
| /* Request to server on quickAPI. Returns jqxhr. */ | ||
| table.fn.get = function(filters) { | ||
| var replace = opts['replace'], F = filters || {}; | ||
| if (table.request) table.request.abort(); | ||
| table.request = $.quickAPI({ | ||
| url: opts.url, | ||
| timeout: opts.timeout, | ||
| //type: 'POST', | ||
| async: opts.async, | ||
| args: { | ||
| method: opts.method, | ||
| kwargs: { | ||
| filters: $.extend({}, opts.filters, F), | ||
| ordering: opts.ordering, | ||
| page: opts.page, | ||
| limit: opts.limit, | ||
| }, | ||
| }, | ||
| callback: function(json, status, xhr) { return table.fn.render(json, replace) }, | ||
| handlerShowAlert: opts.handlerShowAlert, | ||
| }) | ||
| .always(function() {table.request = null}); | ||
| return table.request | ||
| }; | ||
| /* Request to server from first page by force. */ | ||
| table.fn.get_first_page = function(filters) { | ||
| opts.page = 1; | ||
| opts.replace = true; | ||
| return table.fn.get(filters); | ||
| }; | ||
| /*** END FUNCTIONS ***/ | ||
| /*** START BINDING TABLE CONTROLLERS ON DOCUMENT BODY ***/ | ||
| $('body') | ||
| /* Keyup on character filters */ | ||
| .off('keyup', opts._selector_filtering+':not(input[type=checkbox])') | ||
| .on('keyup', opts._selector_filtering+':not(input[type=checkbox])', function(e) { | ||
| var fname = this.name || opts._default_filter_key, | ||
| old = opts.filters[fname], | ||
| min = Number($(this).data('minimum')) || 0, // minimum chars for query | ||
| len = this.value.length; | ||
| if (this.value != old && (!len || len >= min)) { | ||
| opts.filters[fname] = this.value; | ||
| table.fn.delay(table.fn.get_first_page, opts.delay); | ||
| } | ||
| }) | ||
| /* change on boolean filters */ | ||
| .off('change', opts._selector_filtering+'[type=checkbox]') | ||
| .on('change', opts._selector_filtering+'[type=checkbox]', function(e) { | ||
| var fname = this.name; | ||
| if (fname && this.checked != opts.filters[fname]) { | ||
| opts.filters[fname] = this.checked; | ||
| table.fn.delay(table.fn.get_first_page, 0); | ||
| } | ||
| }) | ||
| /* Change limit on page */ | ||
| .off('change', opts._selector_limiting) | ||
| .on('change', opts._selector_limiting, function(e) { | ||
| opts.limit = this.value; | ||
| table.fn.get_first_page(); | ||
| }) | ||
| /* Change visible of column */ | ||
| .off('change', opts._selector_colswitcher) | ||
| .on('change', opts._selector_colswitcher, function(e) { | ||
| var n = this.value, | ||
| cls = 'table-col-'+n+'-hidden'; | ||
| if (!n) return; | ||
| if (this.checked) { | ||
| $(table).removeClass(cls); | ||
| opts.columns[n-1].hidden = false; | ||
| } else { | ||
| $(table).addClass(cls); | ||
| opts.columns[n-1].hidden = true; | ||
| } | ||
| }) | ||
| /* Change ordering on columns */ | ||
| .off('click', opts._selector_ordering) | ||
| .on('click', opts._selector_ordering, function(e) { | ||
| var column = $(this).attr('name'), L, i; | ||
| if (!column) return; | ||
| L = opts.ordering; | ||
| i = $.inArray(column, L); | ||
| if (!opts.multiordering) { | ||
| $(opts._selector_ordering).removeClass('sorting-asc') | ||
| .removeClass('sorting-desc') | ||
| .addClass('sorting'); | ||
| } | ||
| if (i > -1) { | ||
| //~ console.debug('exists', i, column); | ||
| if (!opts.multiordering) { | ||
| L = ['-'+column]; | ||
| } else { | ||
| L[i] = '-'+column; | ||
| } | ||
| $(this).removeClass('sorting').addClass('sorting-desc'); | ||
| } else { | ||
| //~ console.debug('not exists', i, column); | ||
| i = $.inArray('-'+column, L); | ||
| if (i > -1) { | ||
| //~ console.debug('remove', i, '-'+column); | ||
| if (!opts.multiordering) { | ||
| L = []; | ||
| } else { | ||
| L = L.slice(0,i).concat(L.slice(i+1)); | ||
| } | ||
| $(this).removeClass('sorting-desc').addClass('sorting'); | ||
| } | ||
| } | ||
| if (i == -1){ | ||
| //~ console.debug('not exists', i, '-'+column); | ||
| if (!opts.multiordering) { | ||
| L = [column]; | ||
| } else { | ||
| L.push(column); | ||
| } | ||
| $(this).removeClass('sorting').addClass('sorting-asc'); | ||
| } | ||
| opts.ordering = L; | ||
| table.fn.get_first_page(); | ||
| }) | ||
| /* Click on pagination */ | ||
| .off('click', opts._selector_pager_links) | ||
| .on('click', opts._selector_pager_links, function(e) { | ||
| e.preventDefault(); | ||
| opts.page = $(this).data('page'); | ||
| if (opts.table_type == 'stack') { opts.replace = false }; | ||
| table.fn.get(); | ||
| }); | ||
| /*** END BINDING TABLE CONTROLLERS ***/ | ||
| /* Starting table */ | ||
| if (opts.autorender_settings) table.fn.render_settings(); | ||
| if (opts.autoload) table.fn.get_first_page(); | ||
| return table; | ||
| }; | ||
| }(jQuery)); | ||
| (function(b){var a="quickTable";b.fn[a]=function(c){if(!this.size()){console.error("The selector found nothing");return undefined}if(!c.method){console.error("Not valid options for "+a,{method:c.method},"method must be defined!")}if(b.type(c.columns)!="array"||b.isEmptyObject(c.columns)){console.error("Not valid options for "+a,{columns:c.columns},"columns must be not empty array!");console.info("EXAMPLE:\n",'columns = [ {name:"id", hidden:true, notmanaged:true}, {name:"name", title:"Name"} ]\n',"where `name` - object attribute, `hidden` - hidden column,"," `notmanaged` - the column is not managed, `title` - title of column.")}var e=this[0],f,d;f=b(e).attr("id");if(!f){return this}d=b.extend({timeout:10000,async:true,autoload:true,autorender_settings:true,delay:500,page:1,limit:25,limit_list:[25,50,75,100],filters:{},ordering:[],multiordering:false,table_type:"table",text_pager_prev:"«",text_pager_next:"»",_selector_filtering:"[data-filtering="+f+"]",_selector_ordering:"#"+f+" th[class^=sorting][name]",_selector_limiting:"input[data-limiting="+f+"]:checked, select[data-limiting="+f+"]",_selector_colswitcher:"input[data-colswitcher="+f+"]",_selector_settings:"#"+f+"_settings",_selector_pager:"#"+f+"_pager",_selector_pager_links:"#"+f+"_pager li:not(.disabled) a:not(.disabled)",_selector_info:"#"+f+"_info",_selector_thead:"#"+f+" thead",_selector_tbody:"#"+f+" tbody",_selector_alert_not_found:"[data-notfound="+f+"]",_default_filter_key:"_search_",_managed_columns:[],_column_names:{},},c);e.opts=d;e.request=null;e.fn={};d.replace=true;b.each(d.columns,function(h,g){d._column_names[g.name]=g;if(g.hidden){b(e).addClass("table-col-"+(h+1)+"-hidden")}});e.fn.delay=(function(){var g=0;return function(i,h){clearTimeout(g);g=setTimeout(i,h)}})();e.fn._render_bs_stack=function(i,h){var j=d._selector_pager,g=d._selector_pager_links;if(i<h){b(g).data("page",(i+1));b(j).show()}else{b(g).data("page","");b(j).hide()}};e.fn._render_bs_pager=function(k,j,h){var i="",l=d.text_pager_prev,g=d.text_pager_next;if(k>1&&!h){i+='<li><a href="#" data-page="'+(k-1)+'">'+l+"</a></li>"}else{i+='<li class="disabled"><span>'+l+"</span></li>"}if(k<j){i+='<li><a href="#" data-page="'+(k+1)+'">'+g+"</a></li>"}else{i+='<li class="disabled"><span>'+g+"</span></li>"}b(d._selector_pager).html(i)};e.fn._render_bs_pagination=function(n,m,k,l){var j="",k=k||3,l=l||2,h=".",i=[],g;if(n>1){j+='<li><a href="#" data-page="'+(n-1)+'">'+d.text_pager_prev+"</a></li>"}else{j+='<li class="disabled"><span>'+d.text_pager_prev+"</span></li>"}g=function(p,q){for(var o=p;o<q;o++){i.push(o)}};if(m>9){if(n>(k+l)){g(1,k);i.push(h);g(n+1-k,n+1)}else{g(1,n+1)}if(n<(m-k-l+1)){g(n+1,n+k);i.push(h);g(m-l+1,m+1)}else{g(n+1,m+1)}}else{i=b.map(b(Array(m)),function(p,o){return o+1})}b.each(i,function(o,p){if(p==h){j+='<li class="disabled"><span>...</span></li>'}else{if(p==n){j+='<li class="active"><span>'+n+"</span></li>"}else{j+='<li><a href="#" data-page="'+p+'">'+p+"</a></li>"}}});if(n<m){j+='<li><a href="#" data-page="'+(n+1)+'">'+d.text_pager_next+"</a></li>"}else{j+='<li class="disabled"><span>'+d.text_pager_next+"</span></li>"}b(d._selector_pager).html(j)};e.fn.render_pager=function(h,g){if(d.table_type=="stack"){return e.fn._render_bs_stack(h,g)}else{if(d.table_type=="pager"){return e.fn._render_bs_pager(h,g,true)}}return e.fn._render_bs_pagination(h,g)};e.fn.alert_not_found=function(g){var h=b(d._selector_alert_not_found);g?h.show():h.hide()};e.fn.render_info=function(g){b(d._selector_info).html(g)};e.fn.render_settings=function(){var g="";b.each(d.columns,function(j,h){if(!h.notmanaged){g+='<label><input type="checkbox" name="'+f+'_colswitcher" value="'+(j+1)+'" '+(!h.hidden?" checked":"")+"/>"+(h.title||h.name)+"</label>"}});g+='<div class="btn-group" data-toggle="buttons">';b.each(d.limit_list,function(j,h){g+='<label class="btn'+(d.limit==h?" active":"")+'"><input type="checkbox" name="'+f+'_limit" '+(d.limit==h?" checked":"")+">"+h+"</label>"});g+="</div>";b(d._selector_settings).html(g)};e.fn.get_class_tr=function(g){return g?"":"danger"};e.fn.render_object=function(h,g){if(g==null){return}var i="";i+='<tr class="'+e.fn.get_class_tr(g)+'">';b.each(d.columns,function(k,j){i+="<td>"+g[j.name]+"</td>"});i+="</tr>";b(d._selector_tbody).append(i)};e.fn.render=function(h,g){var i=h.data;if(g){b(d._selector_tbody).html("")}if(b.isEmptyObject(i.objects)){e.fn.alert_not_found(true)}else{e.fn.alert_not_found(false);b.each(i.objects,function(j,k){e.fn.render_object(j,k)})}e.fn.render_pager(i.page,i.num_pages);if(i.info){e.fn.render_info(i.info)}};e.fn.get=function(i){var g=d.replace,h=i||{};if(e.request){e.request.abort()}e.request=b.quickAPI({url:d.url,timeout:d.timeout,async:d.async,args:{method:d.method,kwargs:{filters:b.extend({},d.filters,h),ordering:d.ordering,page:d.page,limit:d.limit,},},callback:function(k,j,l){return e.fn.render(k,g)},handlerShowAlert:d.handlerShowAlert,}).always(function(){e.request=null});return e.request};e.fn.get_first_page=function(g){d.page=1;d.replace=true;return e.fn.get(g)};b("body").off("keyup",d._selector_filtering+":not(input[type=checkbox])").on("keyup",d._selector_filtering+":not(input[type=checkbox])",function(j){var k=this.name||d._default_filter_key,h=d.filters[k],i=Number(b(this).data("minimum"))||0,g=this.value.length;if(this.value!=h&&(!g||g>=i)){d.filters[k]=this.value;e.fn.delay(e.fn.get_first_page,d.delay)}}).off("change",d._selector_filtering+"[type=checkbox]").on("change",d._selector_filtering+"[type=checkbox]",function(g){var h=this.name;if(h&&this.checked!=d.filters[h]){d.filters[h]=this.checked;e.fn.delay(e.fn.get_first_page,0)}}).off("change",d._selector_limiting).on("change",d._selector_limiting,function(g){d.limit=this.value;e.fn.get_first_page()}).off("change",d._selector_colswitcher).on("change",d._selector_colswitcher,function(h){var i=this.value,g="table-col-"+i+"-hidden";if(!i){return}if(this.checked){b(e).removeClass(g);d.columns[i-1].hidden=false}else{b(e).addClass(g);d.columns[i-1].hidden=true}}).off("click",d._selector_ordering).on("click",d._selector_ordering,function(k){var j=b(this).attr("name"),g,h;if(!j){return}g=d.ordering;h=b.inArray(j,g);if(!d.multiordering){b(d._selector_ordering).removeClass("sorting-asc").removeClass("sorting-desc").addClass("sorting")}if(h>-1){if(!d.multiordering){g=["-"+j]}else{g[h]="-"+j}b(this).removeClass("sorting").addClass("sorting-desc")}else{h=b.inArray("-"+j,g);if(h>-1){if(!d.multiordering){g=[]}else{g=g.slice(0,h).concat(g.slice(h+1))}b(this).removeClass("sorting-desc").addClass("sorting")}}if(h==-1){if(!d.multiordering){g=[j]}else{g.push(j)}b(this).removeClass("sorting").addClass("sorting-asc")}d.ordering=g;e.fn.get_first_page()}).off("click",d._selector_pager_links).on("click",d._selector_pager_links,function(g){g.preventDefault();d.page=b(this).data("page");if(d.table_type=="stack"){d.replace=false}e.fn.get()});if(d.autorender_settings){e.fn.render_settings()}if(d.autoload){e.fn.get_first_page()}return e}}(jQuery)); |
| Metadata-Version: 1.1 | ||
| Name: django-quickapi | ||
| Version: 3.5.2 | ||
| Version: 3.5.3 | ||
| Summary: The Django-application for the fast organization API. | ||
@@ -5,0 +5,0 @@ Home-page: https://bitbucket.org/rosix/django-quickapi/ |
@@ -106,17 +106,17 @@ AUTHORS | ||
| quickapi/static/pygments/2.0/xcode.css | ||
| quickapi/static/quickapi/3.5.2/css/quicktable.css | ||
| quickapi/static/quickapi/3.5.2/css/quicktable.min.css | ||
| quickapi/static/quickapi/3.5.2/img/favicon.png | ||
| quickapi/static/quickapi/3.5.2/img/logo.png | ||
| quickapi/static/quickapi/3.5.2/img/logo.svg | ||
| quickapi/static/quickapi/3.5.2/img/logo_black.png | ||
| quickapi/static/quickapi/3.5.2/img/tables/sort_asc.png | ||
| quickapi/static/quickapi/3.5.2/img/tables/sort_both.png | ||
| quickapi/static/quickapi/3.5.2/img/tables/sort_desc.png | ||
| quickapi/static/quickapi/3.5.2/js/jquery.quickapi.full.js | ||
| quickapi/static/quickapi/3.5.2/js/jquery.quickapi.full.min.js | ||
| quickapi/static/quickapi/3.5.2/js/jquery.quickapi.js | ||
| quickapi/static/quickapi/3.5.2/js/jquery.quickapi.min.js | ||
| quickapi/static/quickapi/3.5.2/js/jquery.quicktable.js | ||
| quickapi/static/quickapi/3.5.2/js/jquery.quicktable.min.js | ||
| quickapi/static/quickapi/3.5.3/css/quicktable.css | ||
| quickapi/static/quickapi/3.5.3/css/quicktable.min.css | ||
| quickapi/static/quickapi/3.5.3/img/favicon.png | ||
| quickapi/static/quickapi/3.5.3/img/logo.png | ||
| quickapi/static/quickapi/3.5.3/img/logo.svg | ||
| quickapi/static/quickapi/3.5.3/img/logo_black.png | ||
| quickapi/static/quickapi/3.5.3/img/tables/sort_asc.png | ||
| quickapi/static/quickapi/3.5.3/img/tables/sort_both.png | ||
| quickapi/static/quickapi/3.5.3/img/tables/sort_desc.png | ||
| quickapi/static/quickapi/3.5.3/js/jquery.quickapi.full.js | ||
| quickapi/static/quickapi/3.5.3/js/jquery.quickapi.full.min.js | ||
| quickapi/static/quickapi/3.5.3/js/jquery.quickapi.js | ||
| quickapi/static/quickapi/3.5.3/js/jquery.quickapi.min.js | ||
| quickapi/static/quickapi/3.5.3/js/jquery.quicktable.js | ||
| quickapi/static/quickapi/3.5.3/js/jquery.quicktable.min.js | ||
| quickapi/static_src/css/quicktable.css | ||
@@ -123,0 +123,0 @@ quickapi/static_src/css/quicktable.less |
+1
-1
| Metadata-Version: 1.1 | ||
| Name: django-quickapi | ||
| Version: 3.5.2 | ||
| Version: 3.5.3 | ||
| Summary: The Django-application for the fast organization API. | ||
@@ -5,0 +5,0 @@ Home-page: https://bitbucket.org/rosix/django-quickapi/ |
@@ -22,3 +22,3 @@ # -*- coding: utf-8 -*- | ||
| VERSION = (3, 5, 2) | ||
| VERSION = (3, 5, 3) | ||
@@ -25,0 +25,0 @@ def get_version(*args, **kwargs): |
+13
-3
@@ -175,7 +175,18 @@ # coding: utf-8 | ||
| if encoding in ('gzip', 'deflate'): | ||
| if encoding in ('gzip', 'zlib'): | ||
| try: | ||
| return zlib.decompress(data) | ||
| # automatic header detection (zlib or gzip) | ||
| return zlib.decompress(data, zlib.MAX_WBITS|32) | ||
| except: | ||
| return data | ||
| elif encoding == 'deflate': | ||
| try: | ||
| # strict deflate format | ||
| return zlib.decompress(data, -zlib.MAX_WBITS) | ||
| except: | ||
| try: | ||
| # really zlib format | ||
| return zlib.decompress(data) | ||
| except: | ||
| return data | ||
@@ -188,3 +199,2 @@ return data | ||
| """ | ||
| data = data.decode(self.code_page) | ||
@@ -191,0 +201,0 @@ data = json.loads(data) |
| /* | ||
| * quicktable.less | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| .table-col-1-hidden th:nth-child(1), | ||
| .table-col-1-hidden td:nth-child(1) { | ||
| display: none; | ||
| } | ||
| .table-col-2-hidden th:nth-child(2), | ||
| .table-col-2-hidden td:nth-child(2) { | ||
| display: none; | ||
| } | ||
| .table-col-3-hidden th:nth-child(3), | ||
| .table-col-3-hidden td:nth-child(3) { | ||
| display: none; | ||
| } | ||
| .table-col-4-hidden th:nth-child(4), | ||
| .table-col-4-hidden td:nth-child(4) { | ||
| display: none; | ||
| } | ||
| .table-col-5-hidden th:nth-child(5), | ||
| .table-col-5-hidden td:nth-child(5) { | ||
| display: none; | ||
| } | ||
| .table-col-6-hidden th:nth-child(6), | ||
| .table-col-6-hidden td:nth-child(6) { | ||
| display: none; | ||
| } | ||
| .table-col-7-hidden th:nth-child(7), | ||
| .table-col-7-hidden td:nth-child(7) { | ||
| display: none; | ||
| } | ||
| .table-col-8-hidden th:nth-child(8), | ||
| .table-col-8-hidden td:nth-child(8) { | ||
| display: none; | ||
| } | ||
| .table-col-9-hidden th:nth-child(9), | ||
| .table-col-9-hidden td:nth-child(9) { | ||
| display: none; | ||
| } | ||
| .table-col-10-hidden th:nth-child(10), | ||
| .table-col-10-hidden td:nth-child(10) { | ||
| display: none; | ||
| } | ||
| .table-col-11-hidden th:nth-child(11), | ||
| .table-col-11-hidden td:nth-child(11) { | ||
| display: none; | ||
| } | ||
| .table-col-12-hidden th:nth-child(12), | ||
| .table-col-12-hidden td:nth-child(12) { | ||
| display: none; | ||
| } | ||
| .table-col-13-hidden th:nth-child(13), | ||
| .table-col-13-hidden td:nth-child(13) { | ||
| display: none; | ||
| } | ||
| .table-col-14-hidden th:nth-child(14), | ||
| .table-col-14-hidden td:nth-child(14) { | ||
| display: none; | ||
| } | ||
| .table-col-15-hidden th:nth-child(15), | ||
| .table-col-15-hidden td:nth-child(15) { | ||
| display: none; | ||
| } | ||
| .table-col-16-hidden th:nth-child(16), | ||
| .table-col-16-hidden td:nth-child(16) { | ||
| display: none; | ||
| } | ||
| .table-col-17-hidden th:nth-child(17), | ||
| .table-col-17-hidden td:nth-child(17) { | ||
| display: none; | ||
| } | ||
| .table-col-18-hidden th:nth-child(18), | ||
| .table-col-18-hidden td:nth-child(18) { | ||
| display: none; | ||
| } | ||
| .table-col-19-hidden th:nth-child(19), | ||
| .table-col-19-hidden td:nth-child(19) { | ||
| display: none; | ||
| } | ||
| .table-col-20-hidden th:nth-child(20), | ||
| .table-col-20-hidden td:nth-child(20) { | ||
| display: none; | ||
| } | ||
| .table-col-21-hidden th:nth-child(21), | ||
| .table-col-21-hidden td:nth-child(21) { | ||
| display: none; | ||
| } | ||
| .table-col-22-hidden th:nth-child(22), | ||
| .table-col-22-hidden td:nth-child(22) { | ||
| display: none; | ||
| } | ||
| .table-col-23-hidden th:nth-child(23), | ||
| .table-col-23-hidden td:nth-child(23) { | ||
| display: none; | ||
| } | ||
| .table-col-24-hidden th:nth-child(24), | ||
| .table-col-24-hidden td:nth-child(24) { | ||
| display: none; | ||
| } | ||
| .table-col-25-hidden th:nth-child(25), | ||
| .table-col-25-hidden td:nth-child(25) { | ||
| display: none; | ||
| } | ||
| .table-col-26-hidden th:nth-child(26), | ||
| .table-col-26-hidden td:nth-child(26) { | ||
| display: none; | ||
| } | ||
| .table-col-27-hidden th:nth-child(27), | ||
| .table-col-27-hidden td:nth-child(27) { | ||
| display: none; | ||
| } | ||
| .table-col-28-hidden th:nth-child(28), | ||
| .table-col-28-hidden td:nth-child(28) { | ||
| display: none; | ||
| } | ||
| .table-col-29-hidden th:nth-child(29), | ||
| .table-col-29-hidden td:nth-child(29) { | ||
| display: none; | ||
| } | ||
| .table-col-30-hidden th:nth-child(30), | ||
| .table-col-30-hidden td:nth-child(30) { | ||
| display: none; | ||
| } | ||
| /* | ||
| * Sorting | ||
| */ | ||
| th.sorting { | ||
| cursor: pointer; | ||
| background: url('../img/tables/sort_both.png') no-repeat center right; | ||
| } | ||
| th.sorting-asc { | ||
| cursor: pointer; | ||
| background: url('../img/tables/sort_asc.png') no-repeat center right; | ||
| } | ||
| th.sorting-desc { | ||
| cursor: pointer; | ||
| background: url('../img/tables/sort_desc.png') no-repeat center right; | ||
| } | ||
| th.sorting-n0 { | ||
| background-color: #FFE6E6; | ||
| } | ||
| th.sorting-n1 { | ||
| background-color: #FFF9E6; | ||
| } | ||
| th.sorting-n2 { | ||
| background-color: #F3FFE6; | ||
| } | ||
| th.sorting-n3 { | ||
| background-color: #E6FFED; | ||
| } | ||
| th.sorting-n4 { | ||
| background-color: #E6FFFF; | ||
| } |
| .table-col-1-hidden th:nth-child(1),.table-col-1-hidden td:nth-child(1){display:none}.table-col-2-hidden th:nth-child(2),.table-col-2-hidden td:nth-child(2){display:none}.table-col-3-hidden th:nth-child(3),.table-col-3-hidden td:nth-child(3){display:none}.table-col-4-hidden th:nth-child(4),.table-col-4-hidden td:nth-child(4){display:none}.table-col-5-hidden th:nth-child(5),.table-col-5-hidden td:nth-child(5){display:none}.table-col-6-hidden th:nth-child(6),.table-col-6-hidden td:nth-child(6){display:none}.table-col-7-hidden th:nth-child(7),.table-col-7-hidden td:nth-child(7){display:none}.table-col-8-hidden th:nth-child(8),.table-col-8-hidden td:nth-child(8){display:none}.table-col-9-hidden th:nth-child(9),.table-col-9-hidden td:nth-child(9){display:none}.table-col-10-hidden th:nth-child(10),.table-col-10-hidden td:nth-child(10){display:none}.table-col-11-hidden th:nth-child(11),.table-col-11-hidden td:nth-child(11){display:none}.table-col-12-hidden th:nth-child(12),.table-col-12-hidden td:nth-child(12){display:none}.table-col-13-hidden th:nth-child(13),.table-col-13-hidden td:nth-child(13){display:none}.table-col-14-hidden th:nth-child(14),.table-col-14-hidden td:nth-child(14){display:none}.table-col-15-hidden th:nth-child(15),.table-col-15-hidden td:nth-child(15){display:none}.table-col-16-hidden th:nth-child(16),.table-col-16-hidden td:nth-child(16){display:none}.table-col-17-hidden th:nth-child(17),.table-col-17-hidden td:nth-child(17){display:none}.table-col-18-hidden th:nth-child(18),.table-col-18-hidden td:nth-child(18){display:none}.table-col-19-hidden th:nth-child(19),.table-col-19-hidden td:nth-child(19){display:none}.table-col-20-hidden th:nth-child(20),.table-col-20-hidden td:nth-child(20){display:none}.table-col-21-hidden th:nth-child(21),.table-col-21-hidden td:nth-child(21){display:none}.table-col-22-hidden th:nth-child(22),.table-col-22-hidden td:nth-child(22){display:none}.table-col-23-hidden th:nth-child(23),.table-col-23-hidden td:nth-child(23){display:none}.table-col-24-hidden th:nth-child(24),.table-col-24-hidden td:nth-child(24){display:none}.table-col-25-hidden th:nth-child(25),.table-col-25-hidden td:nth-child(25){display:none}.table-col-26-hidden th:nth-child(26),.table-col-26-hidden td:nth-child(26){display:none}.table-col-27-hidden th:nth-child(27),.table-col-27-hidden td:nth-child(27){display:none}.table-col-28-hidden th:nth-child(28),.table-col-28-hidden td:nth-child(28){display:none}.table-col-29-hidden th:nth-child(29),.table-col-29-hidden td:nth-child(29){display:none}.table-col-30-hidden th:nth-child(30),.table-col-30-hidden td:nth-child(30){display:none}th.sorting{cursor:pointer;background:url('../img/tables/sort_both.png') no-repeat center right}th.sorting-asc{cursor:pointer;background:url('../img/tables/sort_asc.png') no-repeat center right}th.sorting-desc{cursor:pointer;background:url('../img/tables/sort_desc.png') no-repeat center right}th.sorting-n0{background-color:#ffe6e6}th.sorting-n1{background-color:#fff9e6}th.sorting-n2{background-color:#f3ffe6}th.sorting-n3{background-color:#e6ffed}th.sorting-n4{background-color:#e6ffff} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| <!-- Created with Inkscape (http://www.inkscape.org/) --> | ||
| <svg | ||
| xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
| xmlns:cc="http://creativecommons.org/ns#" | ||
| xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
| xmlns:svg="http://www.w3.org/2000/svg" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | ||
| xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | ||
| width="512" | ||
| height="512" | ||
| id="svg2" | ||
| version="1.1" | ||
| inkscape:version="0.48.3.1 r9886" | ||
| sodipodi:docname="Новый документ 1"> | ||
| <defs | ||
| id="defs4" /> | ||
| <sodipodi:namedview | ||
| id="base" | ||
| pagecolor="#ffffff" | ||
| bordercolor="#666666" | ||
| borderopacity="1.0" | ||
| inkscape:pageopacity="0.0" | ||
| inkscape:pageshadow="2" | ||
| inkscape:zoom="0.98994949" | ||
| inkscape:cx="151.81944" | ||
| inkscape:cy="110.42142" | ||
| inkscape:document-units="px" | ||
| inkscape:current-layer="layer1" | ||
| showgrid="false" | ||
| inkscape:window-width="1920" | ||
| inkscape:window-height="1007" | ||
| inkscape:window-x="0" | ||
| inkscape:window-y="25" | ||
| inkscape:window-maximized="1" /> | ||
| <metadata | ||
| id="metadata7"> | ||
| <rdf:RDF> | ||
| <cc:Work | ||
| rdf:about=""> | ||
| <dc:format>image/svg+xml</dc:format> | ||
| <dc:type | ||
| rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> | ||
| <dc:title></dc:title> | ||
| </cc:Work> | ||
| </rdf:RDF> | ||
| </metadata> | ||
| <g | ||
| inkscape:label="Layer 1" | ||
| inkscape:groupmode="layer" | ||
| id="layer1" | ||
| transform="translate(0,-540.36218)"> | ||
| <text | ||
| xml:space="preserve" | ||
| style="font-size:45.36851882999999930px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans" | ||
| x="565.0733" | ||
| y="467.22543" | ||
| id="text2985" | ||
| sodipodi:linespacing="125%" | ||
| transform="matrix(0,1.0020188,0.99798526,0,0,0)"><tspan | ||
| sodipodi:role="line" | ||
| id="tspan2987" | ||
| x="565.0733" | ||
| y="467.22543" | ||
| style="font-size:580.71704102000001058px;fill:#000000">Q</tspan></text> | ||
| <text | ||
| xml:space="preserve" | ||
| style="font-size:38.25341797px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans" | ||
| x="102.27046" | ||
| y="846.42297" | ||
| id="text2996" | ||
| sodipodi:linespacing="125%" | ||
| transform="scale(0.98903946,1.011082)"><tspan | ||
| sodipodi:role="line" | ||
| id="tspan2998" | ||
| x="102.27046" | ||
| y="846.42297" | ||
| style="font-size:172.14039612px;font-weight:bold;fill:#000000;-inkscape-font-specification:Sans Bold">API</tspan></text> | ||
| </g> | ||
| </svg> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| /** | ||
| * jquery.quickapi.js - jQuery plugin for QuickAPI application | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| (function ($) { | ||
| /* Общая функция для работы с django-quickapi | ||
| * | ||
| * Документация: | ||
| * https://docs.rosix.ru/django-quickapi/wiki/jquery.html#quickapi | ||
| * | ||
| */ | ||
| $.quickAPI = function(opts) { | ||
| var data, options = opts || new Object(); | ||
| // `args` is deprecation option | ||
| if (!options.data) options.data = options.args || { method: "quickapi.test" }; | ||
| if (options.simple || options.type == 'GET') { | ||
| data = options.data; | ||
| if (!data.language) data.language = options.language || window.LANGUAGE_CODE | ||
| } else { | ||
| data = { | ||
| jsonData: $.toJSON(options.data), | ||
| language: options.language || window.LANGUAGE_CODE | ||
| } | ||
| } | ||
| var jqxhr, | ||
| settings = { | ||
| type: options.type || "POST", | ||
| async: options.sync === true ? false : options.async === false ? false : true, | ||
| timeout: options.timeout || window.AJAX_TIMEOUT || 3000, | ||
| url: options.url || window.QUICKAPI_URL || location.pathname, | ||
| data: data, | ||
| dataType: 'json', | ||
| }, | ||
| callback = options.callback || function(json, status, xhr) {}, | ||
| showAlert = options.handlerShowAlert || window.handlerShowAlert || function(head, msg, cls, cb) { | ||
| var match; | ||
| if ($.type(msg) == 'object') { | ||
| msg = $.toJSON(msg) | ||
| .replace(/\,\"/g, ', "') | ||
| .replace(/\"\:/g, '": ') | ||
| } | ||
| else if (msg.match(/<\!DOCTYPE/)) { | ||
| match = msg.match(/<[title,TITLE]+>(.*)<\/[title,TITLE]+>/); | ||
| if (match) head = match[1]; | ||
| match = msg.match(/<[body,BODY]+>([^+]*)<\/[body,BODY]+>/); | ||
| if (match) { | ||
| msg = match[1] | ||
| .replace(/<\/?[^>]+>/g, '') | ||
| .replace(/ [ ]+/g, ' ') | ||
| .replace(/\n[\n]+/g, '\n') | ||
| } else { | ||
| msg = ''; | ||
| } | ||
| } | ||
| if (msg.length > 512) { | ||
| msg = msg.substring(0, 512) + ' ...' | ||
| }; | ||
| alert(head +'\n'+ msg); | ||
| if (cb) { return cb() }; | ||
| return null | ||
| }; | ||
| jqxhr = $.ajax(settings) | ||
| // Обработка ошибок протокола HTTP | ||
| .fail(function(xhr, status, err) { | ||
| // Если есть переадресация, то выполняем её | ||
| if (xhr.getResponseHeader('Location')) { | ||
| location.replace(xhr.getResponseHeader('Location')); | ||
| } else if (xhr.responseText) { | ||
| // Иначе извещаем пользователя ответом и в консоль | ||
| console.error("ERROR:", xhr.responseText); | ||
| showAlert("ERROR:", xhr.responseText, 'alert-danger') | ||
| } | ||
| }) | ||
| // Обработка полученных данных | ||
| .done(function(json, status, xhr) { | ||
| if (options.log && window.DEBUG) {console.debug(options.log)}; | ||
| /* При переадресации нужно отобразить сообщение на некоторое время, | ||
| * а затем выполнить переход по ссылке | ||
| */ | ||
| if ((json.status >=300) && (json.status <400) && (json.data.Location != undefined)) { | ||
| var loc = json.data.Location, redirect; | ||
| redirect = function() { location.replace(loc) }; | ||
| console.info("REDIRECT:" + loc); | ||
| if (json.message) { | ||
| showAlert("REDIRECT:", json.message, 'alert-danger', redirect) | ||
| } else { | ||
| redirect() | ||
| } | ||
| } | ||
| /* При ошибках извещаем пользователя полученным сообщением */ | ||
| else if (json.status >=400) { | ||
| showAlert("ERROR:", json.message, 'alert-danger'); | ||
| } | ||
| /* При нормальном возврате в debug-режиме выводим в консоль | ||
| * сообщение | ||
| */ | ||
| else { | ||
| if (window.DEBUG) { | ||
| console.debug($.toJSON(json.message)); | ||
| if (options.data.method == "quickapi.test") { | ||
| console.debug(json.data) | ||
| } | ||
| }; | ||
| return callback(json, status, xhr) | ||
| } | ||
| }); | ||
| return jqxhr | ||
| } | ||
| }(jQuery)); | ||
| /* | ||
| * jquery.quicktable.js - jQuery plugin for QuickAPI application | ||
| * | ||
| * depends: | ||
| * jquery.quickapi.js - jQuery plugin for QuickAPI | ||
| * recommends: | ||
| * Twitter bootstrap >= 3.0 | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| (function ($) { | ||
| /* Плагин для работы с QuickTable из состава django-quickapi | ||
| * | ||
| * Документация: | ||
| * https://docs.rosix.ru/django-quickapi/wiki/jquery.html#quicktable | ||
| * | ||
| */ | ||
| var pluginName = "quickTable"; | ||
| $.fn[pluginName] = function(options) { | ||
| if (!this.size()) { console.error('The selector found nothing'); return undefined }; | ||
| if (!options.method) { | ||
| console.error( | ||
| "Not valid options for "+pluginName, | ||
| { method:options.method }, | ||
| 'method must be defined!' | ||
| ); | ||
| }; | ||
| if ($.type(options.columns) != 'array' || $.isEmptyObject(options.columns)) { | ||
| console.error( | ||
| "Not valid options for "+pluginName, | ||
| { columns:options.columns }, | ||
| 'columns must be not empty array!' | ||
| ); | ||
| console.info('EXAMPLE:\n', | ||
| 'columns = [ {name:"id", hidden:true, notmanaged:true}, {name:"name", title:"Name"} ]\n', | ||
| 'where `name` - object attribute, `hidden` - hidden column,', | ||
| ' `notmanaged` - the column is not managed, `title` - title of column.' | ||
| ); | ||
| }; | ||
| var table = this[0], id, opts; | ||
| id = $(table).attr('id'); | ||
| if (!id) { return this }; // not valid | ||
| opts = $.extend({ | ||
| //url: undefined, | ||
| //method: undefined, | ||
| //columns: undefined, | ||
| //handlerShowAlert: undefined, | ||
| timeout: 10000, | ||
| async: true, | ||
| autoload: true, | ||
| autorender_settings: true, | ||
| delay: 500, | ||
| page: 1, | ||
| limit: 25, | ||
| limit_list: [25, 50, 75, 100], | ||
| filters: {}, | ||
| ordering: [], | ||
| multiordering: false, | ||
| table_type: 'table', // variants: 'stack' or 'pager' | ||
| text_pager_prev: '«', | ||
| text_pager_next: '»', | ||
| // the following variables are strongly advised not to change | ||
| _selector_filtering: '[data-filtering='+id+']', | ||
| _selector_ordering: '#'+id+' th[class^=sorting][name]', | ||
| _selector_limiting: 'input[data-limiting='+id+']:checked, select[data-limiting='+id+']', | ||
| _selector_colswitcher: 'input[data-colswitcher='+id+']', | ||
| _selector_settings: '#'+id+'_settings', | ||
| _selector_pager: '#'+id+'_pager', | ||
| _selector_pager_links: '#'+id+'_pager li:not(.disabled) a:not(.disabled)', | ||
| _selector_info: '#'+id+'_info', | ||
| _selector_thead: '#'+id+' thead', | ||
| _selector_tbody: '#'+id+' tbody', | ||
| _selector_alert_not_found: '[data-notfound='+id+']', | ||
| _default_filter_key: '_search_', | ||
| _managed_columns: [], | ||
| _column_names: {}, | ||
| }, options); | ||
| table.opts = opts; // link | ||
| table.request = null; // current jqxhr | ||
| table.fn = {}; // storage for functions | ||
| opts.replace = true; // append or overwrite tbody | ||
| $.each(opts.columns, function(i, col) { | ||
| opts._column_names[col.name] = col; | ||
| if (col.hidden) $(table).addClass('table-col-'+(i+1)+'-hidden'); | ||
| }); | ||
| /*** START FUNCTIONS ***/ | ||
| /* Delay for keyup in filters */ | ||
| table.fn.delay = (function(){ | ||
| var tid = 0; | ||
| return function(callback, ms){ | ||
| clearTimeout(tid); | ||
| tid = setTimeout(callback, ms); | ||
| }; | ||
| })(); | ||
| /* Twitter bootstrap .pager as stack */ | ||
| table.fn._render_bs_stack = function(page, num_pages) { | ||
| var p = opts._selector_pager, a = opts._selector_pager_links; | ||
| if (page < num_pages) { | ||
| $(a).data('page', (page+1)); | ||
| $(p).show(); | ||
| } else { | ||
| $(a).data('page', ''); | ||
| $(p).hide(); | ||
| } | ||
| }; | ||
| /* Twitter bootstrap .pager inner HTML */ | ||
| table.fn._render_bs_pager = function(page, num_pages, hide_prev) { | ||
| var html = '', tp = opts.text_pager_prev, tn = opts.text_pager_next; | ||
| if (page >1 && !hide_prev) { | ||
| html += '<li><a href="#" data-page="'+(page-1)+'">'+tp+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+tp+'</span></li>'; | ||
| } | ||
| if (page < num_pages) { | ||
| html += '<li><a href="#" data-page="'+(page+1)+'">'+tn+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+tn+'</span></li>'; | ||
| } | ||
| $(opts._selector_pager).html(html); | ||
| }; | ||
| /* Twitter bootstrap .pagination inner HTML */ | ||
| table.fn._render_bs_pagination = function(page, num_pages, on_each_side, on_ends) { | ||
| var html = '', | ||
| on_each_side=on_each_side||3, | ||
| on_ends=on_ends||2, | ||
| dot='.', | ||
| page_range = [], | ||
| _push; | ||
| if (page >1) { | ||
| html += '<li><a href="#" data-page="'+(page-1)+'">'+opts.text_pager_prev+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+opts.text_pager_prev+'</span></li>'; | ||
| } | ||
| _push = function(s, e) { for(var i=s; i<e; i++) { page_range.push(i) } }; | ||
| if (num_pages > 9) { | ||
| if (page > (on_each_side + on_ends)) { | ||
| _push(1, on_each_side); | ||
| page_range.push(dot); | ||
| _push(page+1-on_each_side, page+1); | ||
| } else { | ||
| _push(1, page+1) | ||
| } | ||
| if (page < (num_pages - on_each_side - on_ends + 1)) { | ||
| _push(page+1, page+on_each_side); | ||
| page_range.push(dot); | ||
| _push(num_pages-on_ends+1, num_pages+1); | ||
| } else { | ||
| _push(page+1, num_pages+1) | ||
| } | ||
| } else { | ||
| page_range = $.map($(Array(num_pages)), function(val, i) { return i+1; }) | ||
| }; | ||
| $.each(page_range, function(i, item) { | ||
| if (item == dot) { | ||
| html += '<li class="disabled"><span>...</span></li>'; | ||
| } else if (item == page) { | ||
| html += '<li class="active"><span>'+page+'</span></li>'; | ||
| } else { | ||
| html += '<li><a href="#" data-page="'+item+'">'+item+'</a></li>'; | ||
| } | ||
| }); | ||
| if (page < num_pages) { | ||
| html += '<li><a href="#" data-page="'+(page+1)+'">'+opts.text_pager_next+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+opts.text_pager_next+'</span></li>'; | ||
| } | ||
| $(opts._selector_pager).html(html); | ||
| }; | ||
| /* Use default pagination */ | ||
| table.fn.render_pager = function(page, num_pages) { | ||
| if (opts.table_type == 'stack') { | ||
| return table.fn._render_bs_stack(page, num_pages) | ||
| } | ||
| else if (opts.table_type == 'pager') { | ||
| return table.fn._render_bs_pager(page, num_pages, true) | ||
| } | ||
| return table.fn._render_bs_pagination(page, num_pages); | ||
| } | ||
| /* Show/hide not found text */ | ||
| table.fn.alert_not_found = function(show) { | ||
| var $alert = $(opts._selector_alert_not_found); | ||
| show ? $alert.show() : $alert.hide(); | ||
| }; | ||
| /* Rendering information */ | ||
| table.fn.render_info = function(html) { | ||
| $(opts._selector_info).html(html); | ||
| }; | ||
| /* Rendering settings */ | ||
| table.fn.render_settings = function() { | ||
| var html = ''; | ||
| $.each(opts.columns, function(i, col) { | ||
| if (!col.notmanaged) { | ||
| html += '<label>' | ||
| +'<input type="checkbox" name="'+id+'_colswitcher" value="'+(i+1)+'" ' | ||
| +(!col.hidden ? ' checked' : '')+'/>' | ||
| +(col.title||col.name) | ||
| +'</label>' | ||
| } | ||
| }); | ||
| html += '<div class="btn-group" data-toggle="buttons">' | ||
| $.each(opts.limit_list, function(i, limit) { | ||
| html += '<label class="btn'+(opts.limit == limit ? ' active': '')+'">' | ||
| +'<input type="checkbox" name="'+id+'_limit" ' | ||
| +(opts.limit == limit ? ' checked': '')+'>' | ||
| + limit | ||
| +'</label>' | ||
| }); | ||
| html += '</div>' | ||
| $(opts._selector_settings).html(html); | ||
| }; | ||
| /* Returns class for <tr> */ | ||
| table.fn.get_class_tr = function(object) { return object ? '' : 'danger' }; | ||
| /* Rendering one object */ | ||
| table.fn.render_object = function(index, object) { | ||
| if (object == null) return; | ||
| var html = ''; | ||
| html += '<tr class="'+table.fn.get_class_tr(object)+'">'; | ||
| $.each(opts.columns, function(i, col) { | ||
| html += '<td>'+object[col.name]+'</td>'; | ||
| }); | ||
| html += '</tr>'; | ||
| $(opts._selector_tbody).append(html); | ||
| }; | ||
| /* Callback of jqxhr. Rendering all objects, pagination, etc. */ | ||
| table.fn.render = function(json, replace) { | ||
| var data = json.data; | ||
| if (replace) $(opts._selector_tbody).html(''); | ||
| if ($.isEmptyObject(data.objects)) { | ||
| table.fn.alert_not_found(true) | ||
| } else { | ||
| table.fn.alert_not_found(false) | ||
| $.each(data.objects, function(i, item) { | ||
| table.fn.render_object(i, item) | ||
| }) | ||
| } | ||
| table.fn.render_pager(data.page, data.num_pages); | ||
| if (data.info) table.fn.render_info(data.info); | ||
| }; | ||
| /* Request to server on quickAPI. Returns jqxhr. */ | ||
| table.fn.get = function(filters) { | ||
| var replace = opts['replace'], F = filters || {}; | ||
| if (table.request) table.request.abort(); | ||
| table.request = $.quickAPI({ | ||
| url: opts.url, | ||
| timeout: opts.timeout, | ||
| //type: 'POST', | ||
| async: opts.async, | ||
| args: { | ||
| method: opts.method, | ||
| kwargs: { | ||
| filters: $.extend({}, opts.filters, F), | ||
| ordering: opts.ordering, | ||
| page: opts.page, | ||
| limit: opts.limit, | ||
| }, | ||
| }, | ||
| callback: function(json, status, xhr) { return table.fn.render(json, replace) }, | ||
| handlerShowAlert: opts.handlerShowAlert, | ||
| }) | ||
| .always(function() {table.request = null}); | ||
| return table.request | ||
| }; | ||
| /* Request to server from first page by force. */ | ||
| table.fn.get_first_page = function(filters) { | ||
| opts.page = 1; | ||
| opts.replace = true; | ||
| return table.fn.get(filters); | ||
| }; | ||
| /*** END FUNCTIONS ***/ | ||
| /*** START BINDING TABLE CONTROLLERS ON DOCUMENT BODY ***/ | ||
| $('body') | ||
| /* Keyup on character filters */ | ||
| .off('keyup', opts._selector_filtering+':not(input[type=checkbox])') | ||
| .on('keyup', opts._selector_filtering+':not(input[type=checkbox])', function(e) { | ||
| var fname = this.name || opts._default_filter_key, | ||
| old = opts.filters[fname], | ||
| min = Number($(this).data('minimum')) || 0, // minimum chars for query | ||
| len = this.value.length; | ||
| if (this.value != old && (!len || len >= min)) { | ||
| opts.filters[fname] = this.value; | ||
| table.fn.delay(table.fn.get_first_page, opts.delay); | ||
| } | ||
| }) | ||
| /* change on boolean filters */ | ||
| .off('change', opts._selector_filtering+'[type=checkbox]') | ||
| .on('change', opts._selector_filtering+'[type=checkbox]', function(e) { | ||
| var fname = this.name; | ||
| if (fname && this.checked != opts.filters[fname]) { | ||
| opts.filters[fname] = this.checked; | ||
| table.fn.delay(table.fn.get_first_page, 0); | ||
| } | ||
| }) | ||
| /* Change limit on page */ | ||
| .off('change', opts._selector_limiting) | ||
| .on('change', opts._selector_limiting, function(e) { | ||
| opts.limit = this.value; | ||
| table.fn.get_first_page(); | ||
| }) | ||
| /* Change visible of column */ | ||
| .off('change', opts._selector_colswitcher) | ||
| .on('change', opts._selector_colswitcher, function(e) { | ||
| var n = this.value, | ||
| cls = 'table-col-'+n+'-hidden'; | ||
| if (!n) return; | ||
| if (this.checked) { | ||
| $(table).removeClass(cls); | ||
| opts.columns[n-1].hidden = false; | ||
| } else { | ||
| $(table).addClass(cls); | ||
| opts.columns[n-1].hidden = true; | ||
| } | ||
| }) | ||
| /* Change ordering on columns */ | ||
| .off('click', opts._selector_ordering) | ||
| .on('click', opts._selector_ordering, function(e) { | ||
| var column = $(this).attr('name'), L, i; | ||
| if (!column) return; | ||
| L = opts.ordering; | ||
| i = $.inArray(column, L); | ||
| if (!opts.multiordering) { | ||
| $(opts._selector_ordering).removeClass('sorting-asc') | ||
| .removeClass('sorting-desc') | ||
| .addClass('sorting'); | ||
| } | ||
| if (i > -1) { | ||
| //~ console.debug('exists', i, column); | ||
| if (!opts.multiordering) { | ||
| L = ['-'+column]; | ||
| } else { | ||
| L[i] = '-'+column; | ||
| } | ||
| $(this).removeClass('sorting').addClass('sorting-desc'); | ||
| } else { | ||
| //~ console.debug('not exists', i, column); | ||
| i = $.inArray('-'+column, L); | ||
| if (i > -1) { | ||
| //~ console.debug('remove', i, '-'+column); | ||
| if (!opts.multiordering) { | ||
| L = []; | ||
| } else { | ||
| L = L.slice(0,i).concat(L.slice(i+1)); | ||
| } | ||
| $(this).removeClass('sorting-desc').addClass('sorting'); | ||
| } | ||
| } | ||
| if (i == -1){ | ||
| //~ console.debug('not exists', i, '-'+column); | ||
| if (!opts.multiordering) { | ||
| L = [column]; | ||
| } else { | ||
| L.push(column); | ||
| } | ||
| $(this).removeClass('sorting').addClass('sorting-asc'); | ||
| } | ||
| opts.ordering = L; | ||
| table.fn.get_first_page(); | ||
| }) | ||
| /* Click on pagination */ | ||
| .off('click', opts._selector_pager_links) | ||
| .on('click', opts._selector_pager_links, function(e) { | ||
| e.preventDefault(); | ||
| opts.page = $(this).data('page'); | ||
| if (opts.table_type == 'stack') { opts.replace = false }; | ||
| table.fn.get(); | ||
| }); | ||
| /*** END BINDING TABLE CONTROLLERS ***/ | ||
| /* Starting table */ | ||
| if (opts.autorender_settings) table.fn.render_settings(); | ||
| if (opts.autoload) table.fn.get_first_page(); | ||
| return table; | ||
| }; | ||
| }(jQuery)); | ||
| (function(a){a.quickAPI=function(d){var f,b=d||new Object();if(!b.data){b.data=b.args||{method:"quickapi.test"}}if(b.simple||b.type=="GET"){f=b.data;if(!f.language){f.language=b.language||window.LANGUAGE_CODE}}else{f={jsonData:a.toJSON(b.data),language:b.language||window.LANGUAGE_CODE}}var g,c={type:b.type||"POST",async:b.sync===true?false:b.async===false?false:true,timeout:b.timeout||window.AJAX_TIMEOUT||3000,url:b.url||window.QUICKAPI_URL||location.pathname,data:f,dataType:"json",},h=b.callback||function(j,i,k){},e=b.handlerShowAlert||window.handlerShowAlert||function(l,m,j,i){var k;if(a.type(m)=="object"){m=a.toJSON(m).replace(/\,\"/g,', "').replace(/\"\:/g,'": ')}else{if(m.match(/<\!DOCTYPE/)){k=m.match(/<[title,TITLE]+>(.*)<\/[title,TITLE]+>/);if(k){l=k[1]}k=m.match(/<[body,BODY]+>([^+]*)<\/[body,BODY]+>/);if(k){m=k[1].replace(/<\/?[^>]+>/g,"").replace(/ [ ]+/g," ").replace(/\n[\n]+/g,"\n")}else{m=""}}}if(m.length>512){m=m.substring(0,512)+" ..."}alert(l+"\n"+m);if(i){return i()}return null};g=a.ajax(c).fail(function(k,i,j){if(k.getResponseHeader("Location")){location.replace(k.getResponseHeader("Location"))}else{if(k.responseText){console.error("ERROR:",k.responseText);e("ERROR:",k.responseText,"alert-danger")}}}).done(function(j,i,l){if(b.log&&window.DEBUG){console.debug(b.log)}if((j.status>=300)&&(j.status<400)&&(j.data.Location!=undefined)){var k=j.data.Location,m;m=function(){location.replace(k)};console.info("REDIRECT:"+k);if(j.message){e("REDIRECT:",j.message,"alert-danger",m)}else{m()}}else{if(j.status>=400){e("ERROR:",j.message,"alert-danger")}else{if(window.DEBUG){console.debug(a.toJSON(j.message));if(b.data.method=="quickapi.test"){console.debug(j.data)}}return h(j,i,l)}}});return g}}(jQuery));(function(b){var a="quickTable";b.fn[a]=function(c){if(!this.size()){console.error("The selector found nothing");return undefined}if(!c.method){console.error("Not valid options for "+a,{method:c.method},"method must be defined!")}if(b.type(c.columns)!="array"||b.isEmptyObject(c.columns)){console.error("Not valid options for "+a,{columns:c.columns},"columns must be not empty array!");console.info("EXAMPLE:\n",'columns = [ {name:"id", hidden:true, notmanaged:true}, {name:"name", title:"Name"} ]\n',"where `name` - object attribute, `hidden` - hidden column,"," `notmanaged` - the column is not managed, `title` - title of column.")}var e=this[0],f,d;f=b(e).attr("id");if(!f){return this}d=b.extend({timeout:10000,async:true,autoload:true,autorender_settings:true,delay:500,page:1,limit:25,limit_list:[25,50,75,100],filters:{},ordering:[],multiordering:false,table_type:"table",text_pager_prev:"«",text_pager_next:"»",_selector_filtering:"[data-filtering="+f+"]",_selector_ordering:"#"+f+" th[class^=sorting][name]",_selector_limiting:"input[data-limiting="+f+"]:checked, select[data-limiting="+f+"]",_selector_colswitcher:"input[data-colswitcher="+f+"]",_selector_settings:"#"+f+"_settings",_selector_pager:"#"+f+"_pager",_selector_pager_links:"#"+f+"_pager li:not(.disabled) a:not(.disabled)",_selector_info:"#"+f+"_info",_selector_thead:"#"+f+" thead",_selector_tbody:"#"+f+" tbody",_selector_alert_not_found:"[data-notfound="+f+"]",_default_filter_key:"_search_",_managed_columns:[],_column_names:{},},c);e.opts=d;e.request=null;e.fn={};d.replace=true;b.each(d.columns,function(h,g){d._column_names[g.name]=g;if(g.hidden){b(e).addClass("table-col-"+(h+1)+"-hidden")}});e.fn.delay=(function(){var g=0;return function(i,h){clearTimeout(g);g=setTimeout(i,h)}})();e.fn._render_bs_stack=function(i,h){var j=d._selector_pager,g=d._selector_pager_links;if(i<h){b(g).data("page",(i+1));b(j).show()}else{b(g).data("page","");b(j).hide()}};e.fn._render_bs_pager=function(k,j,h){var i="",l=d.text_pager_prev,g=d.text_pager_next;if(k>1&&!h){i+='<li><a href="#" data-page="'+(k-1)+'">'+l+"</a></li>"}else{i+='<li class="disabled"><span>'+l+"</span></li>"}if(k<j){i+='<li><a href="#" data-page="'+(k+1)+'">'+g+"</a></li>"}else{i+='<li class="disabled"><span>'+g+"</span></li>"}b(d._selector_pager).html(i)};e.fn._render_bs_pagination=function(n,m,k,l){var j="",k=k||3,l=l||2,h=".",i=[],g;if(n>1){j+='<li><a href="#" data-page="'+(n-1)+'">'+d.text_pager_prev+"</a></li>"}else{j+='<li class="disabled"><span>'+d.text_pager_prev+"</span></li>"}g=function(p,q){for(var o=p;o<q;o++){i.push(o)}};if(m>9){if(n>(k+l)){g(1,k);i.push(h);g(n+1-k,n+1)}else{g(1,n+1)}if(n<(m-k-l+1)){g(n+1,n+k);i.push(h);g(m-l+1,m+1)}else{g(n+1,m+1)}}else{i=b.map(b(Array(m)),function(p,o){return o+1})}b.each(i,function(o,p){if(p==h){j+='<li class="disabled"><span>...</span></li>'}else{if(p==n){j+='<li class="active"><span>'+n+"</span></li>"}else{j+='<li><a href="#" data-page="'+p+'">'+p+"</a></li>"}}});if(n<m){j+='<li><a href="#" data-page="'+(n+1)+'">'+d.text_pager_next+"</a></li>"}else{j+='<li class="disabled"><span>'+d.text_pager_next+"</span></li>"}b(d._selector_pager).html(j)};e.fn.render_pager=function(h,g){if(d.table_type=="stack"){return e.fn._render_bs_stack(h,g)}else{if(d.table_type=="pager"){return e.fn._render_bs_pager(h,g,true)}}return e.fn._render_bs_pagination(h,g)};e.fn.alert_not_found=function(g){var h=b(d._selector_alert_not_found);g?h.show():h.hide()};e.fn.render_info=function(g){b(d._selector_info).html(g)};e.fn.render_settings=function(){var g="";b.each(d.columns,function(j,h){if(!h.notmanaged){g+='<label><input type="checkbox" name="'+f+'_colswitcher" value="'+(j+1)+'" '+(!h.hidden?" checked":"")+"/>"+(h.title||h.name)+"</label>"}});g+='<div class="btn-group" data-toggle="buttons">';b.each(d.limit_list,function(j,h){g+='<label class="btn'+(d.limit==h?" active":"")+'"><input type="checkbox" name="'+f+'_limit" '+(d.limit==h?" checked":"")+">"+h+"</label>"});g+="</div>";b(d._selector_settings).html(g)};e.fn.get_class_tr=function(g){return g?"":"danger"};e.fn.render_object=function(h,g){if(g==null){return}var i="";i+='<tr class="'+e.fn.get_class_tr(g)+'">';b.each(d.columns,function(k,j){i+="<td>"+g[j.name]+"</td>"});i+="</tr>";b(d._selector_tbody).append(i)};e.fn.render=function(h,g){var i=h.data;if(g){b(d._selector_tbody).html("")}if(b.isEmptyObject(i.objects)){e.fn.alert_not_found(true)}else{e.fn.alert_not_found(false);b.each(i.objects,function(j,k){e.fn.render_object(j,k)})}e.fn.render_pager(i.page,i.num_pages);if(i.info){e.fn.render_info(i.info)}};e.fn.get=function(i){var g=d.replace,h=i||{};if(e.request){e.request.abort()}e.request=b.quickAPI({url:d.url,timeout:d.timeout,async:d.async,args:{method:d.method,kwargs:{filters:b.extend({},d.filters,h),ordering:d.ordering,page:d.page,limit:d.limit,},},callback:function(k,j,l){return e.fn.render(k,g)},handlerShowAlert:d.handlerShowAlert,}).always(function(){e.request=null});return e.request};e.fn.get_first_page=function(g){d.page=1;d.replace=true;return e.fn.get(g)};b("body").off("keyup",d._selector_filtering+":not(input[type=checkbox])").on("keyup",d._selector_filtering+":not(input[type=checkbox])",function(j){var k=this.name||d._default_filter_key,h=d.filters[k],i=Number(b(this).data("minimum"))||0,g=this.value.length;if(this.value!=h&&(!g||g>=i)){d.filters[k]=this.value;e.fn.delay(e.fn.get_first_page,d.delay)}}).off("change",d._selector_filtering+"[type=checkbox]").on("change",d._selector_filtering+"[type=checkbox]",function(g){var h=this.name;if(h&&this.checked!=d.filters[h]){d.filters[h]=this.checked;e.fn.delay(e.fn.get_first_page,0)}}).off("change",d._selector_limiting).on("change",d._selector_limiting,function(g){d.limit=this.value;e.fn.get_first_page()}).off("change",d._selector_colswitcher).on("change",d._selector_colswitcher,function(h){var i=this.value,g="table-col-"+i+"-hidden";if(!i){return}if(this.checked){b(e).removeClass(g);d.columns[i-1].hidden=false}else{b(e).addClass(g);d.columns[i-1].hidden=true}}).off("click",d._selector_ordering).on("click",d._selector_ordering,function(k){var j=b(this).attr("name"),g,h;if(!j){return}g=d.ordering;h=b.inArray(j,g);if(!d.multiordering){b(d._selector_ordering).removeClass("sorting-asc").removeClass("sorting-desc").addClass("sorting")}if(h>-1){if(!d.multiordering){g=["-"+j]}else{g[h]="-"+j}b(this).removeClass("sorting").addClass("sorting-desc")}else{h=b.inArray("-"+j,g);if(h>-1){if(!d.multiordering){g=[]}else{g=g.slice(0,h).concat(g.slice(h+1))}b(this).removeClass("sorting-desc").addClass("sorting")}}if(h==-1){if(!d.multiordering){g=[j]}else{g.push(j)}b(this).removeClass("sorting").addClass("sorting-asc")}d.ordering=g;e.fn.get_first_page()}).off("click",d._selector_pager_links).on("click",d._selector_pager_links,function(g){g.preventDefault();d.page=b(this).data("page");if(d.table_type=="stack"){d.replace=false}e.fn.get()});if(d.autorender_settings){e.fn.render_settings()}if(d.autoload){e.fn.get_first_page()}return e}}(jQuery)); |
| /** | ||
| * jquery.quickapi.js - jQuery plugin for QuickAPI application | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| (function ($) { | ||
| /* Общая функция для работы с django-quickapi | ||
| * | ||
| * Документация: | ||
| * https://docs.rosix.ru/django-quickapi/wiki/jquery.html#quickapi | ||
| * | ||
| */ | ||
| $.quickAPI = function(opts) { | ||
| var data, options = opts || new Object(); | ||
| // `args` is deprecation option | ||
| if (!options.data) options.data = options.args || { method: "quickapi.test" }; | ||
| if (options.simple || options.type == 'GET') { | ||
| data = options.data; | ||
| if (!data.language) data.language = options.language || window.LANGUAGE_CODE | ||
| } else { | ||
| data = { | ||
| jsonData: $.toJSON(options.data), | ||
| language: options.language || window.LANGUAGE_CODE | ||
| } | ||
| } | ||
| var jqxhr, | ||
| settings = { | ||
| type: options.type || "POST", | ||
| async: options.sync === true ? false : options.async === false ? false : true, | ||
| timeout: options.timeout || window.AJAX_TIMEOUT || 3000, | ||
| url: options.url || window.QUICKAPI_URL || location.pathname, | ||
| data: data, | ||
| dataType: 'json', | ||
| }, | ||
| callback = options.callback || function(json, status, xhr) {}, | ||
| showAlert = options.handlerShowAlert || window.handlerShowAlert || function(head, msg, cls, cb) { | ||
| var match; | ||
| if ($.type(msg) == 'object') { | ||
| msg = $.toJSON(msg) | ||
| .replace(/\,\"/g, ', "') | ||
| .replace(/\"\:/g, '": ') | ||
| } | ||
| else if (msg.match(/<\!DOCTYPE/)) { | ||
| match = msg.match(/<[title,TITLE]+>(.*)<\/[title,TITLE]+>/); | ||
| if (match) head = match[1]; | ||
| match = msg.match(/<[body,BODY]+>([^+]*)<\/[body,BODY]+>/); | ||
| if (match) { | ||
| msg = match[1] | ||
| .replace(/<\/?[^>]+>/g, '') | ||
| .replace(/ [ ]+/g, ' ') | ||
| .replace(/\n[\n]+/g, '\n') | ||
| } else { | ||
| msg = ''; | ||
| } | ||
| } | ||
| if (msg.length > 512) { | ||
| msg = msg.substring(0, 512) + ' ...' | ||
| }; | ||
| alert(head +'\n'+ msg); | ||
| if (cb) { return cb() }; | ||
| return null | ||
| }; | ||
| jqxhr = $.ajax(settings) | ||
| // Обработка ошибок протокола HTTP | ||
| .fail(function(xhr, status, err) { | ||
| // Если есть переадресация, то выполняем её | ||
| if (xhr.getResponseHeader('Location')) { | ||
| location.replace(xhr.getResponseHeader('Location')); | ||
| } else if (xhr.responseText) { | ||
| // Иначе извещаем пользователя ответом и в консоль | ||
| console.error("ERROR:", xhr.responseText); | ||
| showAlert("ERROR:", xhr.responseText, 'alert-danger') | ||
| } | ||
| }) | ||
| // Обработка полученных данных | ||
| .done(function(json, status, xhr) { | ||
| if (options.log && window.DEBUG) {console.debug(options.log)}; | ||
| /* При переадресации нужно отобразить сообщение на некоторое время, | ||
| * а затем выполнить переход по ссылке | ||
| */ | ||
| if ((json.status >=300) && (json.status <400) && (json.data.Location != undefined)) { | ||
| var loc = json.data.Location, redirect; | ||
| redirect = function() { location.replace(loc) }; | ||
| console.info("REDIRECT:" + loc); | ||
| if (json.message) { | ||
| showAlert("REDIRECT:", json.message, 'alert-danger', redirect) | ||
| } else { | ||
| redirect() | ||
| } | ||
| } | ||
| /* При ошибках извещаем пользователя полученным сообщением */ | ||
| else if (json.status >=400) { | ||
| showAlert("ERROR:", json.message, 'alert-danger'); | ||
| } | ||
| /* При нормальном возврате в debug-режиме выводим в консоль | ||
| * сообщение | ||
| */ | ||
| else { | ||
| if (window.DEBUG) { | ||
| console.debug($.toJSON(json.message)); | ||
| if (options.data.method == "quickapi.test") { | ||
| console.debug(json.data) | ||
| } | ||
| }; | ||
| return callback(json, status, xhr) | ||
| } | ||
| }); | ||
| return jqxhr | ||
| } | ||
| }(jQuery)); | ||
| (function(a){a.quickAPI=function(d){var f,b=d||new Object();if(!b.data){b.data=b.args||{method:"quickapi.test"}}if(b.simple||b.type=="GET"){f=b.data;if(!f.language){f.language=b.language||window.LANGUAGE_CODE}}else{f={jsonData:a.toJSON(b.data),language:b.language||window.LANGUAGE_CODE}}var g,c={type:b.type||"POST",async:b.sync===true?false:b.async===false?false:true,timeout:b.timeout||window.AJAX_TIMEOUT||3000,url:b.url||window.QUICKAPI_URL||location.pathname,data:f,dataType:"json",},h=b.callback||function(j,i,k){},e=b.handlerShowAlert||window.handlerShowAlert||function(l,m,j,i){var k;if(a.type(m)=="object"){m=a.toJSON(m).replace(/\,\"/g,', "').replace(/\"\:/g,'": ')}else{if(m.match(/<\!DOCTYPE/)){k=m.match(/<[title,TITLE]+>(.*)<\/[title,TITLE]+>/);if(k){l=k[1]}k=m.match(/<[body,BODY]+>([^+]*)<\/[body,BODY]+>/);if(k){m=k[1].replace(/<\/?[^>]+>/g,"").replace(/ [ ]+/g," ").replace(/\n[\n]+/g,"\n")}else{m=""}}}if(m.length>512){m=m.substring(0,512)+" ..."}alert(l+"\n"+m);if(i){return i()}return null};g=a.ajax(c).fail(function(k,i,j){if(k.getResponseHeader("Location")){location.replace(k.getResponseHeader("Location"))}else{if(k.responseText){console.error("ERROR:",k.responseText);e("ERROR:",k.responseText,"alert-danger")}}}).done(function(j,i,l){if(b.log&&window.DEBUG){console.debug(b.log)}if((j.status>=300)&&(j.status<400)&&(j.data.Location!=undefined)){var k=j.data.Location,m;m=function(){location.replace(k)};console.info("REDIRECT:"+k);if(j.message){e("REDIRECT:",j.message,"alert-danger",m)}else{m()}}else{if(j.status>=400){e("ERROR:",j.message,"alert-danger")}else{if(window.DEBUG){console.debug(a.toJSON(j.message));if(b.data.method=="quickapi.test"){console.debug(j.data)}}return h(j,i,l)}}});return g}}(jQuery)); |
| /* | ||
| * jquery.quicktable.js - jQuery plugin for QuickAPI application | ||
| * | ||
| * depends: | ||
| * jquery.quickapi.js - jQuery plugin for QuickAPI | ||
| * recommends: | ||
| * Twitter bootstrap >= 3.0 | ||
| * | ||
| * Copyright 2014-2015 Grigoriy Kramarenko <root@rosix.ru> | ||
| * | ||
| * This file is part of QuickAPI. | ||
| * | ||
| * QuickAPI is free software: you can redistribute it and/or | ||
| * modify it under the terms of the GNU Affero General Public License | ||
| * as published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * QuickAPI is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with QuickAPI. If not, see | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| (function ($) { | ||
| /* Плагин для работы с QuickTable из состава django-quickapi | ||
| * | ||
| * Документация: | ||
| * https://docs.rosix.ru/django-quickapi/wiki/jquery.html#quicktable | ||
| * | ||
| */ | ||
| var pluginName = "quickTable"; | ||
| $.fn[pluginName] = function(options) { | ||
| if (!this.size()) { console.error('The selector found nothing'); return undefined }; | ||
| if (!options.method) { | ||
| console.error( | ||
| "Not valid options for "+pluginName, | ||
| { method:options.method }, | ||
| 'method must be defined!' | ||
| ); | ||
| }; | ||
| if ($.type(options.columns) != 'array' || $.isEmptyObject(options.columns)) { | ||
| console.error( | ||
| "Not valid options for "+pluginName, | ||
| { columns:options.columns }, | ||
| 'columns must be not empty array!' | ||
| ); | ||
| console.info('EXAMPLE:\n', | ||
| 'columns = [ {name:"id", hidden:true, notmanaged:true}, {name:"name", title:"Name"} ]\n', | ||
| 'where `name` - object attribute, `hidden` - hidden column,', | ||
| ' `notmanaged` - the column is not managed, `title` - title of column.' | ||
| ); | ||
| }; | ||
| var table = this[0], id, opts; | ||
| id = $(table).attr('id'); | ||
| if (!id) { return this }; // not valid | ||
| opts = $.extend({ | ||
| //url: undefined, | ||
| //method: undefined, | ||
| //columns: undefined, | ||
| //handlerShowAlert: undefined, | ||
| timeout: 10000, | ||
| async: true, | ||
| autoload: true, | ||
| autorender_settings: true, | ||
| delay: 500, | ||
| page: 1, | ||
| limit: 25, | ||
| limit_list: [25, 50, 75, 100], | ||
| filters: {}, | ||
| ordering: [], | ||
| multiordering: false, | ||
| table_type: 'table', // variants: 'stack' or 'pager' | ||
| text_pager_prev: '«', | ||
| text_pager_next: '»', | ||
| // the following variables are strongly advised not to change | ||
| _selector_filtering: '[data-filtering='+id+']', | ||
| _selector_ordering: '#'+id+' th[class^=sorting][name]', | ||
| _selector_limiting: 'input[data-limiting='+id+']:checked, select[data-limiting='+id+']', | ||
| _selector_colswitcher: 'input[data-colswitcher='+id+']', | ||
| _selector_settings: '#'+id+'_settings', | ||
| _selector_pager: '#'+id+'_pager', | ||
| _selector_pager_links: '#'+id+'_pager li:not(.disabled) a:not(.disabled)', | ||
| _selector_info: '#'+id+'_info', | ||
| _selector_thead: '#'+id+' thead', | ||
| _selector_tbody: '#'+id+' tbody', | ||
| _selector_alert_not_found: '[data-notfound='+id+']', | ||
| _default_filter_key: '_search_', | ||
| _managed_columns: [], | ||
| _column_names: {}, | ||
| }, options); | ||
| table.opts = opts; // link | ||
| table.request = null; // current jqxhr | ||
| table.fn = {}; // storage for functions | ||
| opts.replace = true; // append or overwrite tbody | ||
| $.each(opts.columns, function(i, col) { | ||
| opts._column_names[col.name] = col; | ||
| if (col.hidden) $(table).addClass('table-col-'+(i+1)+'-hidden'); | ||
| }); | ||
| /*** START FUNCTIONS ***/ | ||
| /* Delay for keyup in filters */ | ||
| table.fn.delay = (function(){ | ||
| var tid = 0; | ||
| return function(callback, ms){ | ||
| clearTimeout(tid); | ||
| tid = setTimeout(callback, ms); | ||
| }; | ||
| })(); | ||
| /* Twitter bootstrap .pager as stack */ | ||
| table.fn._render_bs_stack = function(page, num_pages) { | ||
| var p = opts._selector_pager, a = opts._selector_pager_links; | ||
| if (page < num_pages) { | ||
| $(a).data('page', (page+1)); | ||
| $(p).show(); | ||
| } else { | ||
| $(a).data('page', ''); | ||
| $(p).hide(); | ||
| } | ||
| }; | ||
| /* Twitter bootstrap .pager inner HTML */ | ||
| table.fn._render_bs_pager = function(page, num_pages, hide_prev) { | ||
| var html = '', tp = opts.text_pager_prev, tn = opts.text_pager_next; | ||
| if (page >1 && !hide_prev) { | ||
| html += '<li><a href="#" data-page="'+(page-1)+'">'+tp+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+tp+'</span></li>'; | ||
| } | ||
| if (page < num_pages) { | ||
| html += '<li><a href="#" data-page="'+(page+1)+'">'+tn+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+tn+'</span></li>'; | ||
| } | ||
| $(opts._selector_pager).html(html); | ||
| }; | ||
| /* Twitter bootstrap .pagination inner HTML */ | ||
| table.fn._render_bs_pagination = function(page, num_pages, on_each_side, on_ends) { | ||
| var html = '', | ||
| on_each_side=on_each_side||3, | ||
| on_ends=on_ends||2, | ||
| dot='.', | ||
| page_range = [], | ||
| _push; | ||
| if (page >1) { | ||
| html += '<li><a href="#" data-page="'+(page-1)+'">'+opts.text_pager_prev+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+opts.text_pager_prev+'</span></li>'; | ||
| } | ||
| _push = function(s, e) { for(var i=s; i<e; i++) { page_range.push(i) } }; | ||
| if (num_pages > 9) { | ||
| if (page > (on_each_side + on_ends)) { | ||
| _push(1, on_each_side); | ||
| page_range.push(dot); | ||
| _push(page+1-on_each_side, page+1); | ||
| } else { | ||
| _push(1, page+1) | ||
| } | ||
| if (page < (num_pages - on_each_side - on_ends + 1)) { | ||
| _push(page+1, page+on_each_side); | ||
| page_range.push(dot); | ||
| _push(num_pages-on_ends+1, num_pages+1); | ||
| } else { | ||
| _push(page+1, num_pages+1) | ||
| } | ||
| } else { | ||
| page_range = $.map($(Array(num_pages)), function(val, i) { return i+1; }) | ||
| }; | ||
| $.each(page_range, function(i, item) { | ||
| if (item == dot) { | ||
| html += '<li class="disabled"><span>...</span></li>'; | ||
| } else if (item == page) { | ||
| html += '<li class="active"><span>'+page+'</span></li>'; | ||
| } else { | ||
| html += '<li><a href="#" data-page="'+item+'">'+item+'</a></li>'; | ||
| } | ||
| }); | ||
| if (page < num_pages) { | ||
| html += '<li><a href="#" data-page="'+(page+1)+'">'+opts.text_pager_next+'</a></li>'; | ||
| } else { | ||
| html += '<li class="disabled"><span>'+opts.text_pager_next+'</span></li>'; | ||
| } | ||
| $(opts._selector_pager).html(html); | ||
| }; | ||
| /* Use default pagination */ | ||
| table.fn.render_pager = function(page, num_pages) { | ||
| if (opts.table_type == 'stack') { | ||
| return table.fn._render_bs_stack(page, num_pages) | ||
| } | ||
| else if (opts.table_type == 'pager') { | ||
| return table.fn._render_bs_pager(page, num_pages, true) | ||
| } | ||
| return table.fn._render_bs_pagination(page, num_pages); | ||
| } | ||
| /* Show/hide not found text */ | ||
| table.fn.alert_not_found = function(show) { | ||
| var $alert = $(opts._selector_alert_not_found); | ||
| show ? $alert.show() : $alert.hide(); | ||
| }; | ||
| /* Rendering information */ | ||
| table.fn.render_info = function(html) { | ||
| $(opts._selector_info).html(html); | ||
| }; | ||
| /* Rendering settings */ | ||
| table.fn.render_settings = function() { | ||
| var html = ''; | ||
| $.each(opts.columns, function(i, col) { | ||
| if (!col.notmanaged) { | ||
| html += '<label>' | ||
| +'<input type="checkbox" name="'+id+'_colswitcher" value="'+(i+1)+'" ' | ||
| +(!col.hidden ? ' checked' : '')+'/>' | ||
| +(col.title||col.name) | ||
| +'</label>' | ||
| } | ||
| }); | ||
| html += '<div class="btn-group" data-toggle="buttons">' | ||
| $.each(opts.limit_list, function(i, limit) { | ||
| html += '<label class="btn'+(opts.limit == limit ? ' active': '')+'">' | ||
| +'<input type="checkbox" name="'+id+'_limit" ' | ||
| +(opts.limit == limit ? ' checked': '')+'>' | ||
| + limit | ||
| +'</label>' | ||
| }); | ||
| html += '</div>' | ||
| $(opts._selector_settings).html(html); | ||
| }; | ||
| /* Returns class for <tr> */ | ||
| table.fn.get_class_tr = function(object) { return object ? '' : 'danger' }; | ||
| /* Rendering one object */ | ||
| table.fn.render_object = function(index, object) { | ||
| if (object == null) return; | ||
| var html = ''; | ||
| html += '<tr class="'+table.fn.get_class_tr(object)+'">'; | ||
| $.each(opts.columns, function(i, col) { | ||
| html += '<td>'+object[col.name]+'</td>'; | ||
| }); | ||
| html += '</tr>'; | ||
| $(opts._selector_tbody).append(html); | ||
| }; | ||
| /* Callback of jqxhr. Rendering all objects, pagination, etc. */ | ||
| table.fn.render = function(json, replace) { | ||
| var data = json.data; | ||
| if (replace) $(opts._selector_tbody).html(''); | ||
| if ($.isEmptyObject(data.objects)) { | ||
| table.fn.alert_not_found(true) | ||
| } else { | ||
| table.fn.alert_not_found(false) | ||
| $.each(data.objects, function(i, item) { | ||
| table.fn.render_object(i, item) | ||
| }) | ||
| } | ||
| table.fn.render_pager(data.page, data.num_pages); | ||
| if (data.info) table.fn.render_info(data.info); | ||
| }; | ||
| /* Request to server on quickAPI. Returns jqxhr. */ | ||
| table.fn.get = function(filters) { | ||
| var replace = opts['replace'], F = filters || {}; | ||
| if (table.request) table.request.abort(); | ||
| table.request = $.quickAPI({ | ||
| url: opts.url, | ||
| timeout: opts.timeout, | ||
| //type: 'POST', | ||
| async: opts.async, | ||
| args: { | ||
| method: opts.method, | ||
| kwargs: { | ||
| filters: $.extend({}, opts.filters, F), | ||
| ordering: opts.ordering, | ||
| page: opts.page, | ||
| limit: opts.limit, | ||
| }, | ||
| }, | ||
| callback: function(json, status, xhr) { return table.fn.render(json, replace) }, | ||
| handlerShowAlert: opts.handlerShowAlert, | ||
| }) | ||
| .always(function() {table.request = null}); | ||
| return table.request | ||
| }; | ||
| /* Request to server from first page by force. */ | ||
| table.fn.get_first_page = function(filters) { | ||
| opts.page = 1; | ||
| opts.replace = true; | ||
| return table.fn.get(filters); | ||
| }; | ||
| /*** END FUNCTIONS ***/ | ||
| /*** START BINDING TABLE CONTROLLERS ON DOCUMENT BODY ***/ | ||
| $('body') | ||
| /* Keyup on character filters */ | ||
| .off('keyup', opts._selector_filtering+':not(input[type=checkbox])') | ||
| .on('keyup', opts._selector_filtering+':not(input[type=checkbox])', function(e) { | ||
| var fname = this.name || opts._default_filter_key, | ||
| old = opts.filters[fname], | ||
| min = Number($(this).data('minimum')) || 0, // minimum chars for query | ||
| len = this.value.length; | ||
| if (this.value != old && (!len || len >= min)) { | ||
| opts.filters[fname] = this.value; | ||
| table.fn.delay(table.fn.get_first_page, opts.delay); | ||
| } | ||
| }) | ||
| /* change on boolean filters */ | ||
| .off('change', opts._selector_filtering+'[type=checkbox]') | ||
| .on('change', opts._selector_filtering+'[type=checkbox]', function(e) { | ||
| var fname = this.name; | ||
| if (fname && this.checked != opts.filters[fname]) { | ||
| opts.filters[fname] = this.checked; | ||
| table.fn.delay(table.fn.get_first_page, 0); | ||
| } | ||
| }) | ||
| /* Change limit on page */ | ||
| .off('change', opts._selector_limiting) | ||
| .on('change', opts._selector_limiting, function(e) { | ||
| opts.limit = this.value; | ||
| table.fn.get_first_page(); | ||
| }) | ||
| /* Change visible of column */ | ||
| .off('change', opts._selector_colswitcher) | ||
| .on('change', opts._selector_colswitcher, function(e) { | ||
| var n = this.value, | ||
| cls = 'table-col-'+n+'-hidden'; | ||
| if (!n) return; | ||
| if (this.checked) { | ||
| $(table).removeClass(cls); | ||
| opts.columns[n-1].hidden = false; | ||
| } else { | ||
| $(table).addClass(cls); | ||
| opts.columns[n-1].hidden = true; | ||
| } | ||
| }) | ||
| /* Change ordering on columns */ | ||
| .off('click', opts._selector_ordering) | ||
| .on('click', opts._selector_ordering, function(e) { | ||
| var column = $(this).attr('name'), L, i; | ||
| if (!column) return; | ||
| L = opts.ordering; | ||
| i = $.inArray(column, L); | ||
| if (!opts.multiordering) { | ||
| $(opts._selector_ordering).removeClass('sorting-asc') | ||
| .removeClass('sorting-desc') | ||
| .addClass('sorting'); | ||
| } | ||
| if (i > -1) { | ||
| //~ console.debug('exists', i, column); | ||
| if (!opts.multiordering) { | ||
| L = ['-'+column]; | ||
| } else { | ||
| L[i] = '-'+column; | ||
| } | ||
| $(this).removeClass('sorting').addClass('sorting-desc'); | ||
| } else { | ||
| //~ console.debug('not exists', i, column); | ||
| i = $.inArray('-'+column, L); | ||
| if (i > -1) { | ||
| //~ console.debug('remove', i, '-'+column); | ||
| if (!opts.multiordering) { | ||
| L = []; | ||
| } else { | ||
| L = L.slice(0,i).concat(L.slice(i+1)); | ||
| } | ||
| $(this).removeClass('sorting-desc').addClass('sorting'); | ||
| } | ||
| } | ||
| if (i == -1){ | ||
| //~ console.debug('not exists', i, '-'+column); | ||
| if (!opts.multiordering) { | ||
| L = [column]; | ||
| } else { | ||
| L.push(column); | ||
| } | ||
| $(this).removeClass('sorting').addClass('sorting-asc'); | ||
| } | ||
| opts.ordering = L; | ||
| table.fn.get_first_page(); | ||
| }) | ||
| /* Click on pagination */ | ||
| .off('click', opts._selector_pager_links) | ||
| .on('click', opts._selector_pager_links, function(e) { | ||
| e.preventDefault(); | ||
| opts.page = $(this).data('page'); | ||
| if (opts.table_type == 'stack') { opts.replace = false }; | ||
| table.fn.get(); | ||
| }); | ||
| /*** END BINDING TABLE CONTROLLERS ***/ | ||
| /* Starting table */ | ||
| if (opts.autorender_settings) table.fn.render_settings(); | ||
| if (opts.autoload) table.fn.get_first_page(); | ||
| return table; | ||
| }; | ||
| }(jQuery)); | ||
| (function(b){var a="quickTable";b.fn[a]=function(c){if(!this.size()){console.error("The selector found nothing");return undefined}if(!c.method){console.error("Not valid options for "+a,{method:c.method},"method must be defined!")}if(b.type(c.columns)!="array"||b.isEmptyObject(c.columns)){console.error("Not valid options for "+a,{columns:c.columns},"columns must be not empty array!");console.info("EXAMPLE:\n",'columns = [ {name:"id", hidden:true, notmanaged:true}, {name:"name", title:"Name"} ]\n',"where `name` - object attribute, `hidden` - hidden column,"," `notmanaged` - the column is not managed, `title` - title of column.")}var e=this[0],f,d;f=b(e).attr("id");if(!f){return this}d=b.extend({timeout:10000,async:true,autoload:true,autorender_settings:true,delay:500,page:1,limit:25,limit_list:[25,50,75,100],filters:{},ordering:[],multiordering:false,table_type:"table",text_pager_prev:"«",text_pager_next:"»",_selector_filtering:"[data-filtering="+f+"]",_selector_ordering:"#"+f+" th[class^=sorting][name]",_selector_limiting:"input[data-limiting="+f+"]:checked, select[data-limiting="+f+"]",_selector_colswitcher:"input[data-colswitcher="+f+"]",_selector_settings:"#"+f+"_settings",_selector_pager:"#"+f+"_pager",_selector_pager_links:"#"+f+"_pager li:not(.disabled) a:not(.disabled)",_selector_info:"#"+f+"_info",_selector_thead:"#"+f+" thead",_selector_tbody:"#"+f+" tbody",_selector_alert_not_found:"[data-notfound="+f+"]",_default_filter_key:"_search_",_managed_columns:[],_column_names:{},},c);e.opts=d;e.request=null;e.fn={};d.replace=true;b.each(d.columns,function(h,g){d._column_names[g.name]=g;if(g.hidden){b(e).addClass("table-col-"+(h+1)+"-hidden")}});e.fn.delay=(function(){var g=0;return function(i,h){clearTimeout(g);g=setTimeout(i,h)}})();e.fn._render_bs_stack=function(i,h){var j=d._selector_pager,g=d._selector_pager_links;if(i<h){b(g).data("page",(i+1));b(j).show()}else{b(g).data("page","");b(j).hide()}};e.fn._render_bs_pager=function(k,j,h){var i="",l=d.text_pager_prev,g=d.text_pager_next;if(k>1&&!h){i+='<li><a href="#" data-page="'+(k-1)+'">'+l+"</a></li>"}else{i+='<li class="disabled"><span>'+l+"</span></li>"}if(k<j){i+='<li><a href="#" data-page="'+(k+1)+'">'+g+"</a></li>"}else{i+='<li class="disabled"><span>'+g+"</span></li>"}b(d._selector_pager).html(i)};e.fn._render_bs_pagination=function(n,m,k,l){var j="",k=k||3,l=l||2,h=".",i=[],g;if(n>1){j+='<li><a href="#" data-page="'+(n-1)+'">'+d.text_pager_prev+"</a></li>"}else{j+='<li class="disabled"><span>'+d.text_pager_prev+"</span></li>"}g=function(p,q){for(var o=p;o<q;o++){i.push(o)}};if(m>9){if(n>(k+l)){g(1,k);i.push(h);g(n+1-k,n+1)}else{g(1,n+1)}if(n<(m-k-l+1)){g(n+1,n+k);i.push(h);g(m-l+1,m+1)}else{g(n+1,m+1)}}else{i=b.map(b(Array(m)),function(p,o){return o+1})}b.each(i,function(o,p){if(p==h){j+='<li class="disabled"><span>...</span></li>'}else{if(p==n){j+='<li class="active"><span>'+n+"</span></li>"}else{j+='<li><a href="#" data-page="'+p+'">'+p+"</a></li>"}}});if(n<m){j+='<li><a href="#" data-page="'+(n+1)+'">'+d.text_pager_next+"</a></li>"}else{j+='<li class="disabled"><span>'+d.text_pager_next+"</span></li>"}b(d._selector_pager).html(j)};e.fn.render_pager=function(h,g){if(d.table_type=="stack"){return e.fn._render_bs_stack(h,g)}else{if(d.table_type=="pager"){return e.fn._render_bs_pager(h,g,true)}}return e.fn._render_bs_pagination(h,g)};e.fn.alert_not_found=function(g){var h=b(d._selector_alert_not_found);g?h.show():h.hide()};e.fn.render_info=function(g){b(d._selector_info).html(g)};e.fn.render_settings=function(){var g="";b.each(d.columns,function(j,h){if(!h.notmanaged){g+='<label><input type="checkbox" name="'+f+'_colswitcher" value="'+(j+1)+'" '+(!h.hidden?" checked":"")+"/>"+(h.title||h.name)+"</label>"}});g+='<div class="btn-group" data-toggle="buttons">';b.each(d.limit_list,function(j,h){g+='<label class="btn'+(d.limit==h?" active":"")+'"><input type="checkbox" name="'+f+'_limit" '+(d.limit==h?" checked":"")+">"+h+"</label>"});g+="</div>";b(d._selector_settings).html(g)};e.fn.get_class_tr=function(g){return g?"":"danger"};e.fn.render_object=function(h,g){if(g==null){return}var i="";i+='<tr class="'+e.fn.get_class_tr(g)+'">';b.each(d.columns,function(k,j){i+="<td>"+g[j.name]+"</td>"});i+="</tr>";b(d._selector_tbody).append(i)};e.fn.render=function(h,g){var i=h.data;if(g){b(d._selector_tbody).html("")}if(b.isEmptyObject(i.objects)){e.fn.alert_not_found(true)}else{e.fn.alert_not_found(false);b.each(i.objects,function(j,k){e.fn.render_object(j,k)})}e.fn.render_pager(i.page,i.num_pages);if(i.info){e.fn.render_info(i.info)}};e.fn.get=function(i){var g=d.replace,h=i||{};if(e.request){e.request.abort()}e.request=b.quickAPI({url:d.url,timeout:d.timeout,async:d.async,args:{method:d.method,kwargs:{filters:b.extend({},d.filters,h),ordering:d.ordering,page:d.page,limit:d.limit,},},callback:function(k,j,l){return e.fn.render(k,g)},handlerShowAlert:d.handlerShowAlert,}).always(function(){e.request=null});return e.request};e.fn.get_first_page=function(g){d.page=1;d.replace=true;return e.fn.get(g)};b("body").off("keyup",d._selector_filtering+":not(input[type=checkbox])").on("keyup",d._selector_filtering+":not(input[type=checkbox])",function(j){var k=this.name||d._default_filter_key,h=d.filters[k],i=Number(b(this).data("minimum"))||0,g=this.value.length;if(this.value!=h&&(!g||g>=i)){d.filters[k]=this.value;e.fn.delay(e.fn.get_first_page,d.delay)}}).off("change",d._selector_filtering+"[type=checkbox]").on("change",d._selector_filtering+"[type=checkbox]",function(g){var h=this.name;if(h&&this.checked!=d.filters[h]){d.filters[h]=this.checked;e.fn.delay(e.fn.get_first_page,0)}}).off("change",d._selector_limiting).on("change",d._selector_limiting,function(g){d.limit=this.value;e.fn.get_first_page()}).off("change",d._selector_colswitcher).on("change",d._selector_colswitcher,function(h){var i=this.value,g="table-col-"+i+"-hidden";if(!i){return}if(this.checked){b(e).removeClass(g);d.columns[i-1].hidden=false}else{b(e).addClass(g);d.columns[i-1].hidden=true}}).off("click",d._selector_ordering).on("click",d._selector_ordering,function(k){var j=b(this).attr("name"),g,h;if(!j){return}g=d.ordering;h=b.inArray(j,g);if(!d.multiordering){b(d._selector_ordering).removeClass("sorting-asc").removeClass("sorting-desc").addClass("sorting")}if(h>-1){if(!d.multiordering){g=["-"+j]}else{g[h]="-"+j}b(this).removeClass("sorting").addClass("sorting-desc")}else{h=b.inArray("-"+j,g);if(h>-1){if(!d.multiordering){g=[]}else{g=g.slice(0,h).concat(g.slice(h+1))}b(this).removeClass("sorting-desc").addClass("sorting")}}if(h==-1){if(!d.multiordering){g=[j]}else{g.push(j)}b(this).removeClass("sorting").addClass("sorting-asc")}d.ordering=g;e.fn.get_first_page()}).off("click",d._selector_pager_links).on("click",d._selector_pager_links,function(g){g.preventDefault();d.page=b(this).data("page");if(d.table_type=="stack"){d.replace=false}e.fn.get()});if(d.autorender_settings){e.fn.render_settings()}if(d.autoload){e.fn.get_first_page()}return e}}(jQuery)); |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
2594515
0.02%25057
0.04%