From 278ee2b207eba3a8b4cb07e47e044bed1727a492 Mon Sep 17 00:00:00 2001 From: booblegum Date: Tue, 27 Dec 2016 17:38:43 +0300 Subject: [PATCH] =?UTF-8?q?PR-58=20=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Страница поиска Исполнителей переделана на ajax Изменены внутренние инструменты стараницы поиска Заказов --- archilance/util.py | 24 + assets/js/build/contractor_filter.js | 228 +++ assets/js/build/create_project.js | 154 +- assets/js/build/create_worksell.js | 38 +- assets/js/build/customer_profile.js | 39 +- assets/js/build/home_page.js | 4 +- assets/js/build/init_contractor_filter.js | 1443 +++++++++++++++++ assets/js/build/init_create_worksell.js | 256 +-- .../js/build/init_customer_project_create.js | 257 +-- assets/js/build/project_filter.js | 195 +++ assets/js/build/user_profile_edit.js | 4 +- assets/js/src/contractor_filter.js | 22 + assets/js/src/init_contractor_filter.js | 64 + assets/js/src/project_filter.js | 20 + assets/js/src/seeds/ajax_set_filter.js | 49 + assets/js/src/seeds/filter_toggle.js | 20 + assets/sass/components/custom-components.sass | 6 +- assets/sass/old_main.sass | 76 +- projects/static/css/project_filter.css | 2 +- .../partials/inc-projects-filter.html | 6 +- projects/templates/project_filter.html | 2 +- projects/views.py | 50 +- templates/partials/ajax_pagination.html | 19 +- users/templates/contractor_filter.html | 539 +----- .../partials/inc-contractors-filter.html | 154 ++ .../partials/inc-contractors-results.html | 196 +++ .../partials/inc-contractors-sort_by.html | 0 users/templates/trash/contractor_filter.html | 521 ++++++ users/views.py | 517 ++++-- webpack.config.js | 7 +- 30 files changed, 3767 insertions(+), 1145 deletions(-) create mode 100644 assets/js/build/contractor_filter.js create mode 100644 assets/js/build/init_contractor_filter.js create mode 100644 assets/js/build/project_filter.js create mode 100644 assets/js/src/contractor_filter.js create mode 100644 assets/js/src/init_contractor_filter.js create mode 100644 assets/js/src/project_filter.js create mode 100644 assets/js/src/seeds/ajax_set_filter.js create mode 100644 assets/js/src/seeds/filter_toggle.js create mode 100644 users/templates/partials/inc-contractors-filter.html create mode 100644 users/templates/partials/inc-contractors-results.html create mode 100644 users/templates/partials/inc-contractors-sort_by.html create mode 100644 users/templates/trash/contractor_filter.html diff --git a/archilance/util.py b/archilance/util.py index a673c07..eb5a803 100644 --- a/archilance/util.py +++ b/archilance/util.py @@ -2,12 +2,14 @@ import datetime from pprint import pprint import natsort +import re import pydash as _; from django.core import validators from django.core.exceptions import ObjectDoesNotExist from django.core.files.storage import FileSystemStorage from django.shortcuts import _get_queryset from django.utils import timezone +from django.db.models import Q _.map = _.map_; _.filter = _.filter_ @@ -175,3 +177,25 @@ class ASCIIFileSystemStorage(FileSystemStorage): tr = {ord(a): ord(b) for a, b in zip(*symbols)} name = name.translate(tr) return super().get_valid_name(name) + + +def build_query(id_str, _class, *args): + """ + Возвращает QuerySet для строки id-ников по заданным args (см. примеры вызова - там понятнее) + :param id_str: 'id1, id2, ...idn' + :param _class: model + :param args: + :return: queryset + """ + query = Q() + id_list = tuple(filter(None, re.split(r'\s|,|;', id_str))) + for id in id_list: + obj = _class.objects.get(id=id) + try: + kwargs = dict(zip(args, (obj.lft, obj.rght))) + except AttributeError: + kwargs = {args[0]: obj.id} + # print("kwargs = ", type(kwargs)) + query |= Q(**kwargs) + + return query \ No newline at end of file diff --git a/assets/js/build/contractor_filter.js b/assets/js/build/contractor_filter.js new file mode 100644 index 0000000..a5afc1c --- /dev/null +++ b/assets/js/build/contractor_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 = $('#contractorsBlock'); + + (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'), $('#contractorsBlock')); + }); + } + + exports.filterToggleInit = filterToggleInit; + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/assets/js/build/create_project.js b/assets/js/build/create_project.js index dec3dd1..d3122f3 100644 --- a/assets/js/build/create_project.js +++ b/assets/js/build/create_project.js @@ -46,23 +46,23 @@ 'use strict'; - var _file_upload = __webpack_require__(1); + var _file_upload = __webpack_require__(5); - var _extended_field = __webpack_require__(3); + var _extended_field = __webpack_require__(2); - var _custom_check = __webpack_require__(4); + var _custom_check = __webpack_require__(1); - var _read_more = __webpack_require__(5); + var _read_more = __webpack_require__(7); - var _only_one_checkbox = __webpack_require__(6); + var _only_one_checkbox = __webpack_require__(8); - var _popups = __webpack_require__(7); + var _popups = __webpack_require__(9); - var _scroll_on_required = __webpack_require__(8); + var _scroll_on_required = __webpack_require__(10); - var _ajax_registration = __webpack_require__(9); + var _ajax_registration = __webpack_require__(11); - var _test_seeds = __webpack_require__(10); + var _test_seeds = __webpack_require__(12); function showHideRealry() { var check = $('#checkbox-sb-realty'); @@ -91,6 +91,67 @@ /***/ }, /* 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 */, +/* 4 */, +/* 5 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -100,7 +161,7 @@ }); exports.fileUploadInit = undefined; - var _utils = __webpack_require__(2); + var _utils = __webpack_require__(6); function fileUploadInit() { var $fileUploadContainer = $('#fileUploadContainer'); @@ -138,7 +199,7 @@ exports.fileUploadInit = fileUploadInit; /***/ }, -/* 2 */ +/* 6 */ /***/ function(module, exports) { 'use strict'; @@ -182,66 +243,7 @@ exports.getCookie = getCookie; /***/ }, -/* 3 */ -/***/ 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; - -/***/ }, -/* 4 */ -/***/ 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; - -/***/ }, -/* 5 */ +/* 7 */ /***/ function(module, exports) { "use strict"; @@ -267,7 +269,7 @@ exports.readMoreInit = readMoreInit; /***/ }, -/* 6 */ +/* 8 */ /***/ function(module, exports) { "use strict"; @@ -298,7 +300,7 @@ exports.onlyOneCheckboxInit = onlyOneCheckboxInit; /***/ }, -/* 7 */ +/* 9 */ /***/ function(module, exports) { 'use strict'; @@ -351,7 +353,7 @@ exports.addMessage = addMessage; /***/ }, -/* 8 */ +/* 10 */ /***/ function(module, exports) { 'use strict'; @@ -371,7 +373,7 @@ exports.scrollOnRequiredInit = scrollOnRequiredInit; /***/ }, -/* 9 */ +/* 11 */ /***/ function(module, exports) { 'use strict'; @@ -469,7 +471,7 @@ exports.ajaxRegistrationInit = ajaxRegistrationInit; /***/ }, -/* 10 */ +/* 12 */ /***/ function(module, exports) { "use strict"; diff --git a/assets/js/build/create_worksell.js b/assets/js/build/create_worksell.js index 24e8a41..d8f36c3 100644 --- a/assets/js/build/create_worksell.js +++ b/assets/js/build/create_worksell.js @@ -46,15 +46,15 @@ 'use strict'; - var _image_upload = __webpack_require__(11); + var _image_upload = __webpack_require__(13); - var _scroll_on_required = __webpack_require__(8); + var _scroll_on_required = __webpack_require__(10); - var _popups = __webpack_require__(7); + var _popups = __webpack_require__(9); - var _ajax_registration = __webpack_require__(9); + var _ajax_registration = __webpack_require__(11); - var _ajax_send_form_data = __webpack_require__(12); + var _ajax_send_form_data = __webpack_require__(14); $(function () { (0, _image_upload.imageUploadInit)(); @@ -68,7 +68,11 @@ /***/ }, /* 1 */, -/* 2 */ +/* 2 */, +/* 3 */, +/* 4 */, +/* 5 */, +/* 6 */ /***/ function(module, exports) { 'use strict'; @@ -112,11 +116,9 @@ exports.getCookie = getCookie; /***/ }, -/* 3 */, -/* 4 */, -/* 5 */, -/* 6 */, -/* 7 */ +/* 7 */, +/* 8 */, +/* 9 */ /***/ function(module, exports) { 'use strict'; @@ -169,7 +171,7 @@ exports.addMessage = addMessage; /***/ }, -/* 8 */ +/* 10 */ /***/ function(module, exports) { 'use strict'; @@ -189,7 +191,7 @@ exports.scrollOnRequiredInit = scrollOnRequiredInit; /***/ }, -/* 9 */ +/* 11 */ /***/ function(module, exports) { 'use strict'; @@ -287,8 +289,8 @@ exports.ajaxRegistrationInit = ajaxRegistrationInit; /***/ }, -/* 10 */, -/* 11 */ +/* 12 */, +/* 13 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -298,7 +300,7 @@ }); exports.imageUploadInit = undefined; - var _utils = __webpack_require__(2); + var _utils = __webpack_require__(6); // function previewImg() { // let $fileUploadWidgets = $('.file-upload-widget'); @@ -366,7 +368,7 @@ // export {imageUploadInit, previewImg} /***/ }, -/* 12 */ +/* 14 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -376,7 +378,7 @@ }); exports.sendFormData = undefined; - var _utils = __webpack_require__(2); + var _utils = __webpack_require__(6); function sendFormData(e) { e.preventDefault(); diff --git a/assets/js/build/customer_profile.js b/assets/js/build/customer_profile.js index 0af6a44..814f344 100644 --- a/assets/js/build/customer_profile.js +++ b/assets/js/build/customer_profile.js @@ -40,17 +40,18 @@ /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ -/******/ ([ -/* 0 */ +/******/ ({ + +/***/ 0: /***/ function(module, exports, __webpack_require__) { 'use strict'; - var _show_hide = __webpack_require__(13); + var _show_hide = __webpack_require__(15); - var _bootstrap_tabs = __webpack_require__(14); + var _bootstrap_tabs = __webpack_require__(16); - var _sort_by = __webpack_require__(15); + var _sort_by = __webpack_require__(17); $(function () { (0, _bootstrap_tabs.restoreTab)(); @@ -61,8 +62,8 @@ }); /***/ }, -/* 1 */, -/* 2 */ + +/***/ 6: /***/ function(module, exports) { 'use strict'; @@ -106,17 +107,8 @@ exports.getCookie = getCookie; /***/ }, -/* 3 */, -/* 4 */, -/* 5 */, -/* 6 */, -/* 7 */, -/* 8 */, -/* 9 */, -/* 10 */, -/* 11 */, -/* 12 */, -/* 13 */ + +/***/ 15: /***/ function(module, exports) { "use strict"; @@ -132,7 +124,8 @@ exports.toggler = toggler; /***/ }, -/* 14 */ + +/***/ 16: /***/ function(module, exports) { "use strict"; @@ -167,7 +160,8 @@ exports.restoreTab = restoreTab; /***/ }, -/* 15 */ + +/***/ 17: /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -177,7 +171,7 @@ }); exports.sortRealtyBy = undefined; - var _utils = __webpack_require__(2); + var _utils = __webpack_require__(6); function sortRealtyBy(data, container_id) { console.log("sort_by = ", data); @@ -200,4 +194,5 @@ exports.sortRealtyBy = sortRealtyBy; /***/ } -/******/ ]); \ No newline at end of file + +/******/ }); \ No newline at end of file diff --git a/assets/js/build/home_page.js b/assets/js/build/home_page.js index 7801825..74f6e8d 100644 --- a/assets/js/build/home_page.js +++ b/assets/js/build/home_page.js @@ -47,7 +47,7 @@ 'use strict'; - var _popupYoutube = __webpack_require__(16); + var _popupYoutube = __webpack_require__(18); $(function () { (0, _popupYoutube.popupYoutubeInit)(); @@ -55,7 +55,7 @@ /***/ }, -/***/ 16: +/***/ 18: /***/ function(module, exports) { 'use strict'; diff --git a/assets/js/build/init_contractor_filter.js b/assets/js/build/init_contractor_filter.js new file mode 100644 index 0000000..d595990 --- /dev/null +++ b/assets/js/build/init_contractor_filter.js @@ -0,0 +1,1443 @@ +/******/ (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, hasEditableContainer: true, visible: 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(); + + obj.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
    \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/init_create_worksell.js b/assets/js/build/init_create_worksell.js index d44f06a..8d35d9b 100644 --- a/assets/js/build/init_create_worksell.js +++ b/assets/js/build/init_create_worksell.js @@ -46,27 +46,27 @@ 'use strict'; - var _SelectedContainer = __webpack_require__(17); + var _SelectedContainer = __webpack_require__(19); var _SelectedContainer2 = _interopRequireDefault(_SelectedContainer); - var _SelectedContainerCreate = __webpack_require__(21); + var _SelectedContainerCreate = __webpack_require__(26); var _SelectedContainerCreate2 = _interopRequireDefault(_SelectedContainerCreate); - var _NoTreeSelect = __webpack_require__(22); + var _NoTreeSelect = __webpack_require__(23); var _NoTreeSelect2 = _interopRequireDefault(_NoTreeSelect); - var _TreeSelect = __webpack_require__(24); + var _TreeSelect = __webpack_require__(25); var _TreeSelect2 = _interopRequireDefault(_TreeSelect); - var _SingleTreeSelect = __webpack_require__(25); + var _SingleTreeSelect = __webpack_require__(27); var _SingleTreeSelect2 = _interopRequireDefault(_SingleTreeSelect); - var _SelectOrCreate = __webpack_require__(26); + var _SelectOrCreate = __webpack_require__(28); var _SelectOrCreate2 = _interopRequireDefault(_SelectOrCreate); @@ -183,7 +183,9 @@ /* 14 */, /* 15 */, /* 16 */, -/* 17 */ +/* 17 */, +/* 18 */, +/* 19 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -198,15 +200,15 @@ var _desc, _value, _class; // ` - var _DataTree = __webpack_require__(18); + var _DataTree = __webpack_require__(20); var _DataTree2 = _interopRequireDefault(_DataTree); - var _NoTreeData = __webpack_require__(19); + var _NoTreeData = __webpack_require__(21); var _NoTreeData2 = _interopRequireDefault(_NoTreeData); - var _decorators = __webpack_require__(20); + var _decorators = __webpack_require__(22); var _decorators2 = _interopRequireDefault(_decorators); @@ -437,7 +439,7 @@ exports.default = SelectedContainer; /***/ }, -/* 18 */ +/* 20 */ /***/ function(module, exports) { "use strict"; @@ -592,7 +594,7 @@ exports.default = DataTree; /***/ }, -/* 19 */ +/* 21 */ /***/ function(module, exports) { "use strict"; @@ -648,7 +650,7 @@ exports.default = NoTreeData; /***/ }, -/* 20 */ +/* 22 */ /***/ function(module, exports) { "use strict"; @@ -732,108 +734,7 @@ // export {onBind}; /***/ }, -/* 21 */ -/***/ 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 _desc, _value, _class; - - var _SelectedContainer2 = __webpack_require__(17); - - var _SelectedContainer3 = _interopRequireDefault(_SelectedContainer2); - - var _decorators = __webpack_require__(20); - - 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 _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; } - - 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; - } - - /** - * Контэйнер - позволяющий принимать/отправлять новый объект для создания - */ - //TODO: попробовать реализовать как Mixin - var SelectedContainerCreate = (_class = function (_SelectedContainer) { - _inherits(SelectedContainerCreate, _SelectedContainer); - - function SelectedContainerCreate() { - _classCallCheck(this, SelectedContainerCreate); - - return _possibleConstructorReturn(this, (SelectedContainerCreate.__proto__ || Object.getPrototypeOf(SelectedContainerCreate)).apply(this, arguments)); - } - - _createClass(SelectedContainerCreate, [{ - key: 'add', - value: function add(_id, max_len) { - console.log("_id = ", _id); - var self = this; - if (_id.text) { - this._removeById(this.elements_id[0]); - this.elements_id = [0]; - this.$input_id = this.$self.find('input[type="hidden"].-id'); - this.$input_id.val(""); - this.$input_name = this.$self.find('input[type="hidden"].-name'); - this.$input_name.val(_id.text); - this.$self.append(_SelectedContainer3.default.getTemplate("", _id.text, 0)); - 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(); - return; - } - _get(SelectedContainerCreate.prototype.__proto__ || Object.getPrototypeOf(SelectedContainerCreate.prototype), 'add', this).call(this, _id, max_len); - } - }]); - - return SelectedContainerCreate; - }(_SelectedContainer3.default), (_applyDecoratedDescriptor(_class.prototype, 'add', [_decorators2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'add'), _class.prototype)), _class); - exports.default = SelectedContainerCreate; - -/***/ }, -/* 22 */ +/* 23 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -847,9 +748,9 @@ 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__(23); + var _AbsBaseSelect2 = __webpack_require__(24); - var _NoTreeData = __webpack_require__(19); + var _NoTreeData = __webpack_require__(21); var _NoTreeData2 = _interopRequireDefault(_NoTreeData); @@ -910,7 +811,7 @@ exports.default = NoTreeSelect; /***/ }, -/* 23 */ +/* 24 */ /***/ function(module, exports) { "use strict"; @@ -1461,7 +1362,7 @@ exports.AbsBaseSelect = AbsBaseSelect; /***/ }, -/* 24 */ +/* 25 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -1475,9 +1376,9 @@ 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__(23); + var _AbsBaseSelect2 = __webpack_require__(24); - var _DataTree = __webpack_require__(18); + var _DataTree = __webpack_require__(20); var _DataTree2 = _interopRequireDefault(_DataTree); @@ -1586,7 +1487,108 @@ exports.default = TreeSelect; /***/ }, -/* 25 */ +/* 26 */ +/***/ 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 _desc, _value, _class; + + var _SelectedContainer2 = __webpack_require__(19); + + var _SelectedContainer3 = _interopRequireDefault(_SelectedContainer2); + + 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 _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; } + + 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; + } + + /** + * Контэйнер - позволяющий принимать/отправлять новый объект для создания + */ + //TODO: попробовать реализовать как Mixin + var SelectedContainerCreate = (_class = function (_SelectedContainer) { + _inherits(SelectedContainerCreate, _SelectedContainer); + + function SelectedContainerCreate() { + _classCallCheck(this, SelectedContainerCreate); + + return _possibleConstructorReturn(this, (SelectedContainerCreate.__proto__ || Object.getPrototypeOf(SelectedContainerCreate)).apply(this, arguments)); + } + + _createClass(SelectedContainerCreate, [{ + key: 'add', + value: function add(_id, max_len) { + console.log("_id = ", _id); + var self = this; + if (_id.text) { + this._removeById(this.elements_id[0]); + this.elements_id = [0]; + this.$input_id = this.$self.find('input[type="hidden"].-id'); + this.$input_id.val(""); + this.$input_name = this.$self.find('input[type="hidden"].-name'); + this.$input_name.val(_id.text); + this.$self.append(_SelectedContainer3.default.getTemplate("", _id.text, 0)); + 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(); + return; + } + _get(SelectedContainerCreate.prototype.__proto__ || Object.getPrototypeOf(SelectedContainerCreate.prototype), 'add', this).call(this, _id, max_len); + } + }]); + + return SelectedContainerCreate; + }(_SelectedContainer3.default), (_applyDecoratedDescriptor(_class.prototype, 'add', [_decorators2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'add'), _class.prototype)), _class); + exports.default = SelectedContainerCreate; + +/***/ }, +/* 27 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -1598,9 +1600,9 @@ 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 _AbsBaseSelect = __webpack_require__(23); + var _AbsBaseSelect = __webpack_require__(24); - var _TreeSelect2 = __webpack_require__(24); + var _TreeSelect2 = __webpack_require__(25); var _TreeSelect3 = _interopRequireDefault(_TreeSelect2); @@ -1681,7 +1683,7 @@ exports.default = SingleTreeSelect; /***/ }, -/* 26 */ +/* 28 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -1695,9 +1697,9 @@ 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__(23); + var _AbsBaseSelect2 = __webpack_require__(24); - var _NoTreeData = __webpack_require__(19); + var _NoTreeData = __webpack_require__(21); var _NoTreeData2 = _interopRequireDefault(_NoTreeData); diff --git a/assets/js/build/init_customer_project_create.js b/assets/js/build/init_customer_project_create.js index 7ebba90..fba34b2 100644 --- a/assets/js/build/init_customer_project_create.js +++ b/assets/js/build/init_customer_project_create.js @@ -46,27 +46,27 @@ 'use strict'; - var _SelectedContainer = __webpack_require__(17); + var _SelectedContainer = __webpack_require__(19); var _SelectedContainer2 = _interopRequireDefault(_SelectedContainer); - var _SelectedContainerCreate = __webpack_require__(21); + var _SelectedContainerCreate = __webpack_require__(26); var _SelectedContainerCreate2 = _interopRequireDefault(_SelectedContainerCreate); - var _NoTreeSelect = __webpack_require__(22); + var _NoTreeSelect = __webpack_require__(23); var _NoTreeSelect2 = _interopRequireDefault(_NoTreeSelect); - var _TreeSelect = __webpack_require__(24); + var _TreeSelect = __webpack_require__(25); var _TreeSelect2 = _interopRequireDefault(_TreeSelect); - var _SingleTreeSelect = __webpack_require__(25); + var _SingleTreeSelect = __webpack_require__(27); var _SingleTreeSelect2 = _interopRequireDefault(_SingleTreeSelect); - var _SelectOrCreate = __webpack_require__(26); + var _SelectOrCreate = __webpack_require__(28); var _SelectOrCreate2 = _interopRequireDefault(_SelectOrCreate); @@ -179,7 +179,6 @@ } }); select_realty.on("add", function (args) { - console.log("realty add"); //TODO: Костыли!!! $('#checkbox-sb-realty').prop("checked", true); sb_realty.show(); @@ -227,7 +226,9 @@ /* 14 */, /* 15 */, /* 16 */, -/* 17 */ +/* 17 */, +/* 18 */, +/* 19 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -242,15 +243,15 @@ var _desc, _value, _class; // ` - var _DataTree = __webpack_require__(18); + var _DataTree = __webpack_require__(20); var _DataTree2 = _interopRequireDefault(_DataTree); - var _NoTreeData = __webpack_require__(19); + var _NoTreeData = __webpack_require__(21); var _NoTreeData2 = _interopRequireDefault(_NoTreeData); - var _decorators = __webpack_require__(20); + var _decorators = __webpack_require__(22); var _decorators2 = _interopRequireDefault(_decorators); @@ -481,7 +482,7 @@ exports.default = SelectedContainer; /***/ }, -/* 18 */ +/* 20 */ /***/ function(module, exports) { "use strict"; @@ -636,7 +637,7 @@ exports.default = DataTree; /***/ }, -/* 19 */ +/* 21 */ /***/ function(module, exports) { "use strict"; @@ -692,7 +693,7 @@ exports.default = NoTreeData; /***/ }, -/* 20 */ +/* 22 */ /***/ function(module, exports) { "use strict"; @@ -776,108 +777,7 @@ // export {onBind}; /***/ }, -/* 21 */ -/***/ 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 _desc, _value, _class; - - var _SelectedContainer2 = __webpack_require__(17); - - var _SelectedContainer3 = _interopRequireDefault(_SelectedContainer2); - - var _decorators = __webpack_require__(20); - - 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 _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; } - - 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; - } - - /** - * Контэйнер - позволяющий принимать/отправлять новый объект для создания - */ - //TODO: попробовать реализовать как Mixin - var SelectedContainerCreate = (_class = function (_SelectedContainer) { - _inherits(SelectedContainerCreate, _SelectedContainer); - - function SelectedContainerCreate() { - _classCallCheck(this, SelectedContainerCreate); - - return _possibleConstructorReturn(this, (SelectedContainerCreate.__proto__ || Object.getPrototypeOf(SelectedContainerCreate)).apply(this, arguments)); - } - - _createClass(SelectedContainerCreate, [{ - key: 'add', - value: function add(_id, max_len) { - console.log("_id = ", _id); - var self = this; - if (_id.text) { - this._removeById(this.elements_id[0]); - this.elements_id = [0]; - this.$input_id = this.$self.find('input[type="hidden"].-id'); - this.$input_id.val(""); - this.$input_name = this.$self.find('input[type="hidden"].-name'); - this.$input_name.val(_id.text); - this.$self.append(_SelectedContainer3.default.getTemplate("", _id.text, 0)); - 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(); - return; - } - _get(SelectedContainerCreate.prototype.__proto__ || Object.getPrototypeOf(SelectedContainerCreate.prototype), 'add', this).call(this, _id, max_len); - } - }]); - - return SelectedContainerCreate; - }(_SelectedContainer3.default), (_applyDecoratedDescriptor(_class.prototype, 'add', [_decorators2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'add'), _class.prototype)), _class); - exports.default = SelectedContainerCreate; - -/***/ }, -/* 22 */ +/* 23 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -891,9 +791,9 @@ 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__(23); + var _AbsBaseSelect2 = __webpack_require__(24); - var _NoTreeData = __webpack_require__(19); + var _NoTreeData = __webpack_require__(21); var _NoTreeData2 = _interopRequireDefault(_NoTreeData); @@ -954,7 +854,7 @@ exports.default = NoTreeSelect; /***/ }, -/* 23 */ +/* 24 */ /***/ function(module, exports) { "use strict"; @@ -1505,7 +1405,7 @@ exports.AbsBaseSelect = AbsBaseSelect; /***/ }, -/* 24 */ +/* 25 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -1519,9 +1419,9 @@ 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__(23); + var _AbsBaseSelect2 = __webpack_require__(24); - var _DataTree = __webpack_require__(18); + var _DataTree = __webpack_require__(20); var _DataTree2 = _interopRequireDefault(_DataTree); @@ -1630,7 +1530,108 @@ exports.default = TreeSelect; /***/ }, -/* 25 */ +/* 26 */ +/***/ 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 _desc, _value, _class; + + var _SelectedContainer2 = __webpack_require__(19); + + var _SelectedContainer3 = _interopRequireDefault(_SelectedContainer2); + + 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 _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; } + + 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; + } + + /** + * Контэйнер - позволяющий принимать/отправлять новый объект для создания + */ + //TODO: попробовать реализовать как Mixin + var SelectedContainerCreate = (_class = function (_SelectedContainer) { + _inherits(SelectedContainerCreate, _SelectedContainer); + + function SelectedContainerCreate() { + _classCallCheck(this, SelectedContainerCreate); + + return _possibleConstructorReturn(this, (SelectedContainerCreate.__proto__ || Object.getPrototypeOf(SelectedContainerCreate)).apply(this, arguments)); + } + + _createClass(SelectedContainerCreate, [{ + key: 'add', + value: function add(_id, max_len) { + console.log("_id = ", _id); + var self = this; + if (_id.text) { + this._removeById(this.elements_id[0]); + this.elements_id = [0]; + this.$input_id = this.$self.find('input[type="hidden"].-id'); + this.$input_id.val(""); + this.$input_name = this.$self.find('input[type="hidden"].-name'); + this.$input_name.val(_id.text); + this.$self.append(_SelectedContainer3.default.getTemplate("", _id.text, 0)); + 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(); + return; + } + _get(SelectedContainerCreate.prototype.__proto__ || Object.getPrototypeOf(SelectedContainerCreate.prototype), 'add', this).call(this, _id, max_len); + } + }]); + + return SelectedContainerCreate; + }(_SelectedContainer3.default), (_applyDecoratedDescriptor(_class.prototype, 'add', [_decorators2.default], Object.getOwnPropertyDescriptor(_class.prototype, 'add'), _class.prototype)), _class); + exports.default = SelectedContainerCreate; + +/***/ }, +/* 27 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -1642,9 +1643,9 @@ 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 _AbsBaseSelect = __webpack_require__(23); + var _AbsBaseSelect = __webpack_require__(24); - var _TreeSelect2 = __webpack_require__(24); + var _TreeSelect2 = __webpack_require__(25); var _TreeSelect3 = _interopRequireDefault(_TreeSelect2); @@ -1725,7 +1726,7 @@ exports.default = SingleTreeSelect; /***/ }, -/* 26 */ +/* 28 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; @@ -1739,9 +1740,9 @@ 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__(23); + var _AbsBaseSelect2 = __webpack_require__(24); - var _NoTreeData = __webpack_require__(19); + var _NoTreeData = __webpack_require__(21); var _NoTreeData2 = _interopRequireDefault(_NoTreeData); diff --git a/assets/js/build/project_filter.js b/assets/js/build/project_filter.js new file mode 100644 index 0000000..3eb6917 --- /dev/null +++ b/assets/js/build/project_filter.js @@ -0,0 +1,195 @@ +/******/ (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); + + function paginateTo(pageNum) { + var $form = $('#filter-form'); + var postfix = "&page=" + pageNum; + var $container = $('#projectsBlock'); + + (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)(); + 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; + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/assets/js/build/user_profile_edit.js b/assets/js/build/user_profile_edit.js index d4fd163..1b5b545 100644 --- a/assets/js/build/user_profile_edit.js +++ b/assets/js/build/user_profile_edit.js @@ -47,7 +47,7 @@ 'use strict'; - var _avatar_upload = __webpack_require__(27); + var _avatar_upload = __webpack_require__(29); $(function () { (0, _avatar_upload.avatarUploadInit)(); @@ -55,7 +55,7 @@ /***/ }, -/***/ 27: +/***/ 29: /***/ function(module, exports) { 'use strict'; diff --git a/assets/js/src/contractor_filter.js b/assets/js/src/contractor_filter.js new file mode 100644 index 0000000..1372aae --- /dev/null +++ b/assets/js/src/contractor_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 = $('#contractorsBlock'); + + 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/js/src/init_contractor_filter.js b/assets/js/src/init_contractor_filter.js new file mode 100644 index 0000000..bd37166 --- /dev/null +++ b/assets/js/src/init_contractor_filter.js @@ -0,0 +1,64 @@ +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, hasEditableContainer: true, visible: 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 new file mode 100644 index 0000000..3b6243f --- /dev/null +++ b/assets/js/src/project_filter.js @@ -0,0 +1,20 @@ +import {customCheckInit} from './seeds/custom_check' +import {extendedFieldInit} from './seeds/extended_field' +import {sendFilterData, sendData, modUrl} from './seeds/ajax_set_filter' + +function paginateTo(pageNum) { + const $form = $('#filter-form'); + const postfix = "&page=" + pageNum; + const $container = $('#projectsBlock'); + + sendData($form, $container, pageNum); + modUrl($form, postfix); + return false; +} + +$(function () { + customCheckInit(); + extendedFieldInit(); + window.sendFilterData = sendFilterData; + window.paginateTo = paginateTo; +}); \ No newline at end of file diff --git a/assets/js/src/seeds/ajax_set_filter.js b/assets/js/src/seeds/ajax_set_filter.js new file mode 100644 index 0000000..69ad22c --- /dev/null +++ b/assets/js/src/seeds/ajax_set_filter.js @@ -0,0 +1,49 @@ +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) { + let 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); + let 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 (xhr) { + xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); + }, + success: updateResults, + error: (data) => console.log("Error", data) + }); +} + +function sendFilterData($form, $update_container) { + sendData($form, $update_container); + modUrl($form); + return false; +} + +export {sendFilterData, sendData, modUrl} \ No newline at end of file diff --git a/assets/js/src/seeds/filter_toggle.js b/assets/js/src/seeds/filter_toggle.js new file mode 100644 index 0000000..89c7826 --- /dev/null +++ b/assets/js/src/seeds/filter_toggle.js @@ -0,0 +1,20 @@ +function filterToggleInit() { + let $group = $('.btn-group.toggle'); + let $buttons = $group.find('a.btn').add('.link-sort a.btn'); + // let $input = $('input[name="party_types"]'); + + $buttons.on("click", function (e) { + e.preventDefault(); + let $target = $(e.target); + let $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'), $('#contractorsBlock')); + }) +} + +export {filterToggleInit} \ No newline at end of file diff --git a/assets/sass/components/custom-components.sass b/assets/sass/components/custom-components.sass index dc0dad9..dda3e75 100644 --- a/assets/sass/components/custom-components.sass +++ b/assets/sass/components/custom-components.sass @@ -311,7 +311,9 @@ textarea.description border-bottom-right-radius: $radius -.link-sort button +.link-sort + button, + a font-size: 14px font-family: 'Arial-MT-Regular', sans-serif color: #6b6b6b @@ -330,6 +332,8 @@ textarea.description font-weight: normal line-height: 1 -webkit-font-smoothing: antialiased + p + display: inline-block .btn-up_down width: 110px diff --git a/assets/sass/old_main.sass b/assets/sass/old_main.sass index 44c2692..55e381e 100644 --- a/assets/sass/old_main.sass +++ b/assets/sass/old_main.sass @@ -1126,27 +1126,27 @@ .sro margin: 33px 0 28px 0 - label - width: 23px - height: 23px - display: block - position: relative - float: left - margin-right: 10px - - input[type="checkbox"] - + span - position: absolute - left: 0 - top: 0 - width: 100% - height: 100% - background: url('../img/check.png') no-repeat center - background-position: 0 0 - background-size: cover - cursor: pointer - &:checked + span - background-position: 0 -23px + //label + // width: 23px + // height: 23px + // display: block + // position: relative + // float: left + // margin-right: 10px + // + //input[type="checkbox"] + // + span + // position: absolute + // left: 0 + // top: 0 + // width: 100% + // height: 100% + // background: url('../img/check.png') no-repeat center + // background-position: 0 0 + // background-size: cover + // cursor: pointer + // &:checked + span + // background-position: 0 -23px /*.sro input[type="checkbox"] { /*opacity: 0; @@ -3847,23 +3847,23 @@ &:link, &:visited color: #009DD9 - label - width: 23px - height: 23px - display: block - position: relative - - input[type="checkbox"] - + span - position: absolute - left: 0 - top: 0 - width: 100% - height: 100% - background: url('../img/check.png') no-repeat - cursor: pointer - &:checked + span - background-position: 0 -23px + //label + // width: 23px + // height: 23px + // display: block + // position: relative + // + //input[type="checkbox"] + // + span + // position: absolute + // left: 0 + // top: 0 + // width: 100% + // height: 100% + // background: url('../img/check.png') no-repeat + // cursor: pointer + // &:checked + span + // background-position: 0 -23px .text-block width: 100% diff --git a/projects/static/css/project_filter.css b/projects/static/css/project_filter.css index 58abe23..b718a80 100644 --- a/projects/static/css/project_filter.css +++ b/projects/static/css/project_filter.css @@ -9,7 +9,7 @@ body { margin: 50px 30px; } -.form-container { +.filter.form-container { padding: 50px 45px; } diff --git a/projects/templates/partials/inc-projects-filter.html b/projects/templates/partials/inc-projects-filter.html index 1c038f9..8383610 100644 --- a/projects/templates/partials/inc-projects-filter.html +++ b/projects/templates/partials/inc-projects-filter.html @@ -1,4 +1,4 @@ -
    +
    @@ -47,14 +47,14 @@
    {# $(this).closest('form').submit(); return false#} - + найти проект
    diff --git a/projects/templates/project_filter.html b/projects/templates/project_filter.html index cb23f85..938f856 100644 --- a/projects/templates/project_filter.html +++ b/projects/templates/project_filter.html @@ -34,6 +34,6 @@ {% block js_block %} {{ block.super }} - + {% endblock %} \ No newline at end of file diff --git a/projects/views.py b/projects/views.py index cb8a2e9..8cae54a 100644 --- a/projects/views.py +++ b/projects/views.py @@ -277,17 +277,6 @@ class RestoreProjectAnswerView(NoCsrfMixin, LoginRequiredMixin, BaseMixin, View) return redirect(redirect_to) -def build_query(id_str, _class, *args): - query = Q() - id_list = tuple(filter(None, re.split(r'\s|,|;', id_str))) - for id in id_list: - obj = _class.objects.get(id=id) - kwargs = dict(zip(args, (obj.lft, obj.rght))) - query |= Q(**kwargs) - - return query - - class ProjectFilterView(BaseMixin, View): template_name = 'project_filter.html' # form_class = ProjectFilterForm @@ -299,14 +288,14 @@ class ProjectFilterView(BaseMixin, View): ('views', 'просмотрам'), ) - def filter(self, projects, data): + def set_filter(self, projects, request): # print("filter data = ", data) - specialization = data.get('specialization') - keywords = data.get('keywords') - building_classification = data.get('building_classification') - construction_type = data.get('construction_type') - location = data.get('location') - cro = data.get('cro') + specialization = request.get('specialization') + keywords = request.get('keywords') + building_classification = request.get('building_classification') + construction_type = request.get('construction_type') + location = request.get('location') + cro = request.get('cro') if keywords: # print("keywords = ", keywords) @@ -316,23 +305,23 @@ class ProjectFilterView(BaseMixin, View): projects = projects.filter(Q(name__icontains=k.lower()) | Q(text__icontains=k.lower())) if specialization: - query = build_query(specialization, Specialization, - 'specialization__lft__gte', 'specialization__rght__lte') + query = util.build_query(specialization, Specialization, + 'specialization__lft__gte', 'specialization__rght__lte') projects = projects.filter(query) if building_classification: - query = build_query(building_classification, BuildingClassfication, - 'realty__building_classification__lft__gte', - 'realty__building_classification__rght__lte') + query = util.build_query(building_classification, BuildingClassfication, + 'realty__building_classification__lft__gte', + 'realty__building_classification__rght__lte') projects = projects.filter(query) if construction_type: projects = projects.filter(realty__construction_type__in= tuple(filter(None, re.split(r'\s|,|;', construction_type)))) if location: - query = build_query(location, Location, - 'realty__location__lft__gte', - 'realty__location__rght__lte') + query = util.build_query(location, Location, + 'realty__location__lft__gte', + 'realty__location__rght__lte') projects = projects.filter(query) if cro: @@ -378,7 +367,7 @@ class ProjectFilterView(BaseMixin, View): context = request.dict() projects = Project.objects.filter(state='active', order__status='created') - projects = self.filter(projects, request) + projects = self.set_filter(projects, request) num_results = projects.count() projects = self.sort_by(projects) projects = self.pagination(projects, request.get("page")) @@ -404,7 +393,6 @@ class ProjectFilterView(BaseMixin, View): class SortRealtyBy(View): - def get_context(self): print("request.POST = ", self.request.POST) user_id = self.request.POST.get('user_id') @@ -448,7 +436,8 @@ class CustomerProjectCreateView(BaseMixin, View): return render(request, self.template_name, context) def post(self, request, *args, **kwargs): - form = self.form_class(request.POST, request=request) # Passing `request.FILES` seems unnecessary here. Files are added manually below + form = self.form_class(request.POST, + request=request) # Passing `request.FILES` seems unnecessary here. Files are added manually below # print('POST = ', request.POST) form.is_valid() realty = form.cleaned_data.get('realty') @@ -700,7 +689,8 @@ class CustomerRealtyTrashView(AbcCustomerRealityChangeState): def dispatch(self, request, *args, **kwargs): if request.user.is_authenticated() and request.user.is_customer(): - num_project_in_process = Project.objects.filter(realty__id=kwargs.get('pk')).filter(order__status="process").count() + num_project_in_process = Project.objects.filter(realty__id=kwargs.get('pk')).filter( + order__status="process").count() if num_project_in_process: raise PermissionDenied('Один или более Заказ, данного Объекта, уже находятся в работе. ' diff --git a/templates/partials/ajax_pagination.html b/templates/partials/ajax_pagination.html index 67b2b34..9d70c78 100644 --- a/templates/partials/ajax_pagination.html +++ b/templates/partials/ajax_pagination.html @@ -1,3 +1,12 @@ +{# TODO: Сделать более явное определение функции paginateTo() #} +{#function paginateTo(pageNum) {#} +{# const $form = $('#filter-form');#} +{# const postfix = "&page=" + pageNum;#} +{# const $container = $('#contractorsBlock');#} +{##} +{# sendData($form, $container, pageNum);#} +{# modUrl($form, postfix);#} +{# return false;#} {% if is_paginated %} - - {% endif %} \ No newline at end of file diff --git a/users/templates/contractor_filter.html b/users/templates/contractor_filter.html index b4752f3..3b9e68d 100644 --- a/users/templates/contractor_filter.html +++ b/users/templates/contractor_filter.html @@ -1,521 +1,34 @@ -{% extends 'partials/base.html' %} - -{% load common_tags %} -{% load specializtions_tags %} -{% load thumbnail %} -{% load i18n %} +{% extends 'partials/_base.html' %} +{% load sass_tags %} +{% load static %} +{% block personal_css %} + + + + +{% endblock %} {% block content %} - {% include 'partials/modals/project_selection.html' %} - {% include 'partials/header.html' %} - - -
    -
    -
    -

    {% if display_msg %}{{ display_msg }}{% else %}Поиск исполнителей{% endif %}

    -
    - - - -
    -
    -
    - - -
    -
    {% trans 'project_stage0' %}
    -
    - -
    -
    - {{ form.work_type }} -
    -
    - - - - - - -
    -
    - -
    -
    -
    {% trans 'project_stage1' %} {{ form.specialization.errors.as_text }}
    - -
    -
    -
    {% trans 'project_stage2' %}
    - -
    -
    -
    {% trans 'project_stage3' %}
    - -
    -
    -
    {% trans 'project_stage4' %}
    - -
    - - -
    - - - - - - - - - -
    -
    -

    Расширенный поиск

    - -
    -
    -
    -
    -
    - - - - - - - - -
    -
    -
    Местоположение
    -
    - -
    -
    - -
    - -
    - -
    - -
    - -
    - - -
    - - -
    -
    Классификация здания
    -
    Вид строительства
    -
    - -
    -
    - {{ form.building_classification }} -
    - -
    - {{ form.construction_type }} -
    - -
    - -

    Требуется допуск (СРО)

    -
    -
    -
    - - - - -
    +
    +
    +
    +
    +

    Поиск Исполнителей

    - - - -
    -
    - {% for val, text in form.party_types.field.choices %} - - {% endfor %} -
    - - - -
    -
    - -
    - - - + {% include 'partials/inc-contractors-filter.html' %} + +
    +
    + {% include 'partials/inc-contractors-results.html' %}
    - - - - - {% for obj in coll %} - {% if obj|class_name == 'Team' %} - {% with team=obj %} -
    - - - - - - -
    - {% specialization_team_widget team_id=team.pk %} -
    - - -
    - {% ratings_team_widget team.pk 'restList2' %} - - -
    -
    -

    Есть допуск СРО

    -
    -
    - - - {% if TEMPLATE_DEBUG %} -
    -
    ######## Team owner #########

    Specializations: {{ team.owner.contractor_specializations.all }}

    Location: {{ team.owner.location }}

    Build. classif-s: {% for o in team.owner.orders.all %}{{ o.project.realty.building_classification }}, {% endfor %}

    Constr. types: {% for o in team.owner.orders.all %}{{ o.project.realty.construction_type }}, {% endfor %}

    CRO: {{ team.owner.cro }}

    Work types: {% for o in team.owner.orders.all %}{{ o.project.work_type }}, {% endfor %}



    ######## Team users #########

    Specializations: {% for u in team.users.all %}{{ u.contractor_specializations.all }}, {% endfor %}

    Location: {% for u in team.users.all %}{{ u.location }}, {% endfor %}

    Build. classif-s: {% for u in team.users.all %}{% for o in u.orders.all %}{{ o.project.realty.building_classification }}, {% endfor %}; {% endfor %}

    Constr. types: {% for u in team.users.all %}{% for o in u.orders.all %}{{ o.project.realty.construction_type }}, {% endfor %}; {% endfor %}

    CRO: {% for u in team.users.all %}{{ u.cro }}, {% endfor %}

    Work types: {% for u in team.users.all %}{% for o in u.orders.all %}{{ o.project.work_type }}, {% endfor %}; {% endfor %}
    -
    - {% endif %} - - -
    - {% for portf in team.portfolios.all|slice:':4' %} - - {% endfor %} -
    -
    - {% endwith %} - {% elif obj|class_name == 'User' %} - {% with contractor=obj %} -
    - - - - - - -
    - {% specialization_widget user_id=contractor.pk %} -
    - - -
    - {% ratings_widget contractor.pk 'restList2' %} - - {% if contractor.cro %} -
    -
    -

    Есть допуск СРО

    -
    - {% endif %} -
    - - - {% if TEMPLATE_DEBUG %} -
    -
    Specializations: {{ contractor.contractor_specializations.all }}

    Location: {{ contractor.location }}

    Build. classif-s: {% for o in contractor.orders.all %}{{ o.project.realty.building_classification }}, {% endfor %}

    Constr. types: {% for o in contractor.orders.all %}{{ o.project.realty.construction_type }}, {% endfor %}

    CRO: {{ contractor.cro }}

    Work types: {% for o in contractor.orders.all %}{{ o.project.work_type }}, {% endfor %}
    -
    - {% endif %} - -
    - {% for portf in contractor.portfolios.all|slice:':4' %} - - {% endfor %} -
    -
    - {% endwith %} - {% endif %} - {% endfor %} - - -
    - {% include 'partials/pagination.html' %}
    - - - {% include 'partials/footer.html' %} -
    -
    -{% endblock %} -{% block js_block %} - +
    +
    {% endblock %} + +{% block personal_js %} + + +{% endblock %} \ No newline at end of file diff --git a/users/templates/partials/inc-contractors-filter.html b/users/templates/partials/inc-contractors-filter.html new file mode 100644 index 0000000..87fc9af --- /dev/null +++ b/users/templates/partials/inc-contractors-filter.html @@ -0,0 +1,154 @@ +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    + +
    +
    +
    +
    +
    + + + + +
    +
    +
    + Расширенные поля + +
    +
    +
    +
    + +
    +
    +
    +
    +
    + Опыт работы исполнителей по классификации зданий и виду строительства +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    + +
    +
    +
    +
    +   +
    +
    +
    +
    +
    + С наличием СРО(Юр.лицо) + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    + + +

    + {{ display_msg }} +

    + +
    diff --git a/users/templates/partials/inc-contractors-results.html b/users/templates/partials/inc-contractors-results.html new file mode 100644 index 0000000..ffe292d --- /dev/null +++ b/users/templates/partials/inc-contractors-results.html @@ -0,0 +1,196 @@ +{% load common_tags %} +{% load specializtions_tags %} +{% load thumbnail %} +{% load i18n %} + + + +{% for object in objects %} + {% if object|class_name == 'Team' %} + {% with team=object %} +
    + + + + + + +
    + {% specialization_team_widget team_id=team.pk %} +
    + + +
    + {% ratings_team_widget team.pk 'restList2' %} + + +
    +
    +

    Есть допуск СРО

    +
    +
    +
    + {% for portf in team.portfolios.all|slice:':4' %} + + {% endfor %} +
    +
    + {% endwith %} + {% elif object|class_name == 'User' %} + {% with contractor=object %} +
    + + + + + + +
    + {% specialization_widget user_id=contractor.pk %} +
    + + +
    + {% ratings_widget contractor.pk 'restList2' %} + + {% if contractor.cro %} +
    +
    +

    Есть допуск СРО

    +
    + {% endif %} +
    +
    + {% for portf in contractor.portfolios.all|slice:':4' %} + + {% endfor %} +
    +
    + {% endwith %} + {% endif %} +{% endfor %} +
    +
    + {% include 'partials/ajax_pagination.html' %} +
    +
    \ No newline at end of file diff --git a/users/templates/partials/inc-contractors-sort_by.html b/users/templates/partials/inc-contractors-sort_by.html new file mode 100644 index 0000000..e69de29 diff --git a/users/templates/trash/contractor_filter.html b/users/templates/trash/contractor_filter.html new file mode 100644 index 0000000..b4752f3 --- /dev/null +++ b/users/templates/trash/contractor_filter.html @@ -0,0 +1,521 @@ +{% extends 'partials/base.html' %} + +{% load common_tags %} +{% load specializtions_tags %} +{% load thumbnail %} +{% load i18n %} + +{% block content %} + {% include 'partials/modals/project_selection.html' %} + {% include 'partials/header.html' %} + + +
    +
    +
    +

    {% if display_msg %}{{ display_msg }}{% else %}Поиск исполнителей{% endif %}

    +
    + + +
    +
    +
    +
    + + +
    +
    {% trans 'project_stage0' %}
    +
    + +
    +
    + {{ form.work_type }} +
    +
    + + + + + + +
    +
    + +
    +
    +
    {% trans 'project_stage1' %} {{ form.specialization.errors.as_text }}
    + +
    +
    +
    {% trans 'project_stage2' %}
    + +
    +
    +
    {% trans 'project_stage3' %}
    + +
    +
    +
    {% trans 'project_stage4' %}
    + +
    + + +
    + + + + + + + + + +
    +
    +

    Расширенный поиск

    + +
    +
    +
    +
    +
    + + + + + + + + +
    +
    +
    Местоположение
    +
    + +
    +
    + +
    + +
    + +
    + +
    + +
    + + +
    + + +
    +
    Классификация здания
    +
    Вид строительства
    +
    + +
    +
    + {{ form.building_classification }} +
    + +
    + {{ form.construction_type }} +
    + +
    + +

    Требуется допуск (СРО)

    +
    +
    +
    + + + + +
    +
    + + + +
    +
    + {% for val, text in form.party_types.field.choices %} + + {% endfor %} +
    + + + +
    +
    + +
    + + + +
    +
    +
    + + + + {% for obj in coll %} + {% if obj|class_name == 'Team' %} + {% with team=obj %} +
    + + + + + + +
    + {% specialization_team_widget team_id=team.pk %} +
    + + +
    + {% ratings_team_widget team.pk 'restList2' %} + + +
    +
    +

    Есть допуск СРО

    +
    +
    + + + {% if TEMPLATE_DEBUG %} +
    +
    ######## Team owner #########

    Specializations: {{ team.owner.contractor_specializations.all }}

    Location: {{ team.owner.location }}

    Build. classif-s: {% for o in team.owner.orders.all %}{{ o.project.realty.building_classification }}, {% endfor %}

    Constr. types: {% for o in team.owner.orders.all %}{{ o.project.realty.construction_type }}, {% endfor %}

    CRO: {{ team.owner.cro }}

    Work types: {% for o in team.owner.orders.all %}{{ o.project.work_type }}, {% endfor %}



    ######## Team users #########

    Specializations: {% for u in team.users.all %}{{ u.contractor_specializations.all }}, {% endfor %}

    Location: {% for u in team.users.all %}{{ u.location }}, {% endfor %}

    Build. classif-s: {% for u in team.users.all %}{% for o in u.orders.all %}{{ o.project.realty.building_classification }}, {% endfor %}; {% endfor %}

    Constr. types: {% for u in team.users.all %}{% for o in u.orders.all %}{{ o.project.realty.construction_type }}, {% endfor %}; {% endfor %}

    CRO: {% for u in team.users.all %}{{ u.cro }}, {% endfor %}

    Work types: {% for u in team.users.all %}{% for o in u.orders.all %}{{ o.project.work_type }}, {% endfor %}; {% endfor %}
    +
    + {% endif %} + + +
    + {% for portf in team.portfolios.all|slice:':4' %} + + {% endfor %} +
    +
    + {% endwith %} + {% elif obj|class_name == 'User' %} + {% with contractor=obj %} +
    + + + + + + +
    + {% specialization_widget user_id=contractor.pk %} +
    + + +
    + {% ratings_widget contractor.pk 'restList2' %} + + {% if contractor.cro %} +
    +
    +

    Есть допуск СРО

    +
    + {% endif %} +
    + + + {% if TEMPLATE_DEBUG %} +
    +
    Specializations: {{ contractor.contractor_specializations.all }}

    Location: {{ contractor.location }}

    Build. classif-s: {% for o in contractor.orders.all %}{{ o.project.realty.building_classification }}, {% endfor %}

    Constr. types: {% for o in contractor.orders.all %}{{ o.project.realty.construction_type }}, {% endfor %}

    CRO: {{ contractor.cro }}

    Work types: {% for o in contractor.orders.all %}{{ o.project.work_type }}, {% endfor %}
    +
    + {% endif %} + +
    + {% for portf in contractor.portfolios.all|slice:':4' %} + + {% endfor %} +
    +
    + {% endwith %} + {% endif %} + {% endfor %} + + +
    + {% include 'partials/pagination.html' %} +
    + + + {% include 'partials/footer.html' %} +
    +
    +{% endblock %} + +{% block js_block %} + +{% endblock %} diff --git a/users/views.py b/users/views.py index 9465589..5599beb 100644 --- a/users/views.py +++ b/users/views.py @@ -24,11 +24,13 @@ from .models import User, Team, ContractorResume, ContractorResumeFiles, TeamInv from archilance import util from archilance.mixins import BaseMixin from common.mixins import ContractorRequiredMixin, NoCsrfMixin +from common.models import Location from projects.forms import PortfolioForm -from projects.models import Order, Realty, Project +from projects.models import Order, Realty, Project, BuildingClassfication, ConstructionType from reviews.models import Review from work_sell.forms import WorkSellForm from work_sell.models import Picture +from specializations.models import Specialization from .helpers import get_projects_grouped @@ -249,188 +251,359 @@ class UserFinancialInfoEditView(BaseMixin, View): return render(request, self.template_name, context) +# class ContractorFilterViewOld(BaseMixin, View): +# template_name = 'contractor_filter.html' +# form_class = ContractorFilterForm +# +# def get(self, request, *args, **kwargs): +# form = self.form_class(request.GET, request=request) +# context = self.get_context_data(**_.merge({}, request.GET, kwargs)) +# coll = [] +# +# if form.is_valid(): +# contractors = teams = None +# contr_count = team_count = None +# get_contractors = get_teams = None +# ord = None +# +# cro = form.cleaned_data.get('cro') +# specialization = form.cleaned_data.get('specialization') +# location = form.cleaned_data.get('location') +# work_type = form.cleaned_data.get('work_type') +# build_classif = form.cleaned_data.get('building_classification') +# constr_type = form.cleaned_data.get('construction_type') +# +# party_types = form.cleaned_data.get('party_types') +# last_party_types = form.cleaned_data.get('last_party_types') +# +# if party_types == 'all': +# get_contractors = get_teams = True +# elif party_types == 'contractors': +# get_contractors = True +# elif party_types == 'teams': +# get_teams = True +# elif not party_types: +# if last_party_types == 'contractors': +# get_contractors = True +# elif last_party_types == 'teams': +# get_teams = True +# else: +# get_contractors = get_teams = True +# +# if party_types: +# last_party_types = party_types +# +# context.update({'last_party_types': last_party_types}) +# +# if get_contractors: +# contractors = User.contractor_objects.all() +# +# if cro: +# contractors = contractors.filter(cro=cro) +# +# if specialization: +# contractors = contractors.filter( +# contractor_specializations__lft__gte=specialization.lft, +# contractor_specializations__rght__lte=specialization.rght, +# ) +# +# if location: +# contractors = contractors.filter( +# location__lft__gte=location.lft, +# location__rght__lte=location.rght, +# ) +# +# if work_type: +# contractors = contractors.filter(orders__project__work_type=work_type) +# +# if build_classif: +# contractors = contractors.filter(Q(orders__project__realty__building_classification=build_classif) | +# Q(contractor_building_classifications=build_classif)) +# +# if constr_type: +# contractors = contractors.filter(Q(orders__project__realty__construction_type=constr_type) | +# Q(contractor_construction_types=constr_type)) +# +# if get_teams: +# teams = Team.objects.all() +# +# if cro: +# teams = teams.filter(Q(contractors__cro=cro) | Q(owner__cro=cro)) +# +# if specialization: +# teams = teams.filter( +# ( +# Q(contractors__contractor_specializations__lft__gte=specialization.lft) +# & Q(contractors__contractor_specializations__rght__lte=specialization.rght) +# ) | ( +# Q(owner__contractor_specializations__lft__gte=specialization.lft) +# & Q(owner__contractor_specializations__rght__lte=specialization.rght) +# ), +# ) +# +# if location: +# teams = teams.filter( +# ( +# Q(contractors__location__lft__gte=location.lft) +# & Q(contractors__location__rght__lte=location.rght) +# ) | ( +# Q(owner__location__lft__gte=location.lft) +# & Q(owner__location__rght__lte=location.rght) +# ), +# ) +# +# if work_type: +# teams = teams.filter( +# Q(contractors__orders__project__work_type=work_type) +# | Q(owner__orders__project__work_type=work_type), +# ) +# +# if build_classif: +# teams = teams.filter( +# Q(contractors__orders__project__realty__building_classification=build_classif) +# | Q(owner__orders__project__realty__building_classification=build_classif), +# ) +# +# if constr_type: +# teams = teams.filter( +# Q(contractors__orders__project__realty__construction_type=constr_type) +# | Q(owner__orders__project__realty__construction_type=constr_type), +# ) +# +# if get_contractors and get_teams: +# coll = tuple(itertools.chain(contractors.distinct(), teams.distinct())) +# count = len(coll) +# display_msg = 'Найдено %s элементов' % count if count > 0 else 'Ничего не найдено' +# elif get_contractors: +# coll = contractors.distinct() +# count = coll.count() +# display_msg = 'Найдено %s исполнителей' % count if count > 0 else 'Ничего не найдено' +# elif get_teams: +# coll = teams.distinct() +# count = coll.count() +# display_msg = 'Найдено %s групп' % count if count > 0 else 'Ничего не найдено' +# +# order_by = form.cleaned_data.get('order_by') +# last_order_by = form.cleaned_data.get('last_order_by') +# reverse_order = form.cleaned_data.get('reverse_order') +# +# if order_by: +# reverse_order = not reverse_order if order_by == last_order_by else False +# ord = order_by +# last_order_by = ord +# elif last_order_by: +# ord = last_order_by +# +# if ord: +# if ord == 'name': +# coll = natsort.natsorted(coll, key=lambda obj: getattr(obj, 'username', None) or obj.name, +# reverse=reverse_order) +# elif ord == 'created': +# coll = natsort.natsorted(coll, key=lambda obj: obj.created, reverse=reverse_order) +# +# context.update({ +# 'last_order_by': last_order_by, +# 'reverse_order': reverse_order, +# }) +# else: +# display_msg = 'Пожалуйста, введите корректные данные' +# +# if form.errors: +# messages.info(request, ( +# '

    Произошла ошибка (form)

    ' +# '
    {form}
    ' +# ).format(form=pformat(form.errors))) +# +# paginator = Paginator(coll, settings.PAGE_SIZE) +# page = request.GET.get('page') +# +# try: +# coll = paginator.page(page) +# except PageNotAnInteger: +# coll = paginator.page(1) +# except EmptyPage: +# coll = paginator.page(paginator.num_pages) +# +# context.update({ +# 'form': form, +# 'coll': coll, +# 'is_paginated': True, +# 'page_obj': coll, +# 'display_msg': display_msg, +# }) +# +# return render(request, self.template_name, context) + +# TODO: не работает сортировка по reviews(не получилось создать отзывы) и views(не нашел счетчик просмотров) class ContractorFilterView(BaseMixin, View): template_name = 'contractor_filter.html' + include_template = 'partials/inc-contractors-results.html' form_class = ContractorFilterForm - - def get(self, request, *args, **kwargs): - form = self.form_class(request.GET, request=request) - context = self.get_context_data(**_.merge({}, request.GET, kwargs)) - coll = [] - - if form.is_valid(): - contractors = teams = None - contr_count = team_count = None - get_contractors = get_teams = None - ord = None - - cro = form.cleaned_data.get('cro') - specialization = form.cleaned_data.get('specialization') - location = form.cleaned_data.get('location') - work_type = form.cleaned_data.get('work_type') - build_classif = form.cleaned_data.get('building_classification') - constr_type = form.cleaned_data.get('construction_type') - - party_types = form.cleaned_data.get('party_types') - last_party_types = form.cleaned_data.get('last_party_types') - - if party_types == 'all': - get_contractors = get_teams = True - elif party_types == 'contractors': - get_contractors = True - elif party_types == 'teams': - get_teams = True - elif not party_types: - if last_party_types == 'contractors': - get_contractors = True - elif last_party_types == 'teams': - get_teams = True - else: - get_contractors = get_teams = True - - if party_types: - last_party_types = party_types - - context.update({'last_party_types': last_party_types}) - - if get_contractors: - contractors = User.contractor_objects.all() - - if cro: - contractors = contractors.filter(cro=cro) - - if specialization: - contractors = contractors.filter( - contractor_specializations__lft__gte=specialization.lft, - contractor_specializations__rght__lte=specialization.rght, - ) - - if location: - contractors = contractors.filter( - location__lft__gte=location.lft, - location__rght__lte=location.rght, - ) - - if work_type: - contractors = contractors.filter(orders__project__work_type=work_type) - - if build_classif: - contractors = contractors.filter(Q(orders__project__realty__building_classification=build_classif) | - Q(contractor_building_classifications=build_classif)) - - if constr_type: - contractors = contractors.filter(Q(orders__project__realty__construction_type=constr_type) | - Q(contractor_construction_types=constr_type)) - - if get_teams: - teams = Team.objects.all() - - if cro: - teams = teams.filter(Q(contractors__cro=cro) | Q(owner__cro=cro)) - - if specialization: - teams = teams.filter( - ( - Q(contractors__contractor_specializations__lft__gte=specialization.lft) - & Q(contractors__contractor_specializations__rght__lte=specialization.rght) - ) | ( - Q(owner__contractor_specializations__lft__gte=specialization.lft) - & Q(owner__contractor_specializations__rght__lte=specialization.rght) - ), - ) - - if location: - teams = teams.filter( - ( - Q(contractors__location__lft__gte=location.lft) - & Q(contractors__location__rght__lte=location.rght) - ) | ( - Q(owner__location__lft__gte=location.lft) - & Q(owner__location__rght__lte=location.rght) - ), - ) - - if work_type: - teams = teams.filter( - Q(contractors__orders__project__work_type=work_type) - | Q(owner__orders__project__work_type=work_type), - ) - - if build_classif: - teams = teams.filter( - Q(contractors__orders__project__realty__building_classification=build_classif) - | Q(owner__orders__project__realty__building_classification=build_classif), - ) - - if constr_type: - teams = teams.filter( - Q(contractors__orders__project__realty__construction_type=constr_type) - | Q(owner__orders__project__realty__construction_type=constr_type), - ) - - if get_contractors and get_teams: - coll = tuple(itertools.chain(contractors.distinct(), teams.distinct())) - count = len(coll) - display_msg = 'Найдено %s элементов' % count if count > 0 else 'Ничего не найдено' - elif get_contractors: - coll = contractors.distinct() - count = coll.count() - display_msg = 'Найдено %s исполнителей' % count if count > 0 else 'Ничего не найдено' - elif get_teams: - coll = teams.distinct() - count = coll.count() - display_msg = 'Найдено %s групп' % count if count > 0 else 'Ничего не найдено' - - order_by = form.cleaned_data.get('order_by') - last_order_by = form.cleaned_data.get('last_order_by') - reverse_order = form.cleaned_data.get('reverse_order') - - if order_by: - reverse_order = not reverse_order if order_by == last_order_by else False - ord = order_by - last_order_by = ord - elif last_order_by: - ord = last_order_by - - if ord: - if ord == 'name': - coll = natsort.natsorted(coll, key=lambda obj: getattr(obj, 'username', None) or obj.name, - reverse=reverse_order) - elif ord == 'created': - coll = natsort.natsorted(coll, key=lambda obj: obj.created, reverse=reverse_order) - - context.update({ - 'last_order_by': last_order_by, - 'reverse_order': reverse_order, - }) - else: - display_msg = 'Пожалуйста, введите корректные данные' - - if form.errors: - messages.info(request, ( - '

    Произошла ошибка (form)

    ' - '
    {form}
    ' - ).format(form=pformat(form.errors))) - - paginator = Paginator(coll, settings.PAGE_SIZE) - page = request.GET.get('page') - + PROJECT_ORDER_CHOICES = ( # "Упорядочить по"... + ('name', 'названию'), + ('created', 'дате размещения'), + ('views', 'просмотрам'), + ('reviews', 'Отзывам'), + ('rating', 'Рейтингу'), + ) + + def set_teams_filter(self, objects, request_data): + specialization = request_data.get('specialization') + building_classification = request_data.get('building_classification') + construction_type = request_data.get('construction_type') + location = request_data.get('location') + cro = request_data.get('cro') + if specialization: + query_contractors = util.build_query(specialization, Specialization, + 'contractors__contractor_specializations__lft__gte', + 'contractors__contractor_specializations__rght__lte') + query_owner = util.build_query(specialization, Specialization, + 'owner__contractor_specializations__lft__gte', + 'owner__contractor_specializations__rght__lte') + objects = objects.filter(query_contractors | query_owner) + + if building_classification: + query_contractors = util.build_query(building_classification, BuildingClassfication, + 'contractors__contractor_building_classifications') + query_owner = util.build_query(building_classification, BuildingClassfication, + 'owner__contractor_building_classifications') + objects = objects.filter(query_contractors | query_owner) + + if construction_type: + query_contractors = util.build_query(construction_type, ConstructionType, + 'contractors__contractor_construction_types') + query_owner = util.build_query(construction_type, ConstructionType, + 'owner__contractor_construction_types') + objects = objects.filter(query_contractors | query_owner) + + if location: + query_contractors = util.build_query(location, Location, + 'contractors__location__lft__gte', + 'contractors__location__rght__lte') + query_owner = util.build_query(construction_type, Location, + 'owner__location__lft__gte', + 'owner__location__rght__lte',) + objects = objects.filter(query_contractors | query_owner) + + if cro: + objects = objects.filter(Q(contractors__cro=cro) | Q(owner__cro=cro)) + + return objects + + def set_contractors_filter(self, objects, request_data): + specialization = request_data.get('specialization') + building_classification = request_data.get('building_classification') + construction_type = request_data.get('construction_type') + location = request_data.get('location') + cro = request_data.get('cro') + if specialization: + query = util.build_query(specialization, Specialization, + 'contractor_specializations__lft__gte', 'contractor_specializations__rght__lte') + objects = objects.filter(query) + + if building_classification: + query = util.build_query(building_classification, BuildingClassfication, + 'contractor_building_classifications__lft__gte', + 'contractor_building_classifications__rght__lte') + objects = objects.filter(query) + + if construction_type: + objects = objects.filter(contractor_construction_types__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 cro: + objects = objects.filter(cro=True) + return objects + + def contractors_sort_by(self, contractors, order_by): + if order_by == 'name': + contractors = contractors.order_by('username') + if order_by == 'created': + contractors = contractors.order_by('created') + if order_by == 'views': + pass + if order_by == 'reviews': + pass + if order_by == 'rating': + contractors = contractors.order_by('rating') + return contractors + + def teams_sort_by(self, teams, order_by): + if order_by == 'name': + teams = teams.order_by('name') + if order_by == 'created': + teams = teams.order_by('created') + if order_by == 'views': + pass + if order_by == 'reviews': + pass + if order_by == 'rating': + teams = teams.order_by('rating') + return teams + + def pagination(self, objects, page): + paginator = Paginator(objects, settings.PAGE_SIZE) + # print("pag page = ", page) try: - coll = paginator.page(page) + objects = paginator.page(page) except PageNotAnInteger: - coll = paginator.page(1) + objects = paginator.page(1) except EmptyPage: - coll = paginator.page(paginator.num_pages) + objects = paginator.page(paginator.num_pages) + return objects + + def get_context(self, request_data): + context = request_data.dict() + contractors = User.contractor_objects.all() + teams = Team.objects.all() + print(request_data) + party_types = request_data.get("party_types") + order_by = request_data.get("order_by") + print("order_by = ", order_by) + + if party_types == 'teams': + objects = self.set_teams_filter(teams, request_data).distinct() + objects = self.teams_sort_by(objects, order_by) + count = objects.count() + display_msg = 'Найдено %s групп' % count if count > 0 else 'Ничего не найдено' + elif party_types == 'contractors': + objects = self.set_contractors_filter(contractors, request_data).distinct() + objects = self.contractors_sort_by(objects, order_by) + count = objects.count() + display_msg = 'Найдено %s исполнителей' % count if count > 0 else 'Ничего не найдено' + else: + teams = self.set_teams_filter(teams, request_data) + teams = self.teams_sort_by(teams, order_by) + contractors = self.set_contractors_filter(contractors, request_data) + contractors = self.contractors_sort_by(contractors, order_by) + objects = tuple(itertools.chain(contractors.distinct(), teams.distinct())) + count = len(objects) + display_msg = 'Найдено %s элементов' % count if count > 0 else 'Ничего не найдено' + + # objects = self.sort_by(objects, order_by) + objects = self.pagination(objects, request_data.get("page")) context.update({ - 'form': form, - 'coll': coll, + 'choices': self.PROJECT_ORDER_CHOICES, + 'objects': objects, 'is_paginated': True, - 'page_obj': coll, 'display_msg': display_msg, + 'page_obj': objects, + # 'num_results': num_results, + # '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 ContractorProfileView(BaseMixin, DetailView): @@ -915,7 +1088,7 @@ class CustomerProfileReviewsView(BaseMixin, View): # @Add fast num_current_projects = customer.customer_projects.filter(state='active').exclude(order__contractor__isnull=True, - order__team__isnull=True).count() + order__team__isnull=True).count() context.update({ 'reviews': reviews, diff --git a/webpack.config.js b/webpack.config.js index 2ca09b1..c08c003 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -18,7 +18,12 @@ module.exports = { home_page: "./assets/js/src/home_page.js", //profile customer_profile: "./assets/js/src/customer_profile.js", - user_profile_edit: "./assets/js/src/user_profile_edit.js" + user_profile_edit: "./assets/js/src/user_profile_edit.js", + //filters/search + 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", + },