diff --git a/assets/js/build/contractor_filter.js b/assets/js/build/contractor_filter.js index a5afc1c..9c2e0fd 100644 --- a/assets/js/build/contractor_filter.js +++ b/assets/js/build/contractor_filter.js @@ -57,7 +57,7 @@ function paginateTo(pageNum) { var $form = $('#filter-form'); var postfix = "&page=" + pageNum; - var $container = $('#contractorsBlock'); + var $container = $('#resultsBlock'); (0, _ajax_set_filter.sendData)($form, $container, pageNum); (0, _ajax_set_filter.modUrl)($form, postfix); @@ -218,7 +218,7 @@ // console.log('type = ', $target.data("type")); $parent.find('input').val($target.data("type")); // console.log('click'); - sendFilterData($('#filter-form'), $('#contractorsBlock')); + sendFilterData($('#filter-form'), $('#resultsBlock')); }); } diff --git a/assets/js/build/init_worksell_filter.js b/assets/js/build/init_worksell_filter.js new file mode 100644 index 0000000..e2961d7 --- /dev/null +++ b/assets/js/build/init_worksell_filter.js @@ -0,0 +1,1444 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var _SelectedContainer = __webpack_require__(19); + + var _SelectedContainer2 = _interopRequireDefault(_SelectedContainer); + + var _NoTreeSelect = __webpack_require__(23); + + var _NoTreeSelect2 = _interopRequireDefault(_NoTreeSelect); + + var _TreeSelect = __webpack_require__(25); + + var _TreeSelect2 = _interopRequireDefault(_TreeSelect); + + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + $(function () { + function createFilterSpecs(url) { + // SPECIALIZATIONS FILTER + var sb_main = new _TreeSelect2.default($('#select-box-1'), { url: url, visible: true, hasEditableContainer: true }); + sb_main.setHeader("Тип готовой работы"); + var select_container = new _SelectedContainer2.default($('#selected-spec'), { obj: sb_main }); + sb_main.connectSelectedContainer(select_container); + var sb_1 = new _TreeSelect2.default($('#select-box-2'), { obj: sb_main }); + var sb_2 = new _TreeSelect2.default($('#select-box-3'), { obj: sb_main }); + var sb_3 = new _TreeSelect2.default($('#select-box-4'), { obj: sb_main }); + var sb_4 = new _TreeSelect2.default($('#select-box-5'), { obj: sb_main }); + + sb_main.setNearbySelectBox(sb_1); + sb_1.setNearbySelectBox(sb_2, sb_main); + sb_2.setNearbySelectBox(sb_3, sb_1); + sb_3.setNearbySelectBox(sb_4, sb_2); + sb_4.setNearbySelectBox("", sb_3); + } + + function createFilterBuildingClass(url) { + // BUILDING-CLASSIFICATION FILTER + var sb_build_main = new _TreeSelect2.default($('#sb-building-classification'), { url: url, visible: true }); + sb_build_main.setHeader("Классификация здания"); + + var sb_build_1 = new _TreeSelect2.default($('#sb-building-sub-classification'), { obj: sb_build_main }); + + var select_build_container = new _SelectedContainer2.default($('#selected-building-classification'), { obj: sb_build_main }); + sb_build_main.connectSelectedContainer(select_build_container); + + sb_build_main.setNearbySelectBox(sb_build_1); + sb_build_1.setNearbySelectBox("", sb_build_main); + } + + function createFilterConstructionType(url) { + var sb_constr_main = new _NoTreeSelect2.default($('#sb-construction-type'), { url: url, visible: true }); + sb_constr_main.setHeader("Вид строительства"); + var select_constr_type = new _SelectedContainer2.default($('#selected-construction-type'), { obj: sb_constr_main, noTree: true }); + sb_constr_main.connectSelectedContainer(select_constr_type); + } + + function createFilerLocations(url) { + var sb_loc_main = new _TreeSelect2.default($('#sb-location-1'), { url: url, visible: true }); + sb_loc_main.setHeader("Проектное местоположение"); + var select_loc = new _SelectedContainer2.default($('#selected-location'), { obj: sb_loc_main }); + sb_loc_main.connectSelectedContainer(select_loc); + var sb_loc_1 = new _TreeSelect2.default($('#sb-location-2'), { obj: sb_loc_main }); + var sb_loc_2 = new _TreeSelect2.default($('#sb-location-3'), { obj: sb_loc_main }); + + sb_loc_main.setNearbySelectBox(sb_loc_1); + sb_loc_1.setNearbySelectBox(sb_loc_2, sb_loc_main); + sb_loc_2.setNearbySelectBox("", sb_loc_1); + } + + createFilterSpecs('/api/specializations_flat'); + createFilterBuildingClass('/api/building_classifications'); + createFilterConstructionType('/api/construction_type'); + createFilerLocations('/api/locations_flat'); + }); // ` + +/***/ }, +/* 1 */, +/* 2 */, +/* 3 */, +/* 4 */, +/* 5 */, +/* 6 */, +/* 7 */, +/* 8 */, +/* 9 */, +/* 10 */, +/* 11 */, +/* 12 */, +/* 13 */, +/* 14 */, +/* 15 */, +/* 16 */, +/* 17 */, +/* 18 */, +/* 19 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.default = undefined; + + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + + var _desc, _value, _class; // ` + + + var _DataTree = __webpack_require__(20); + + var _DataTree2 = _interopRequireDefault(_DataTree); + + var _NoTreeData = __webpack_require__(21); + + var _NoTreeData2 = _interopRequireDefault(_NoTreeData); + + var _decorators = __webpack_require__(22); + + var _decorators2 = _interopRequireDefault(_decorators); + + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + + function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { + var desc = {}; + Object['ke' + 'ys'](descriptor).forEach(function (key) { + desc[key] = descriptor[key]; + }); + desc.enumerable = !!desc.enumerable; + desc.configurable = !!desc.configurable; + + if ('value' in desc || desc.initializer) { + desc.writable = true; + } + + desc = decorators.slice().reverse().reduce(function (desc, decorator) { + return decorator(target, property, desc) || desc; + }, desc); + + if (context && desc.initializer !== void 0) { + desc.value = desc.initializer ? desc.initializer.call(context) : void 0; + desc.initializer = undefined; + } + + if (desc.initializer === void 0) { + Object['define' + 'Property'](target, property, desc); + desc = null; + } + + return desc; + } + + var tmpl_selectedElement = function tmpl_selectedElement(header, name, id) { + return '\n
\n
\n ' + header + '\n
\n
\n ' + name + '\n
\n \n
\n'; + }; + + var SelectedContainer = (_class = function () { + function SelectedContainer($container, _ref) { + var _this = this; + + var obj = _ref.obj, + _ref$noTree = _ref.noTree, + noTree = _ref$noTree === undefined ? false : _ref$noTree, + _ref$noHeader = _ref.noHeader, + noHeader = _ref$noHeader === undefined ? false : _ref$noHeader, + _ref$onlyOne = _ref.onlyOne, + onlyOne = _ref$onlyOne === undefined ? false : _ref$onlyOne; + + _classCallCheck(this, SelectedContainer); + + // TODO: rename variables to camelCase + this.$self = $container; + this.elements_id = []; // [spec_id, spec_id, ...] + this.onlyOne = onlyOne; + this.options = { noHeader: noHeader }; + var self = this; + this.$self.hide(); + this.dataPromise = obj.dataPromise; + + this.dataPromise.then(function (data) { + data = data.results ? data.results : data; + _this.dataTree = noTree ? new _NoTreeData2.default(data) : new _DataTree2.default(data); + _this.$input = _this.$self.find('input[type="hidden"]'); + if (_this.$input.length == 0) throw new URIError('input for ' + _this.$self.attr("class") + ' not found'); + + _this.restoreElements(); + }).catch(self._onLoadDataError.bind(self)); + } + + _createClass(SelectedContainer, [{ + key: 'restoreElements', + value: function restoreElements() { + var self = this; + if (this.$input && this.$input.val()) { + + var clearString = this.$input.val().replace(/[\[\]\'\'\"\"]/g, ''); + var data = clearString.split(',').filter(function (el) { + return el; + }); + this.elements_id = []; + if (this.$input) this.$input.val(this.elements_id.join(',')); + data.forEach(function (el) { + return self.add(el); + }); + } + } + }, { + key: 'on', + value: function on(methodName, func) { + this[methodName] = this[methodName].bind(this, { func: func, bindFunc: true }); + } + }, { + key: '_removeById', + value: function _removeById(id) { + var index = this.elements_id.indexOf(id); + if (index >= 0) { + this.elements_id.splice(index, 1); + } + this.$self.find('span[data-id=\'' + id + '\']').parents('.selected-element').remove(); + } + }, { + key: '_onLoadDataError', + value: function _onLoadDataError(error) { + console.log("Error loading data -->", error); + } + }, { + key: 'removeAll', + value: function removeAll() { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.elements_id[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var id = _step.value; + + this._removeById(id); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } + }, { + key: 'remove', + value: function remove(e) { + var spec_id = $(e.target).data("id"); + this._removeById(spec_id); + if (this.$input) this.$input.val(this.elements_id.join(',')); + if (!this.elements_id.length) this.$self.hide(); + e.preventDefault(); + } + }, { + key: 'replace', + value: function replace(_id, max_len) { + var id = Number(_id); + if (this.elements_id.length > 1) throw new RangeError("Replace error: more than one element"); + // Remove old + this._removeById(this.elements_id[0]); + //Add new + this._addElementToHtml(id, max_len); + this.elements_id = [id]; + } + }, { + key: '_addElementToHtml', + value: function _addElementToHtml(id, max_len) { + var self = this; + var header = SelectedContainer.getHeader(this.dataTree.getSpecChain(id), "", max_len); + var name = this.dataTree.getElementById(id).name; + this.elements_id.push(id); + if (this.$input) this.$input.val(this.elements_id.join(',')); + // console.log("header = ", header); + this.$self.append(SelectedContainer.getTemplate(header || (this.options.noHeader ? "" : " "), name, id)); + this.btn_remove = this.$self.find('.icon-remove'); + this.btn_remove.on("click", this.remove.bind(self)); + if (this.elements_id.length) this.$self.show(); + } + }, { + key: 'add', + value: function add(_id, max_len) { + var id = Number(_id); + var el = this.dataTree.getElementById(id); + if (!el) { + throw new Error('\u042D\u043B\u0435\u043C\u0435\u043D\u0442 \u0441 id = ' + _id + ' \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0438 \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C \u0434\u043E\u0431\u0430\u0432\u043B\u0435\u043D'); + } + var self = this; + if (this.onlyOne) { + this.replace(_id, max_len); + return; + } + + var has_already = this.elements_id.filter(function (el) { + return self.dataTree.isChild(el, id); + }); + + if (has_already.length || this.elements_id.indexOf(Number(id)) != -1) { + //TODO: do popup messages + return; + } + + var not_valid = this.elements_id.filter(function (el) { + return self.dataTree.isChild(id, el); + }); + + not_valid.forEach(function (el) { + self._removeById(el); + }); + this._addElementToHtml(id, max_len); + } + }], [{ + key: 'getTemplate', + value: function getTemplate(header, name, id) { + return tmpl_selectedElement(header, name, id); + } + }, { + key: 'getHeader', + value: function getHeader(spec_chain, separator, max_len) { + function toShortString(string, max_len) { + return string.slice(0, max_len) + (string.length > max_len ? "..." : ""); + } + + separator = separator || ' / '; + var str_chain = ""; + + spec_chain.forEach(function (el) { + str_chain = (max_len ? toShortString(el.name, max_len) : el.name) + (str_chain ? separator : "") + str_chain; + }); + + return str_chain; + } + }]); + + return SelectedContainer; + }(), (_applyDecoratedDescriptor(_class.prototype, 'remove', [_decorators2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'remove'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'add', [_decorators2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'add'), _class.prototype)), _class); + exports.default = SelectedContainer; + +/***/ }, +/* 20 */ +/***/ function(module, exports) { + + "use strict"; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + + var Node = function Node(data, tree) { + _classCallCheck(this, Node); + + this.name = data.name; + this.id = data.id; + if (data.parent === null) { + this.parent = "root"; + data.parent = { id: "root" }; + this.name = ""; + } + if (data.parent.id && data.parent.id !== 'root') { + var el = tree._getElementById(data.parent.id); + this.parent = el.node || new Node(el, tree); + } + data.node = this; + this.children = data.children.map(function (el_obj) { + var el = tree._getElementById(el_obj.id); + if (el.node) return el.node; + el.node = new Node(el, tree); + return el.node; + }); + + this.children = this.children || []; + }; + + var DataTree = function () { + function DataTree(data) { + _classCallCheck(this, DataTree); + + this.baseData = data; + this._root = new Node(data[0], this); + } + + /** + * получить element в базовой структуре + */ + + + _createClass(DataTree, [{ + key: "_getElementById", + value: function _getElementById(id) { + for (var i = 0; i < this.baseData.length; i++) { + if (this.baseData[i].id == id) return this.baseData[i]; + } + } + + /** + * получить element в дереве + */ + + }, { + key: "getElementById", + value: function getElementById(id) { + function searchInChildren(children) { + for (var i = 0; i < children.length; i++) { + if (children[i].id == id) return children[i]; + var res = searchInChildren(children[i].children); + if (res) return res; + } + } + + return searchInChildren(this._root.children); + } + + /** + * Является ли узел c el_id дочерним для parent_id + * @param el_id + * @param parent_id + */ + + }, { + key: "isChild", + value: function isChild(elId, parent_id) { + function checkParent(el, parent) { + if (el.parent == parent) return true; + if (el.parent && el.parent != 'root') return checkParent(el.parent, parent); + return false; + } + return checkParent(this.getElementById(elId), this.getElementById(parent_id)); + } + }, { + key: "hasChildren", + value: function hasChildren(elId) { + return this.getElementById(elId).children.length ? true : false; + } + + /** + * @param start_parent_id(number) - начиная с + * @param attached(bool) - включая вложенные/дочерние + * @param exclude_id - исключая узел c exclude_id и всеми его вложенными узлами + * @returns [{name, id}, ...] + */ + + }, { + key: "dataToList", + value: function dataToList(start_parent_id, attached, exclude_id) { + var data_list = []; + + function goInChildren(children) { + for (var i = 0; i < children.length; i++) { + if (children[i].id == exclude_id) continue; + data_list.push({ name: children[i].name, id: children[i].id }); + if (attached) goInChildren(children[i].children); + } + } + var start = start_parent_id ? this.getElementById(start_parent_id) : this._root; + goInChildren(start.children); + return data_list; + } + + /** + * + * @param id + * @param incl(bool) - исключая сам элемент + * @returns {Array} всех узлов/элементов от элемента с id до корня + */ + + }, { + key: "getSpecChain", + value: function getSpecChain(id) { + var incl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + + var chain = []; + var el = this.getElementById(id); + function getParent(el) { + if (el.parent && el.parent != "root") { + chain.push(el.parent); + getParent(el.parent); + } + } + getParent(el); + if (incl) chain.unshift(el); + return chain; + } + }]); + + return DataTree; + }(); + + exports.default = DataTree; + +/***/ }, +/* 21 */ +/***/ function(module, exports) { + + "use strict"; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + + var NoTreeData = function () { + function NoTreeData(data) { + _classCallCheck(this, NoTreeData); + + this.data = data; + this.specChain = []; + } + + _createClass(NoTreeData, [{ + key: "getElementById", + value: function getElementById(id) { + for (var i = 0; i < this.data.length; i++) { + if (this.data[i].id == id) return this.data[i]; + } + } + }, { + key: "getSpecChain", + value: function getSpecChain(id, incl) { + return this.specChain; + } + }, { + key: "isChild", + value: function isChild(el_id, parent_id) { + return false; + } + }, { + key: "hasChildren", + value: function hasChildren() { + return false; + } + }, { + key: "dataToList", + value: function dataToList() { + return this.data; + } + }]); + + return NoTreeData; + }(); + + exports.default = NoTreeData; + +/***/ }, +/* 22 */ +/***/ function(module, exports) { + + "use strict"; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.default = onBind; + function onBind(target, name, descriptor) { + var method = descriptor.value; + + descriptor.value = function () { + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + var binds = []; + args = Array.from(args); + // console.log("args -->", args.slice()); + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = args.slice()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var arg = _step.value; + + // console.log("onBind -->", typeof arg, "arg = ", arg); + // console.log("arg.func -->", typeof arg.originalEvent); + // typeof arg === 'object' && !(arg.originalEvent) + if (arg && arg.bindFunc) { + binds.push(arg); + args.splice(args.indexOf(arg), 1); + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + method.apply(this, args); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = binds[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var bind = _step2.value; + + bind.func.bind(this)(args); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + return this; + }; + } + + // export {onBind}; + +/***/ }, +/* 23 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.default = undefined; + + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + + var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + + var _AbsBaseSelect2 = __webpack_require__(24); + + var _NoTreeData = __webpack_require__(21); + + var _NoTreeData2 = _interopRequireDefault(_NoTreeData); + + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + + function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + + var NoTreeSelect = function (_AbsBaseSelect) { + _inherits(NoTreeSelect, _AbsBaseSelect); + + function NoTreeSelect($container, _ref) { + var url = _ref.url, + obj = _ref.obj, + _ref$visible = _ref.visible, + visible = _ref$visible === undefined ? true : _ref$visible, + _ref$required = _ref.required, + required = _ref$required === undefined ? false : _ref$required; + + _classCallCheck(this, NoTreeSelect); + + //TODO: сделать автоматическую передачу всех параметров родителю + return _possibleConstructorReturn(this, (NoTreeSelect.__proto__ || Object.getPrototypeOf(NoTreeSelect)).call(this, $container, { url: url, obj: obj, visible: visible, required: required })); + } + + _createClass(NoTreeSelect, [{ + key: '_buildComponents', + value: function _buildComponents(data) { + _get(NoTreeSelect.prototype.__proto__ || Object.getPrototypeOf(NoTreeSelect.prototype), '_buildComponents', this).call(this, data); + this.dataTree = this.dataTree || new _NoTreeData2.default(data.results || data); + this.$buttonAddOptions.hide(); + this._fillOptionsData(); + this._bindEvents(); + } + }, { + key: '_onclickOptionsElement', + value: function _onclickOptionsElement(e) { + _get(NoTreeSelect.prototype.__proto__ || Object.getPrototypeOf(NoTreeSelect.prototype), '_onclickOptionsElement', this).call(this, e); + this.clear(); + var id = $(e.target).data("id"); + this.selectedContainer.add(id); + e.preventDefault(); + return false; + } + }, { + key: '_onButtonAddOptions', + value: function _onButtonAddOptions(e) { + // pass + } + }]); + + return NoTreeSelect; + }(_AbsBaseSelect2.AbsBaseSelect); + + exports.default = NoTreeSelect; + +/***/ }, +/* 24 */ +/***/ function(module, exports) { + + "use strict"; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + + //TEMPLATES ` + var tmpl_selectBoxEditCont = function tmpl_selectBoxEditCont() { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$preloaderTemplat = _ref.preloaderTemplate, + preloaderTemplate = _ref$preloaderTemplat === undefined ? "" : _ref$preloaderTemplat; + + return "\n
\n
\n \n
\n " + preloaderTemplate + "\n \n \n
\n
\n
\n \n
\n
\n"; + }; + + var tmpl_selectBox = function tmpl_selectBox() { + var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref2$preloaderTempla = _ref2.preloaderTemplate, + preloaderTemplate = _ref2$preloaderTempla === undefined ? "" : _ref2$preloaderTempla; + + return " \n " + preloaderTemplate + "\n \n \n"; + }; + + var tmpl_elementResult = function tmpl_elementResult(el, id, header) { + return "
  • "; + }; + + var tmpl_elementOption = function tmpl_elementOption(el) { + return "
  • " + el.name + "
  • "; + }; + + var tmpl_plug = function tmpl_plug(_ref3) { + var header = _ref3.header, + selectBox = _ref3.selectBox; + return htmlTemplate({ header: header, selectBox: selectBox }); + }; + + var tmpl_selectBoxOptions = function tmpl_selectBoxOptions() { + return "\n
    \n
    \n \n
    \n
    \n"; + }; + + var tmpl_selectBoxResults = function tmpl_selectBoxResults() { + return "\n
    \n
    \n
    \n
      \n
    \n
    \n
    \n \u0418\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u043A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u0439\n
      \n
    \n
    \n
    \n
    \n \n
    \n
    \n"; + }; + + var htmlTemplate = function htmlTemplate(_ref4) { + var header = _ref4.header, + selectBox = _ref4.selectBox, + _ref4$required = _ref4.required, + required = _ref4$required === undefined ? false : _ref4$required, + _ref4$id = _ref4.id, + id = _ref4$id === undefined ? "" : _ref4$id, + _ref4$classes = _ref4.classes, + classes = _ref4$classes === undefined ? "" : _ref4$classes, + _ref4$tmpl_selectBoxO = _ref4.tmpl_selectBoxOptions, + tmpl_selectBoxOptions = _ref4$tmpl_selectBoxO === undefined ? function () { + return ""; + } : _ref4$tmpl_selectBoxO, + _ref4$tmpl_selectBoxR = _ref4.tmpl_selectBoxResults, + tmpl_selectBoxResults = _ref4$tmpl_selectBoxR === undefined ? function () { + return ""; + } : _ref4$tmpl_selectBoxR; + return "\n
    \n
    \n
    " + header + "
    \n \n " + (required ? 'Обязательно' : '') + "\n
    \n
    \n " + selectBox + "\n
    \n \n " + tmpl_selectBoxOptions() + "\n " + tmpl_selectBoxResults() + "\n \n
    \n"; + }; + var tmpl_light = function tmpl_light(el) { + return "" + el + ""; + }; + + var tmpl_preloader = function tmpl_preloader() { + return "
    "; + }; + + var AbsBaseSelect = function () { + function AbsBaseSelect($container, _ref5) { + var url = _ref5.url, + obj = _ref5.obj, + _ref5$hasEditableCont = _ref5.hasEditableContainer, + hasEditableContainer = _ref5$hasEditableCont === undefined ? false : _ref5$hasEditableCont, + _ref5$visible = _ref5.visible, + visible = _ref5$visible === undefined ? false : _ref5$visible, + _ref5$required = _ref5.required, + required = _ref5$required === undefined ? false : _ref5$required; + + _classCallCheck(this, AbsBaseSelect); + + if (new.target === AbsBaseSelect) { + throw new TypeError("Cannot construct Abstract instances directly"); + } + if (obj && url) { + throw new URIError("Must be either the date or url"); + } + + var self = this; + //TODO: проверка наличия id контейнера + this.containerId = $container.attr("id"); + this.$container = $container; + this.hasEditableContainer = hasEditableContainer; + this.visible = visible; + this.required = required; + // Быстрая заглушка, до отображения данных + if (visible) { + var preloaderTemplate = tmpl_preloader(); + var selectBox = this.hasEditableContainer ? tmpl_selectBoxEditCont({ preloaderTemplate: preloaderTemplate }) : tmpl_selectBox({ preloaderTemplate: preloaderTemplate }); + var plugTemplate = tmpl_plug({ header: "Loading...", selectBox: selectBox }); + $container.html(plugTemplate); + + this.$preloader = $container.find('#component-preloader'); + this.$spinner = this.$preloader.find('.spinner'); + } + if (url) { + this.dataPromise = this.getData(url); + //TODO: дописать нормальную обработку url + this.type = url.split("/")[2]; + } + var _dataPromise = void 0; + if (url) { + _dataPromise = this.dataPromise; + } else { + _dataPromise = obj.dataPromise; + } + // if (dataTree) this.dataTree = dataTree; + _dataPromise.then(self._buildComponents.bind(self)).catch(self._onLoadDataError.bind(self)); + + // INIT EMPTY PROP + this.selectedEl = { id: undefined, value: undefined }; + this.parentId = undefined; + } + + _createClass(AbsBaseSelect, [{ + key: "getTemplate", + value: function getTemplate(classes) { + var selectBox = this.hasEditableContainer ? tmpl_selectBoxEditCont() : tmpl_selectBox(); + classes = classes ? classes.join(" ") : ""; + return htmlTemplate({ + header: "", selectBox: selectBox, required: this.required, id: this.containerId, classes: classes, + tmpl_selectBoxOptions: tmpl_selectBoxOptions, tmpl_selectBoxResults: tmpl_selectBoxResults + }); + } + }, { + key: "getData", + value: function getData(url) { + var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + var self = this; + return Promise.resolve($.ajax({ + url: url, + dataType: 'json', + data: data + })); + } + }, { + key: "hidePreloader", + value: function hidePreloader() { + // console.log("hide preloader ", this.$preloader); + this.$spinner.fadeOut(); + return Promise.resolve(this.$preloader.delay(500).fadeOut(2000)); + } + }, { + key: "clear", + value: function clear() { + this.$searchInput.val(""); + this.$optionsBox.hide(); + this.$resultsBox.hide(); + this.$buttonAdd.hide(); + this.$buttonAddOptions.hide(); + this.selectedEl = { id: undefined, value: undefined }; + if (this.hasEditableContainer) { + this.$editableContainer.html(""); + this.$editableContainer.hide(); + } + this.$searchInput.removeClass("active"); + } + }, { + key: "hide", + value: function hide() { + this.$selectBox.hide(); + } + }, { + key: "show", + value: function show() { + this.$selectBox.show(); + } + }, { + key: "setHeader", + value: function setHeader(header) { + + if (this.$header) { + this.$header.find('.header').html(header); + this.$header.show(); + } else { + this.header = header; + } + // default hide + // this.show(); + } + }, { + key: "setParent", + value: function setParent(parentId) { + this.parentId = parentId; + this._fillOptionsData(); + } + }, { + key: "connectSelectedContainer", + value: function connectSelectedContainer(selectedContainer) { + this.selectedContainer = selectedContainer; + } + }, { + key: "getIdsSelectedElements", + value: function getIdsSelectedElements() { + var allChecked = this.$resultsBox.find(":checked"); + return allChecked.map(function () { + return $(this).data("id"); + }); + } + }, { + key: "updateEditableContainer", + value: function updateEditableContainer(elId) { + // Если нет контейнера для отображения ... + if (this.$editableContainer.length) { + var separator = ' / '; + var chainHeader = AbsBaseSelect.getHeader(this.dataTree.getSpecChain(elId, true), { separator: separator }); + chainHeader = AbsBaseSelect.highlight(chainHeader, separator, true); + var elTemplate = "" + chainHeader + ""; + this.$editableContainer.html(elTemplate); + this.$editableContainer.show(); + return; + } + //..., передаем отображение предыдущему selectBox + if (this.prevSelectBox) this.prevSelectBox.updateEditableContainer(elId); + } + }, { + key: "_buildComponents", + value: function _buildComponents(data) { + // AFTER PRELOAD + // this.hidePreloader().then(() => console.log("END -)")); + var classes = this.$container.attr('class'); + if (classes) classes = classes.split(/\s+/); + var template = this.getTemplate(classes); + this.$container.replaceWith(template); + + this.$selectBox = $("#" + this.containerId); + this.$header = this.$selectBox.find('.select-box-header'); + this.$header.find('.header').html(this.header); + if (!this.header) this.$header.hide(); + this.$resultsBox = this.$selectBox.find('.select-box-results'); + this.$optionsBox = this.$selectBox.find('.select-box-options'); + this.$searchInput = this.$selectBox.find('input.select-box-search'); + this.$buttonAdd = this.$selectBox.find('.button-add.results'); + this.$buttonAddOptions = this.$selectBox.find('.button-add.options'); + this.$editableContainer = this.$selectBox.find('.editable-container'); + this.$resultsBox.hide(); + this.$optionsBox.hide(); + this.$buttonAddOptions.hide(); + //TODO: реализовать нормальное show/hide + visible + if (!this.visible) this.hide(); + // TODO: сделать проверку на наличие всех нужных элементов и их корректый jq select + } + }, { + key: "_fillOptionsData", + value: function _fillOptionsData() { + var self = this; + var dataList = this.dataTree.dataToList(this.parentId); + var $container = this.$optionsBox.find('ul'); + $container.html(""); + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = dataList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var el = _step.value; + + $container.append($(tmpl_elementOption(el))); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + this.$selectBox.find('li').on("click", this._onclickOptionsElement.bind(self)); + } + }, { + key: "_search", + value: function _search(_ref6) { + var searchText = _ref6.searchText, + _ref6$parentCategoryI = _ref6.parentCategoryId, + parentCategoryId = _ref6$parentCategoryI === undefined ? null : _ref6$parentCategoryI, + _ref6$attached = _ref6.attached, + attached = _ref6$attached === undefined ? true : _ref6$attached, + _ref6$excludeCategory = _ref6.excludeCategoryId, + excludeCategoryId = _ref6$excludeCategory === undefined ? null : _ref6$excludeCategory; + + // :FORMAT spec_list [{name, id}, ...] + var specList = this.dataTree.dataToList(parentCategoryId, attached, excludeCategoryId); + return specList.filter(function (el) { + return el.name.toLowerCase().indexOf(searchText.toLowerCase()) !== -1; + }); + } + }, { + key: "_fillContainer", + value: function _fillContainer($container, template, _ref7) { + var _ref7$searchText = _ref7.searchText, + searchText = _ref7$searchText === undefined ? "" : _ref7$searchText, + _ref7$parentCategoryI = _ref7.parentCategoryId, + parentCategoryId = _ref7$parentCategoryI === undefined ? null : _ref7$parentCategoryI, + _ref7$attached = _ref7.attached, + attached = _ref7$attached === undefined ? true : _ref7$attached, + _ref7$excludeCategory = _ref7.excludeCategoryId, + excludeCategoryId = _ref7$excludeCategory === undefined ? null : _ref7$excludeCategory; + + $container.html(""); + $('.other-part').show(); + var searchRes = this._search({ searchText: searchText, parentCategoryId: parentCategoryId, attached: attached, excludeCategoryId: excludeCategoryId }); + if (!searchRes.length) { + if ($container.closest('div').hasClass('main-part')) { + $container.append('
  • Ничего не найдено
  • '); + this.$resultsBox.find('.button-add.results').hide(); + } else { + $('.other-part').hide(); + } + return; + } + this.$resultsBox.find('.button-add.results').show(); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = searchRes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var el = _step2.value; + + var header = AbsBaseSelect.getHeader(this.dataTree.getSpecChain(el.id), {}); + $container.append(template(AbsBaseSelect.highlight(el.name, searchText), el.id, header)); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + } + }, { + key: "_fillResultsData", + value: function _fillResultsData(searchText) { + var self = this; + // FILL RESULTS + // MAIN PART + var $container = this.$resultsBox.find('.main-part ul'); + this._fillContainer($container, tmpl_elementResult, { searchText: searchText, parentCategoryId: self.parentId }); + + // OTHER PART + // Если нет parentId, не нужно искать в других категориях + if (!this.parentId) { + $('.other-part').hide(); + } else { + $container = this.$resultsBox.find('.other-part ul'); + this._fillContainer($container, tmpl_elementResult, { searchText: searchText, excludeCategoryId: self.parentId }); + } + this.$resultsBox.find('div.header').hide(); + this.$resultsBox.find('li').on("mouseover", function (e) { + $(e.target).children('.header').show(300); + e.preventDefault(); + }); + + this.$resultsBox.find('li').on("mouseout", function (event) { + var e = event.toElement || event.relatedTarget; + if (e.parentNode == this || e == this) { + return; + } + $(this).find('.header').hide(); + }); + } + }, { + key: "setElementById", + value: function setElementById(id) { + var value = this.dataTree.getElementById(id).name; + this.selectedEl.id = id; + this.selectedEl.value = value; + this.$searchInput.val(value); + this.updateEditableContainer(id); + } + }, { + key: "_onclickOptionsElement", + value: function _onclickOptionsElement(e) { + var id = $(e.target).data("id"); + this.setElementById(id); + this.$buttonAddOptions.show(); + this.$optionsBox.hide(); + } + }, { + key: "_onButtonAddOptions", + value: function _onButtonAddOptions(e) { + this._addToSelectedContainer(this.selectedEl.id); + this.clear(); + e.preventDefault(); + return false; + } + }, { + key: "_onButtonAdd", + value: function _onButtonAdd(e) { + var self = this; + + this.getIdsSelectedElements().each(function () { + self._addToSelectedContainer(this); + }); + this.clear(); + e.preventDefault(); + return false; + } + }, { + key: "_onLoadDataError", + value: function _onLoadDataError(error) { + console.log("Error loading data -->", error); + } + }, { + key: "_addToSelectedContainer", + value: function _addToSelectedContainer(id) { + this.selectedContainer.add(id); + } + }, { + key: "_onInput_searchInput", + value: function _onInput_searchInput(e) { + this._fillResultsData(this.$searchInput.val()); + this.$resultsBox.show(); + this.$optionsBox.hide(); + } + }, { + key: "_onClick_searchInput", + value: function _onClick_searchInput(e) { + this.$optionsBox.show(); + this.$resultsBox.hide(); + this.$searchInput.val(""); + } + }, { + key: "_bindEvents", + value: function _bindEvents() { + var self = this; + $(document).click(function (event) { + if ($(event.target).closest("#" + self.containerId).length) { + return; + } + self._looseFocus(); + }); + // RESULTS BOX + this.$searchInput.on("input", this._onInput_searchInput.bind(self)); + // OPTIONS BOX + this.$searchInput.on("click", this._onClick_searchInput.bind(self)); + + this.$buttonAdd.on("click", this._onButtonAdd.bind(self)); + + this.$buttonAddOptions.on("click", this._onButtonAddOptions.bind(self)); + } + }, { + key: "_looseFocus", + value: function _looseFocus() { + this.$resultsBox.hide(); + this.$optionsBox.hide(); + if (!this.selectedEl.id) { + this.$searchInput.val(""); + } else { + this.$searchInput.val(this.selectedEl.value); + } + } + }], [{ + key: "getHeader", + value: function getHeader(catChain, _ref8) { + var _ref8$separator = _ref8.separator, + separator = _ref8$separator === undefined ? " / " : _ref8$separator, + _ref8$maxLen = _ref8.maxLen, + maxLen = _ref8$maxLen === undefined ? 60 : _ref8$maxLen; + + function toShortString(string, maxLen) { + return string.slice(0, maxLen) + (string.length > maxLen ? "..." : ""); + } + + var strChain = ""; + + catChain.forEach(function (el) { + strChain = (maxLen ? toShortString(el.name, maxLen) : el.name) + (strChain ? separator : "") + strChain; + }); + + return strChain; + } + }, { + key: "highlight", + value: function highlight(string, sub_string) { + var lastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + + var index = lastIndex ? string.toLowerCase().lastIndexOf(sub_string.toLowerCase()) : string.toLowerCase().indexOf(sub_string.toLowerCase()); + if (index === -1) return string; + var before = void 0, + select = void 0, + after = void 0; + if (lastIndex) { + var _ref9 = [string.slice(0, index), string.slice(index, string.length), ""]; + before = _ref9[0]; + select = _ref9[1]; + after = _ref9[2]; + } else { + var _ref10 = [string.slice(0, index), string.slice(index, index + sub_string.length), string.slice(index + sub_string.length)]; + before = _ref10[0]; + select = _ref10[1]; + after = _ref10[2]; + } + + return "" + before + tmpl_light(select) + after; + } + }]); + + return AbsBaseSelect; + }(); + + exports.default = AbsBaseSelect; + exports.htmlTemplate = htmlTemplate; + exports.tmpl_plug = tmpl_plug; + exports.tmpl_elementOption = tmpl_elementOption; + exports.tmpl_preloader = tmpl_preloader; + exports.tmpl_light = tmpl_light; + exports.tmpl_elementResult = tmpl_elementResult; + exports.tmpl_selectBox = tmpl_selectBox; + exports.tmpl_selectBoxEditCont = tmpl_selectBoxEditCont; + exports.tmpl_selectBoxResults = tmpl_selectBoxResults; + exports.tmpl_selectBoxOptions = tmpl_selectBoxOptions; + exports.AbsBaseSelect = AbsBaseSelect; + +/***/ }, +/* 25 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.default = undefined; + + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + + var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + + var _AbsBaseSelect2 = __webpack_require__(24); + + var _DataTree = __webpack_require__(20); + + var _DataTree2 = _interopRequireDefault(_DataTree); + + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + + function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + + var TreeSelect = function (_AbsBaseSelect) { + _inherits(TreeSelect, _AbsBaseSelect); + + function TreeSelect() { + _classCallCheck(this, TreeSelect); + + return _possibleConstructorReturn(this, (TreeSelect.__proto__ || Object.getPrototypeOf(TreeSelect)).apply(this, arguments)); + } + + _createClass(TreeSelect, [{ + key: 'setNearbySelectBox', + value: function setNearbySelectBox(next, prev) { + this.nextSelectBox = next; + this.prevSelectBox = prev; + } + }, { + key: 'clearAllNext', + value: function clearAllNext() { + this.clear(); + if (this.nextSelectBox) { + this.nextSelectBox.hide(); + this.nextSelectBox.clearAllNext(); + } + } + }, { + key: 'clearAllPrev', + value: function clearAllPrev() { + this.clear(); + if (this.prevSelectBox) { + this.clear(); + this.hide(); + this.prevSelectBox.clearAllPrev(); + } + } + }, { + key: '_buildComponents', + value: function _buildComponents(data) { + _get(TreeSelect.prototype.__proto__ || Object.getPrototypeOf(TreeSelect.prototype), '_buildComponents', this).call(this, data); + //TODO: Изменять свойство visible при show/hide + if (!this.visible) this.hide(); + if (this.hasEditableContainer) this.$editableContainer.hide(); + this.dataTree = this.dataTree || new _DataTree2.default(data.results); + this._fillOptionsData(); + this._bindEvents(); + } + }, { + key: '_onclickOptionsElement', + value: function _onclickOptionsElement(e) { + this.clearAllNext(); + _get(TreeSelect.prototype.__proto__ || Object.getPrototypeOf(TreeSelect.prototype), '_onclickOptionsElement', this).call(this, e); + if (this.nextSelectBox && this.dataTree.hasChildren(this.selectedEl.id)) { + this.nextSelectBox.setParent(this.selectedEl.id); + this.nextSelectBox.setHeader(this.selectedEl.value); + this.nextSelectBox.show(); + } + if (this.prevSelectBox) { + this.prevSelectBox.$buttonAddOptions.hide(); + this.prevSelectBox.$searchInput.removeClass("active"); + } + this.$searchInput.addClass('active'); + } + }, { + key: '_onButtonAddOptions', + value: function _onButtonAddOptions(e) { + // this._addToSelectedContainer(this.selectedEl.id); + // this.clear(); + // e.preventDefault(); + // return false; + _get(TreeSelect.prototype.__proto__ || Object.getPrototypeOf(TreeSelect.prototype), '_onButtonAddOptions', this).call(this, e); + this.clearAllNext(); + this.clearAllPrev(); + } + }, { + key: '_onButtonAdd', + value: function _onButtonAdd(e) { + _get(TreeSelect.prototype.__proto__ || Object.getPrototypeOf(TreeSelect.prototype), '_onButtonAdd', this).call(this, e); + this.clearAllNext(); + this.clearAllPrev(); + } + }, { + key: '_addToSelectedContainer', + value: function _addToSelectedContainer(id) { + if (this.selectedContainer) { + this.selectedContainer.add(id); + return; + } + + this.prevSelectBox._addToSelectedContainer(id); + } + }]); + + return TreeSelect; + }(_AbsBaseSelect2.AbsBaseSelect); + + exports.default = TreeSelect; + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/assets/js/build/project_filter.js b/assets/js/build/project_filter.js index 3eb6917..5a1d1e1 100644 --- a/assets/js/build/project_filter.js +++ b/assets/js/build/project_filter.js @@ -55,7 +55,7 @@ function paginateTo(pageNum) { var $form = $('#filter-form'); var postfix = "&page=" + pageNum; - var $container = $('#projectsBlock'); + var $container = $('#resultsBlock'); (0, _ajax_set_filter.sendData)($form, $container, pageNum); (0, _ajax_set_filter.modUrl)($form, postfix); diff --git a/assets/js/build/worksell_filter.js b/assets/js/build/worksell_filter.js new file mode 100644 index 0000000..9c2e0fd --- /dev/null +++ b/assets/js/build/worksell_filter.js @@ -0,0 +1,228 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var _custom_check = __webpack_require__(1); + + var _extended_field = __webpack_require__(2); + + var _ajax_set_filter = __webpack_require__(3); + + var _filter_toggle = __webpack_require__(4); + + function paginateTo(pageNum) { + var $form = $('#filter-form'); + var postfix = "&page=" + pageNum; + var $container = $('#resultsBlock'); + + (0, _ajax_set_filter.sendData)($form, $container, pageNum); + (0, _ajax_set_filter.modUrl)($form, postfix); + return false; + } + + $(function () { + (0, _custom_check.customCheckInit)(); + (0, _extended_field.extendedFieldInit)(); + (0, _filter_toggle.filterToggleInit)(); + window.sendFilterData = _ajax_set_filter.sendFilterData; + window.paginateTo = paginateTo; + }); + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + "use strict"; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + function customCheckInit() { + function tuneCheckBoxes($boxes) { + var currentState = $boxes.find("input").prop("checked") ? 'checked' : 'not-checked'; + $boxes.find("div").hide(); + $boxes.find("div." + currentState).show(); + } + + var $boxes = $('.custom-check'); + tuneCheckBoxes($boxes); + $boxes.on("click", function (e) { + var inside_checkBox = $(e.target).parent().find("input"); + inside_checkBox.prop("checked", !inside_checkBox.prop("checked")); + tuneCheckBoxes($boxes); + e.preventDefault(); + return false; + }); + } + + exports.customCheckInit = customCheckInit; + +/***/ }, +/* 2 */ +/***/ function(module, exports) { + + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + function extendedFieldInit() { + + var $buttonF1 = $('.resButton'); + if ($('.slide').hasClass("active")) $buttonF1.css('transform', 'rotate(0deg)'); + + $buttonF1.on("click", function (e) { + e.preventDefault(); + var $slide = $('.slide'); + if ($slide.hasClass("active")) { + $buttonF1.css('transform', 'rotate(180deg)'); + $slide.slideUp(300); + } else { + $buttonF1.css('transform', 'rotate(0deg)'); + $slide.slideDown(300); + } + $slide.toggleClass("active"); + }); + } + + exports.extendedFieldInit = extendedFieldInit; + +/***/ }, +/* 3 */ +/***/ function(module, exports) { + + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + function getFormData($form, pageNum) { + var unindexed_array = $form.serializeArray(); + var indexed_array = {}; + + $.map(unindexed_array, function (n, i) { + indexed_array[n['name']] = n['value']; + }); + indexed_array["page"] = pageNum || ""; + return indexed_array; + } + + // TODO: Восстановление фильтров из URL + function modUrl($form, postfix) { + var curLoc = '?' + $form.serialize() + (postfix || ""); + try { + history.replaceState($form.serialize(), null, curLoc); + } catch (e) { + console.log("Error!"); + } + } + + function sendData($form, $update_container, pageNum) { + function updateResults(html) { + $update_container.html(html); + var title = $('#titleScore').val(); + $('.search-num').html(title); + } + + console.log("form method = ", $form.attr("method")); + $.ajax({ + url: $form.attr("action"), + type: $form.attr("method"), + dataType: 'html', + data: getFormData($form, pageNum), + beforeSend: function beforeSend(xhr) { + xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); + }, + success: updateResults, + error: function error(data) { + return console.log("Error", data); + } + }); + } + + function sendFilterData($form, $update_container) { + sendData($form, $update_container); + modUrl($form); + return false; + } + + exports.sendFilterData = sendFilterData; + exports.sendData = sendData; + exports.modUrl = modUrl; + +/***/ }, +/* 4 */ +/***/ function(module, exports) { + + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + function filterToggleInit() { + var $group = $('.btn-group.toggle'); + var $buttons = $group.find('a.btn').add('.link-sort a.btn'); + // let $input = $('input[name="party_types"]'); + + $buttons.on("click", function (e) { + e.preventDefault(); + var $target = $(e.target); + var $parent = $target.parent(); + // console.log('parent class = ', $parent.attr("class")); + $parent.children().removeClass('active'); + $target.addClass('active'); + // console.log('type = ', $target.data("type")); + $parent.find('input').val($target.data("type")); + // console.log('click'); + sendFilterData($('#filter-form'), $('#resultsBlock')); + }); + } + + exports.filterToggleInit = filterToggleInit; + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/assets/js/src/contractor_filter.js b/assets/js/src/contractor_filter.js index 1372aae..8170f18 100644 --- a/assets/js/src/contractor_filter.js +++ b/assets/js/src/contractor_filter.js @@ -6,7 +6,7 @@ import {filterToggleInit} from './seeds/filter_toggle' function paginateTo(pageNum) { const $form = $('#filter-form'); const postfix = "&page=" + pageNum; - const $container = $('#contractorsBlock'); + const $container = $('#resultsBlock'); sendData($form, $container, pageNum); modUrl($form, postfix); diff --git a/assets/js/src/init_worksell_filter.js b/assets/js/src/init_worksell_filter.js new file mode 100644 index 0000000..5733b7d --- /dev/null +++ b/assets/js/src/init_worksell_filter.js @@ -0,0 +1,65 @@ +// ` +import SelectedContainer from 'components/SelectedContainer'; +import NoTreeSelect from 'components/NoTreeSelect'; +import TreeSelect from 'components/TreeSelect'; + +$(function () { + function createFilterSpecs(url) { + // SPECIALIZATIONS FILTER + let sb_main = new TreeSelect($('#select-box-1'), {url, visible: true, hasEditableContainer: true}); + sb_main.setHeader("Тип готовой работы"); + let select_container = new SelectedContainer($('#selected-spec'), {obj: sb_main}); + sb_main.connectSelectedContainer(select_container); + let sb_1 = new TreeSelect($('#select-box-2'), {obj: sb_main}); + let sb_2 = new TreeSelect($('#select-box-3'), {obj: sb_main}); + let sb_3 = new TreeSelect($('#select-box-4'), {obj: sb_main}); + let sb_4 = new TreeSelect($('#select-box-5'), {obj: sb_main}); + + sb_main.setNearbySelectBox(sb_1); + sb_1.setNearbySelectBox(sb_2, sb_main); + sb_2.setNearbySelectBox(sb_3, sb_1); + sb_3.setNearbySelectBox(sb_4, sb_2); + sb_4.setNearbySelectBox("", sb_3); + + } + + function createFilterBuildingClass(url) { + // BUILDING-CLASSIFICATION FILTER + let sb_build_main = new TreeSelect($('#sb-building-classification'), {url, visible:true}); + sb_build_main.setHeader("Классификация здания"); + + let sb_build_1 = new TreeSelect($('#sb-building-sub-classification'), {obj: sb_build_main}); + + let select_build_container = new SelectedContainer($('#selected-building-classification'), {obj: sb_build_main}); + sb_build_main.connectSelectedContainer(select_build_container); + + sb_build_main.setNearbySelectBox(sb_build_1); + sb_build_1.setNearbySelectBox("", sb_build_main); + } + + function createFilterConstructionType(url) { + let sb_constr_main = new NoTreeSelect($('#sb-construction-type'), {url, visible:true}); + sb_constr_main.setHeader("Вид строительства"); + let select_constr_type = new SelectedContainer($('#selected-construction-type'), {obj:sb_constr_main, noTree: true}); + sb_constr_main.connectSelectedContainer(select_constr_type); + } + + function createFilerLocations(url) { + let sb_loc_main = new TreeSelect($('#sb-location-1'), {url, visible:true}); + sb_loc_main.setHeader("Проектное местоположение"); + let select_loc = new SelectedContainer($('#selected-location'), {obj: sb_loc_main}); + sb_loc_main.connectSelectedContainer(select_loc); + let sb_loc_1 = new TreeSelect($('#sb-location-2'), {obj: sb_loc_main}); + let sb_loc_2 = new TreeSelect($('#sb-location-3'), {obj: sb_loc_main}); + + sb_loc_main.setNearbySelectBox(sb_loc_1); + sb_loc_1.setNearbySelectBox(sb_loc_2, sb_loc_main); + sb_loc_2.setNearbySelectBox("", sb_loc_1); + + } + + createFilterSpecs('/api/specializations_flat'); + createFilterBuildingClass('/api/building_classifications'); + createFilterConstructionType('/api/construction_type'); + createFilerLocations('/api/locations_flat'); +}); \ No newline at end of file diff --git a/assets/js/src/project_filter.js b/assets/js/src/project_filter.js index 3b6243f..096f766 100644 --- a/assets/js/src/project_filter.js +++ b/assets/js/src/project_filter.js @@ -5,7 +5,7 @@ import {sendFilterData, sendData, modUrl} from './seeds/ajax_set_filter' function paginateTo(pageNum) { const $form = $('#filter-form'); const postfix = "&page=" + pageNum; - const $container = $('#projectsBlock'); + const $container = $('#resultsBlock'); sendData($form, $container, pageNum); modUrl($form, postfix); diff --git a/assets/js/src/seeds/filter_toggle.js b/assets/js/src/seeds/filter_toggle.js index 89c7826..aa4968a 100644 --- a/assets/js/src/seeds/filter_toggle.js +++ b/assets/js/src/seeds/filter_toggle.js @@ -13,7 +13,7 @@ function filterToggleInit() { // console.log('type = ', $target.data("type")); $parent.find('input').val($target.data("type")); // console.log('click'); - sendFilterData($('#filter-form'), $('#contractorsBlock')); + sendFilterData($('#filter-form'), $('#resultsBlock')); }) } diff --git a/assets/js/src/worksell_filter.js b/assets/js/src/worksell_filter.js new file mode 100644 index 0000000..8170f18 --- /dev/null +++ b/assets/js/src/worksell_filter.js @@ -0,0 +1,22 @@ +import {customCheckInit} from './seeds/custom_check' +import {extendedFieldInit} from './seeds/extended_field' +import {sendFilterData, sendData, modUrl} from './seeds/ajax_set_filter' +import {filterToggleInit} from './seeds/filter_toggle' + +function paginateTo(pageNum) { + const $form = $('#filter-form'); + const postfix = "&page=" + pageNum; + const $container = $('#resultsBlock'); + + sendData($form, $container, pageNum); + modUrl($form, postfix); + return false; +} + +$(function () { + customCheckInit(); + extendedFieldInit(); + filterToggleInit(); + window.sendFilterData = sendFilterData; + window.paginateTo = paginateTo; +}); \ No newline at end of file diff --git a/assets/projects-filter.js b/assets/projects-filter.js index 4a489f6..399e293 100644 --- a/assets/projects-filter.js +++ b/assets/projects-filter.js @@ -104,7 +104,7 @@ function sendData(url, $form, pageNum) { $container.html(html); } - const $container = $('#projectsBlock'); + const $container = $('#resultsBlock'); $.ajax({ url: url, type: "POST", diff --git a/assets/sass/components/custom-components.sass b/assets/sass/components/custom-components.sass index a661d75..5387f4a 100644 --- a/assets/sass/components/custom-components.sass +++ b/assets/sass/components/custom-components.sass @@ -10,6 +10,9 @@ label font-weight: normal +.flex + display: flex + .nav li.active border-top: 3px solid black @@ -361,3 +364,138 @@ textarea.description .btn-up_down.clicked &:after content: "\e252" + +.filter + width: 100% + //float: left + background-color: #F2F2F2 + position: relative + padding: 45px 50px + .triangle1 + position: absolute + border: 30px solid transparent + border-top: 17px solid white + top: 0 + left: 50% + margin-left: -30px + + .findReal, .findReal:visited + float: left + color: white + font-size: 16px + font-family: 'pfdintextcomppro-regular', sans-serif + background: url('#{$static}/img/list2.png') no-repeat 41px, #FF0029 + padding: 17px 48px 17px 79px + border-radius: 40px + text-transform: uppercase + .clearSearch + font-size: 15px + font-family: Arial, Verdana, Helvetica, sans-serif + float: left + position: relative + color: #8a8989 + font-style: italic + margin: 14px 0 0 39px + &:before + content: '' + position: absolute + width: 21px + height: 22px + background: url('#{$static}/img/cenaList.png') no-repeat left + background-size: cover + background-position: 0 -46px + left: -33px + top: -3px + &:hover + text-decoration: none + color: #676666 + + .insetCol, .insetCol2 + width: 100% + float: left + margin-top: 15px + position: relative + + .insetCol + background-color: #F2F2F2 + padding: 15px + -webkit-transition: all 0.3s ease-out + -moz-transition: all 0.3s ease-out + transition: all 0.3s ease-out + +.pagin + text-align: center + margin-top: 30px + nav + display: inline-block + ul + li + float: left + margin-right: 26px + padding: 0 0 + line-height: 50px + a + background-color: transparent + color: black + font-size: 20px + line-height: 50px + font-family: 'pfdintextcomppro-regular', sans-serif + border: none + border-radius: 100% + .active a + color: white + background-color: #2c2c2c + padding: 20px !important + line-height: 10px + li a + padding: 20px 0 !important + line-height: 10px + width: 50px !important + height: 50px !important + text-align: center + &:hover, &:active + color: white + background-color: #2c2c2c + border-color: #2c2c2c + li a span + margin-top: -10px + ul + li + &:last-child a:hover, &:first-child a:hover + background: none !important + color: #2c2c2c + opacity: 0.8 + float: left + margin-right: 26px + padding: 0 0 + line-height: 50px + a + background-color: transparent + color: black + font-size: 20px + line-height: 50px + font-family: 'pfdintextcomppro-regular', sans-serif + border: none + border-radius: 100% + .active a + color: white + background-color: #2c2c2c + padding: 20px !important + line-height: 10px + li a + padding: 20px 0 !important + line-height: 10px + width: 50px !important + height: 50px !important + text-align: center + &:hover, &:active + color: white + background-color: #2c2c2c + border-color: #2c2c2c + li a span + margin-top: -10px + ul li + &:last-child a:hover, &:first-child a:hover + background: none !important + color: #2c2c2c + opacity: 0.8 \ No newline at end of file diff --git a/assets/sass/elements/worksell_card.sass b/assets/sass/elements/worksell_card.sass new file mode 100644 index 0000000..1ffec40 --- /dev/null +++ b/assets/sass/elements/worksell_card.sass @@ -0,0 +1,78 @@ +@import "base/variavles" +$size: 250px +$figure_size: 50px +.cards + display: flex + align-items: flex-start + flex-flow: row wrap +.worksell-card + //&:first-child + // margin-left: 0 + // margin-right: 0 + margin: 15px + display: inline-block + a + -webkit-transition: all 0.3s ease-out + -moz-transition: all 0.3s ease-out + transition: all 0.3s ease-out + display: inline-block + color: #235080 + a:hover, + a:visited + .img-figure + opacity: 1 + transform: scale(1.06) + text-decoration: none + color: #121880 + box-shadow: 0 0 10px rgba(0,0,0,0.7) + .img-block + width: $size + //border: 1px solid red + position: relative + .img + width: $size + height: $size + border: 10px solid #F2F2F2 + background: + repeat: no-repeat + position: center + size: cover + .cost-wrapper + position: absolute + bottom: 0 + width: 100% + text-align: center + .cost + color: #fb2c2d + font-size: 18px + display: inline-block + min-width: $size*0.8 + background-color: white + padding: 4px 8px + //border: 1px solid black + + .name-block + margin-top: 15px + max-width: $size + text-align: center + + .img-figure + width: $figure_size + height: $figure_size + -webkit-transition: all 0.3s ease-out + -moz-transition: all 0.3s ease-out + transition: all 0.3s ease-out + border-radius: 100% + background: + image: url("#{$static}/img/img.png") + repeat: no-repeat + position: center + //size: cover + color: rgba(211,211,211,0.8) + position: absolute + top: 50% + left: 50% + margin-left: -$figure_size/2 + margin-top: -$figure_size/2 + opacity: 0 + diff --git a/assets/sass/main.sass b/assets/sass/main.sass index 894a953..0a9d665 100644 --- a/assets/sass/main.sass +++ b/assets/sass/main.sass @@ -45,6 +45,17 @@ body stretch: normal letter-spacing: 2px + p + line-height: 36px + padding: 0 100px + width: 100% + text-align: center + float: left + font-family: 'pfbeausanspro-thin', sans-serif + font-size: 36px + margin: 48px 0 45px 0 + letter-spacing: 2px + .vertical-child margin-top: 30px diff --git a/projects/templates/partials/inc-projects-filter.html b/projects/templates/partials/inc-projects-filter.html index 8383610..5546b8e 100644 --- a/projects/templates/partials/inc-projects-filter.html +++ b/projects/templates/partials/inc-projects-filter.html @@ -54,7 +54,7 @@
    {# $(this).closest('form').submit(); return false#} - + найти проект
    diff --git a/projects/templates/project_filter.html b/projects/templates/project_filter.html index 9eded84..24de6cc 100644 --- a/projects/templates/project_filter.html +++ b/projects/templates/project_filter.html @@ -18,7 +18,7 @@ {% include 'partials/inc-projects-filter.html' %}
    -
    +
    {% include 'partials/inc-projects-results.html' %}
    diff --git a/templates/partials/ajax_pagination.html b/templates/partials/ajax_pagination.html index 9d70c78..ec190a6 100644 --- a/templates/partials/ajax_pagination.html +++ b/templates/partials/ajax_pagination.html @@ -2,7 +2,7 @@ {#function paginateTo(pageNum) {#} {# const $form = $('#filter-form');#} {# const postfix = "&page=" + pageNum;#} -{# const $container = $('#contractorsBlock');#} +{# const $container = $('#resultsBlock');#} {##} {# sendData($form, $container, pageNum);#} {# modUrl($form, postfix);#} diff --git a/templates/partials/header.html b/templates/partials/header.html index e48fb27..e26e445 100644 --- a/templates/partials/header.html +++ b/templates/partials/header.html @@ -143,7 +143,7 @@
  • - Готовые проекты + Готовые проекты
  • {% endif %} {% if request.user.is_customer %} @@ -151,7 +151,7 @@ Поиск исполнителей
  • - Готовые проекты + Готовые проекты
  • {% endif %} {% else %} @@ -162,7 +162,7 @@ Поиск исполнителей
  • - Готовые проекты + Готовые проекты
  • {% endif %} diff --git a/templates/partials/trash/header.html b/templates/partials/trash/header.html index 9b9ea67..7eaf205 100644 --- a/templates/partials/trash/header.html +++ b/templates/partials/trash/header.html @@ -40,7 +40,7 @@
  • - Готовые проекты + Готовые проекты
  • {% endif %} @@ -51,7 +51,7 @@
  • - Готовые проекты + Готовые проекты
  • {% endif %} @@ -68,7 +68,7 @@
  • - Готовые проекты + Готовые проекты
  • diff --git a/users/templates/contractor_filter.html b/users/templates/contractor_filter.html index 1354799..5a0ae93 100644 --- a/users/templates/contractor_filter.html +++ b/users/templates/contractor_filter.html @@ -18,7 +18,7 @@ {% include 'partials/inc-contractors-filter.html' %}
    -
    +
    {% include 'partials/inc-contractors-results.html' %}
    diff --git a/users/templates/partials/inc-contractors-filter.html b/users/templates/partials/inc-contractors-filter.html index 87fc9af..1f41cf0 100644 --- a/users/templates/partials/inc-contractors-filter.html +++ b/users/templates/partials/inc-contractors-filter.html @@ -40,7 +40,7 @@ diff --git a/webpack.config.js b/webpack.config.js index 0d5fd1f..9d39712 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -23,6 +23,8 @@ module.exports = { init_contractor_filter: "./assets/js/src/init_contractor_filter.js", contractor_filter: "./assets/js/src/contractor_filter.js", project_filter: "./assets/js/src/project_filter.js", + init_worksell_filter: "./assets/js/src/init_worksell_filter.js", + worksell_filter: "./assets/js/src/worksell_filter.js", //portfolio init_portfolio_create_edit: "./assets/js/src/init_portfolio_create_edit.js", portfolio_create_edit: "./assets/js/src/portfolio_create_edit.js", diff --git a/work_sell/templates/partials/inc-worksell-filter.html b/work_sell/templates/partials/inc-worksell-filter.html new file mode 100644 index 0000000..1e2f7fe --- /dev/null +++ b/work_sell/templates/partials/inc-worksell-filter.html @@ -0,0 +1,147 @@ +
    + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    + +
    +
    +
    + + Поиск по ключевым словам и фразам + + +
    +
    +
    +
    + + + + +
    +
    +
    + Расширенные поля + +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    + Требуется электронная версия + +
    + +
    +
    + + +
    +
    +
    +
    +
    +{#

    #} +{# #} +{#

    #} +
    +
    +

    + {{ display_msg }} +

    + +
    +
    + +
    \ No newline at end of file diff --git a/work_sell/templates/partials/inc-worksell-results.html b/work_sell/templates/partials/inc-worksell-results.html new file mode 100644 index 0000000..e6402dd --- /dev/null +++ b/work_sell/templates/partials/inc-worksell-results.html @@ -0,0 +1,20 @@ +{% load sass_tags %} + + + +
    +
    + {% for work in worksells %} + {#
    #} + {% include 'partials/inc-worksell_card.html' %} + {#
    #} + {% endfor %} +
    +
    + + +
    +
    + {% include 'partials/ajax_pagination.html' %} +
    +
    \ No newline at end of file diff --git a/work_sell/templates/partials/inc-worksell_card.html b/work_sell/templates/partials/inc-worksell_card.html new file mode 100644 index 0000000..ed3d85c --- /dev/null +++ b/work_sell/templates/partials/inc-worksell_card.html @@ -0,0 +1,19 @@ +{% load staticfiles %} +{% load thumbnail %} +{#/static/sass/elements/worksell_card.sass - стиль карточки отдельно#} + \ No newline at end of file diff --git a/work_sell/templates/worksells_list.html b/work_sell/templates/trash/worksells_list.html similarity index 100% rename from work_sell/templates/worksells_list.html rename to work_sell/templates/trash/worksells_list.html diff --git a/work_sell/templates/worksell_filter.html b/work_sell/templates/worksell_filter.html new file mode 100644 index 0000000..d2f0925 --- /dev/null +++ b/work_sell/templates/worksell_filter.html @@ -0,0 +1,39 @@ +{% extends 'partials/_base.html' %} +{% load sass_tags %} +{% load static %} +{% block personal_css %} + + + +{% endblock %} + +{% block content %} +
    +
    +
    +

    + Поиск готовых проектов +

    + +
    +
    +
    +
    +
    +
    + {% include 'partials/inc-worksell-filter.html' %} +
    +
    + +
    + {% include 'partials/inc-worksell-results.html' %} +
    +
    +
    +
    +{% endblock %} + +{% block personal_js %} + + +{% endblock %} \ No newline at end of file diff --git a/work_sell/urls.py b/work_sell/urls.py index 0d9a947..8736eb8 100644 --- a/work_sell/urls.py +++ b/work_sell/urls.py @@ -17,7 +17,7 @@ from .views import ( app_name = 'work_sell' urlpatterns = [ - urls.url(r'^$', WorkSellFilterView.as_view(), name='list'), + urls.url(r'^$', WorkSellFilterView.as_view(), name='filter'), urls.url(r'^create/$', WorkSellCreateView.as_view(), name='create'), urls.url(r'^upload/$', UploadView.as_view(), name='upload'), urls.url(r'^(?P\d+)/edit/$', WorkSellUpdateView.as_view(), name='edit'), diff --git a/work_sell/views.py b/work_sell/views.py index 6d74670..88ebd5f 100644 --- a/work_sell/views.py +++ b/work_sell/views.py @@ -27,7 +27,9 @@ from .models import WorkSell, Picture, WorkSellPhoto, WorkSellPhoto from .forms import WorkSellForm, WorkSellFilterForm, ContractorWorkSellTrashForm from .serialize import serialize from .response import JSONResponse, response_mimetype - +from specializations.models import Specialization +from common.models import Location +from archilance import util class PictureCreateView(CreateView): model = Picture @@ -74,62 +76,96 @@ class WorkSellsView(ListView): class WorkSellFilterView(BaseMixin, View): - template_name = 'worksells_list.html' - form_class = WorkSellFilterForm - - def get(self, request, *args, **kwargs): - form = self.form_class(request.GET, request=request) - context = self.get_context_data(**_.merge({}, request.GET, kwargs)) - work_sells = WorkSell.objects - if form.is_valid(): - keywords = form.cleaned_data.get('keywords') - specialization = form.cleaned_data.get('specialization') - building_classification = form.cleaned_data.get('building_classification') - construction_type = form.cleaned_data.get('construction_type') - location = form.cleaned_data.get('location') - - if keywords: - keywords = tuple(filter(None, re.split(r'\s|,|;', keywords))) - - for k in keywords: - work_sells = work_sells.filter(Q(name__icontains=k) | Q(description__icontains=k)) - - if specialization: - work_sells = work_sells.filter( - specialization__lft__gte=specialization.lft, - specialization__rght__lte=specialization.rght, - ) - - if building_classification: - work_sells = work_sells.filter(building_classification=building_classification) - - if construction_type: - work_sells = work_sells.filter(construction_type=construction_type) - - if location: - work_sells = work_sells.filter( - location__lft__gte=location.lft, - location__rght__lte=location.rght, - ) - - paginator = Paginator(work_sells.all(), settings.PAGE_SIZE) - page = request.GET.get('page') - + template_name = 'worksell_filter.html' + # form_class = WorkSellFilterForm + include_template = 'partials/inc-worksell-results.html' + PROJECT_ORDER_CHOICES = ( # "Упорядочить по"... + ('name', 'названию'), + ('budget', 'цене'), + ) + + def set_filter(self, objects, request_data): + specialization = request_data.get('specialization') + keywords = request_data.get('keywords') + building_classification = request_data.get('building_classification') + construction_type = request_data.get('construction_type') + location = request_data.get('location') + el_format = request_data.get('el_format') + + if keywords: + keywords = tuple(filter(None, re.split(r'\s|,|;', keywords))) + + for k in keywords: + objects = objects.filter(Q(name__icontains=k.lower()) | Q(description__icontains=k.lower())) + + if specialization: + query = util.build_query(specialization, Specialization, + 'specializations__lft__gte', + 'specializations__rght__lte') + objects = objects.filter(query) + + if building_classification: + query = util.build_query(building_classification, BuildingClassfication, + 'building_classification__lft__gte', + 'building_classification__rght__lte') + objects = objects.filter(query) + # + if construction_type: + objects = objects.filter(construction_type__in= + tuple(filter(None, re.split(r'\s|,|;', construction_type)))) + if location: + query = util.build_query(location, Location, + 'location__lft__gte', + 'location__rght__lte') + objects = objects.filter(query) + + if el_format: + objects = objects.exclude(el_format=None) + + return objects + + def sort_by(self, objects, order_by): + if not order_by: + return objects + return objects.order_by(order_by) + + def pagination(self, objects, page): + paginator = Paginator(objects, settings.PAGE_SIZE) try: - work_sells = paginator.page(page) + objects = paginator.page(page) except PageNotAnInteger: - work_sells = paginator.page(1) + objects = paginator.page(1) except EmptyPage: - work_sells = paginator.page(paginator.num_pages) + objects = paginator.page(paginator.num_pages) + return objects + + def get_context(self, request): + context = request.dict() + worksells = WorkSell.objects.all() + worksells = self.set_filter(worksells, request) + num_results = worksells.count() + worksells = self.sort_by(worksells, request.get("order_by")) + worksells = self.pagination(worksells, request.get("page")) + + has_additional_fields = bool(context.get("building_classification") or context.get( + "construction_type") or context.get("location") or context.get("cro")) + display_msg = 'Найдено %s проектов' % num_results if num_results > 0 else 'Ничего не найдено' context.update({ - 'form': form, - 'work_sells': work_sells, + 'choices': self.PROJECT_ORDER_CHOICES, + 'worksells': worksells, 'is_paginated': True, - 'page_obj': work_sells, + 'display_msg': display_msg, + 'page_obj': worksells, + 'has_additional_fields': has_additional_fields }) + return context - return render(request, self.template_name, context) + def get(self, request): + return render(request, self.template_name, self.get_context(request.GET)) + + def post(self, request): + return render(request, self.include_template, self.get_context(request.POST)) class WorkSellDetail(DetailView): @@ -276,7 +312,7 @@ class WorkSellDeleteView(DeleteView): template_name = 'worksell_delete.html' def get_success_url(self): - return reverse('work_sell:list') + return reverse('work_sell:filter') class ContractorWorkSellTrashView(View):