From 1c6cfe7f8a4e17654f25b1ba3cb81864939c5824 Mon Sep 17 00:00:00 2001 From: vedatakd Date: Mon, 16 Dec 2019 10:48:43 +0300 Subject: [PATCH] base theme filter location for classified list page --- .../views/list/partials/list-filter.twig | 13 +- .../base-theme/resources/css/select2.css | 473 ++ .../base-theme/resources/css/theme.css | 5 + .../resources/js/jquery-3.2.1.slim.min.js | 4 - .../base-theme/resources/js/params.js | 24 + .../base-theme/resources/js/select2.js | 5725 +++++++++++++++++ .../resources/js/vendor/bootstrap.min.js | 7 - .../resources/views/partials/assets.twig | 2 + .../resources/views/partials/metadata.twig | 1 + .../resources/js/filterLocation.js | 155 + .../views/ads-list/partials/list-filter.twig | 60 + .../resources/views/list/filter.twig | 61 - 12 files changed, 6457 insertions(+), 73 deletions(-) create mode 100644 addons/default/visiosoft/base-theme/resources/css/select2.css delete mode 100644 addons/default/visiosoft/base-theme/resources/js/jquery-3.2.1.slim.min.js create mode 100644 addons/default/visiosoft/base-theme/resources/js/params.js create mode 100644 addons/default/visiosoft/base-theme/resources/js/select2.js delete mode 100644 addons/default/visiosoft/base-theme/resources/js/vendor/bootstrap.min.js create mode 100644 addons/default/visiosoft/location-module/resources/js/filterLocation.js create mode 100644 addons/default/visiosoft/location-module/resources/views/ads-list/partials/list-filter.twig delete mode 100644 addons/default/visiosoft/location-module/resources/views/list/filter.twig diff --git a/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig b/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig index c36b13263..a9b8d3507 100644 --- a/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig +++ b/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig @@ -6,7 +6,18 @@
- {{ addBlock('ads-list/partials/list-filter',{'mainCats':mainCats,'subCats':subCats,'ranges':ranges,'checkboxes':checkboxes,'radio':radio})|raw }} + {{ addBlock('ads-list/partials/list-filter',{ + 'mainCats':mainCats, + 'subCats':subCats, + 'ranges':ranges, + 'checkboxes':checkboxes, + 'radio':radio, + 'countries':countries, + 'cities':cities, + 'districts':districts, + 'neighborhoods':neighborhoods, + 'villages':villages + })|raw }}
',trigger:"hover focus",title:"",delay:0,html:!1,selector:!1,placement:"top",offset:0,container:!1,fallbackPlacement:"flip",boundary:"scrollParent",sanitize:!0,sanitizeFn:null,whiteList:Ee},je="show",He="out",Re={HIDE:"hide"+De,HIDDEN:"hidden"+De,SHOW:"show"+De,SHOWN:"shown"+De,INSERTED:"inserted"+De,CLICK:"click"+De,FOCUSIN:"focusin"+De,FOCUSOUT:"focusout"+De,MOUSEENTER:"mouseenter"+De,MOUSELEAVE:"mouseleave"+De},xe="fade",Fe="show",Ue=".tooltip-inner",We=".arrow",qe="hover",Me="focus",Ke="click",Qe="manual",Be=function(){function i(t,e){if("undefined"==typeof u)throw new TypeError("Bootstrap's tooltips require Popper.js (https://popper.js.org/)");this._isEnabled=!0,this._timeout=0,this._hoverState="",this._activeTrigger={},this._popper=null,this.element=t,this.config=this._getConfig(e),this.tip=null,this._setListeners()}var t=i.prototype;return t.enable=function(){this._isEnabled=!0},t.disable=function(){this._isEnabled=!1},t.toggleEnabled=function(){this._isEnabled=!this._isEnabled},t.toggle=function(t){if(this._isEnabled)if(t){var e=this.constructor.DATA_KEY,n=g(t.currentTarget).data(e);n||(n=new this.constructor(t.currentTarget,this._getDelegateConfig()),g(t.currentTarget).data(e,n)),n._activeTrigger.click=!n._activeTrigger.click,n._isWithActiveTrigger()?n._enter(null,n):n._leave(null,n)}else{if(g(this.getTipElement()).hasClass(Fe))return void this._leave(null,this);this._enter(null,this)}},t.dispose=function(){clearTimeout(this._timeout),g.removeData(this.element,this.constructor.DATA_KEY),g(this.element).off(this.constructor.EVENT_KEY),g(this.element).closest(".modal").off("hide.bs.modal"),this.tip&&g(this.tip).remove(),this._isEnabled=null,this._timeout=null,this._hoverState=null,(this._activeTrigger=null)!==this._popper&&this._popper.destroy(),this._popper=null,this.element=null,this.config=null,this.tip=null},t.show=function(){var e=this;if("none"===g(this.element).css("display"))throw new Error("Please use show on visible elements");var t=g.Event(this.constructor.Event.SHOW);if(this.isWithContent()&&this._isEnabled){g(this.element).trigger(t);var n=_.findShadowRoot(this.element),i=g.contains(null!==n?n:this.element.ownerDocument.documentElement,this.element);if(t.isDefaultPrevented()||!i)return;var o=this.getTipElement(),r=_.getUID(this.constructor.NAME);o.setAttribute("id",r),this.element.setAttribute("aria-describedby",r),this.setContent(),this.config.animation&&g(o).addClass(xe);var s="function"==typeof this.config.placement?this.config.placement.call(this,o,this.element):this.config.placement,a=this._getAttachment(s);this.addAttachmentClass(a);var l=this._getContainer();g(o).data(this.constructor.DATA_KEY,this),g.contains(this.element.ownerDocument.documentElement,this.tip)||g(o).appendTo(l),g(this.element).trigger(this.constructor.Event.INSERTED),this._popper=new u(this.element,o,{placement:a,modifiers:{offset:this._getOffset(),flip:{behavior:this.config.fallbackPlacement},arrow:{element:We},preventOverflow:{boundariesElement:this.config.boundary}},onCreate:function(t){t.originalPlacement!==t.placement&&e._handlePopperPlacementChange(t)},onUpdate:function(t){return e._handlePopperPlacementChange(t)}}),g(o).addClass(Fe),"ontouchstart"in document.documentElement&&g(document.body).children().on("mouseover",null,g.noop);var c=function(){e.config.animation&&e._fixTransition();var t=e._hoverState;e._hoverState=null,g(e.element).trigger(e.constructor.Event.SHOWN),t===He&&e._leave(null,e)};if(g(this.tip).hasClass(xe)){var h=_.getTransitionDurationFromElement(this.tip);g(this.tip).one(_.TRANSITION_END,c).emulateTransitionEnd(h)}else c()}},t.hide=function(t){var e=this,n=this.getTipElement(),i=g.Event(this.constructor.Event.HIDE),o=function(){e._hoverState!==je&&n.parentNode&&n.parentNode.removeChild(n),e._cleanTipClass(),e.element.removeAttribute("aria-describedby"),g(e.element).trigger(e.constructor.Event.HIDDEN),null!==e._popper&&e._popper.destroy(),t&&t()};if(g(this.element).trigger(i),!i.isDefaultPrevented()){if(g(n).removeClass(Fe),"ontouchstart"in document.documentElement&&g(document.body).children().off("mouseover",null,g.noop),this._activeTrigger[Ke]=!1,this._activeTrigger[Me]=!1,this._activeTrigger[qe]=!1,g(this.tip).hasClass(xe)){var r=_.getTransitionDurationFromElement(n);g(n).one(_.TRANSITION_END,o).emulateTransitionEnd(r)}else o();this._hoverState=""}},t.update=function(){null!==this._popper&&this._popper.scheduleUpdate()},t.isWithContent=function(){return Boolean(this.getTitle())},t.addAttachmentClass=function(t){g(this.getTipElement()).addClass(Ae+"-"+t)},t.getTipElement=function(){return this.tip=this.tip||g(this.config.template)[0],this.tip},t.setContent=function(){var t=this.getTipElement();this.setElementContent(g(t.querySelectorAll(Ue)),this.getTitle()),g(t).removeClass(xe+" "+Fe)},t.setElementContent=function(t,e){"object"!=typeof e||!e.nodeType&&!e.jquery?this.config.html?(this.config.sanitize&&(e=Se(e,this.config.whiteList,this.config.sanitizeFn)),t.html(e)):t.text(e):this.config.html?g(e).parent().is(t)||t.empty().append(e):t.text(g(e).text())},t.getTitle=function(){var t=this.element.getAttribute("data-original-title");return t||(t="function"==typeof this.config.title?this.config.title.call(this.element):this.config.title),t},t._getOffset=function(){var e=this,t={};return"function"==typeof this.config.offset?t.fn=function(t){return t.offsets=l({},t.offsets,e.config.offset(t.offsets,e.element)||{}),t}:t.offset=this.config.offset,t},t._getContainer=function(){return!1===this.config.container?document.body:_.isElement(this.config.container)?g(this.config.container):g(document).find(this.config.container)},t._getAttachment=function(t){return Pe[t.toUpperCase()]},t._setListeners=function(){var i=this;this.config.trigger.split(" ").forEach(function(t){if("click"===t)g(i.element).on(i.constructor.Event.CLICK,i.config.selector,function(t){return i.toggle(t)});else if(t!==Qe){var e=t===qe?i.constructor.Event.MOUSEENTER:i.constructor.Event.FOCUSIN,n=t===qe?i.constructor.Event.MOUSELEAVE:i.constructor.Event.FOCUSOUT;g(i.element).on(e,i.config.selector,function(t){return i._enter(t)}).on(n,i.config.selector,function(t){return i._leave(t)})}}),g(this.element).closest(".modal").on("hide.bs.modal",function(){i.element&&i.hide()}),this.config.selector?this.config=l({},this.config,{trigger:"manual",selector:""}):this._fixTitle()},t._fixTitle=function(){var t=typeof this.element.getAttribute("data-original-title");(this.element.getAttribute("title")||"string"!==t)&&(this.element.setAttribute("data-original-title",this.element.getAttribute("title")||""),this.element.setAttribute("title",""))},t._enter=function(t,e){var n=this.constructor.DATA_KEY;(e=e||g(t.currentTarget).data(n))||(e=new this.constructor(t.currentTarget,this._getDelegateConfig()),g(t.currentTarget).data(n,e)),t&&(e._activeTrigger["focusin"===t.type?Me:qe]=!0),g(e.getTipElement()).hasClass(Fe)||e._hoverState===je?e._hoverState=je:(clearTimeout(e._timeout),e._hoverState=je,e.config.delay&&e.config.delay.show?e._timeout=setTimeout(function(){e._hoverState===je&&e.show()},e.config.delay.show):e.show())},t._leave=function(t,e){var n=this.constructor.DATA_KEY;(e=e||g(t.currentTarget).data(n))||(e=new this.constructor(t.currentTarget,this._getDelegateConfig()),g(t.currentTarget).data(n,e)),t&&(e._activeTrigger["focusout"===t.type?Me:qe]=!1),e._isWithActiveTrigger()||(clearTimeout(e._timeout),e._hoverState=He,e.config.delay&&e.config.delay.hide?e._timeout=setTimeout(function(){e._hoverState===He&&e.hide()},e.config.delay.hide):e.hide())},t._isWithActiveTrigger=function(){for(var t in this._activeTrigger)if(this._activeTrigger[t])return!0;return!1},t._getConfig=function(t){var e=g(this.element).data();return Object.keys(e).forEach(function(t){-1!==Oe.indexOf(t)&&delete e[t]}),"number"==typeof(t=l({},this.constructor.Default,e,"object"==typeof t&&t?t:{})).delay&&(t.delay={show:t.delay,hide:t.delay}),"number"==typeof t.title&&(t.title=t.title.toString()),"number"==typeof t.content&&(t.content=t.content.toString()),_.typeCheckConfig(be,t,this.constructor.DefaultType),t.sanitize&&(t.template=Se(t.template,t.whiteList,t.sanitizeFn)),t},t._getDelegateConfig=function(){var t={};if(this.config)for(var e in this.config)this.constructor.Default[e]!==this.config[e]&&(t[e]=this.config[e]);return t},t._cleanTipClass=function(){var t=g(this.getTipElement()),e=t.attr("class").match(Ne);null!==e&&e.length&&t.removeClass(e.join(""))},t._handlePopperPlacementChange=function(t){var e=t.instance;this.tip=e.popper,this._cleanTipClass(),this.addAttachmentClass(this._getAttachment(t.placement))},t._fixTransition=function(){var t=this.getTipElement(),e=this.config.animation;null===t.getAttribute("x-placement")&&(g(t).removeClass(xe),this.config.animation=!1,this.hide(),this.show(),this.config.animation=e)},i._jQueryInterface=function(n){return this.each(function(){var t=g(this).data(Ie),e="object"==typeof n&&n;if((t||!/dispose|hide/.test(n))&&(t||(t=new i(this,e),g(this).data(Ie,t)),"string"==typeof n)){if("undefined"==typeof t[n])throw new TypeError('No method named "'+n+'"');t[n]()}})},s(i,null,[{key:"VERSION",get:function(){return"4.3.1"}},{key:"Default",get:function(){return Le}},{key:"NAME",get:function(){return be}},{key:"DATA_KEY",get:function(){return Ie}},{key:"Event",get:function(){return Re}},{key:"EVENT_KEY",get:function(){return De}},{key:"DefaultType",get:function(){return ke}}]),i}();g.fn[be]=Be._jQueryInterface,g.fn[be].Constructor=Be,g.fn[be].noConflict=function(){return g.fn[be]=we,Be._jQueryInterface};var Ve="popover",Ye="bs.popover",ze="."+Ye,Xe=g.fn[Ve],$e="bs-popover",Ge=new RegExp("(^|\\s)"+$e+"\\S+","g"),Je=l({},Be.Default,{placement:"right",trigger:"click",content:"",template:''}),Ze=l({},Be.DefaultType,{content:"(string|element|function)"}),tn="fade",en="show",nn=".popover-header",on=".popover-body",rn={HIDE:"hide"+ze,HIDDEN:"hidden"+ze,SHOW:"show"+ze,SHOWN:"shown"+ze,INSERTED:"inserted"+ze,CLICK:"click"+ze,FOCUSIN:"focusin"+ze,FOCUSOUT:"focusout"+ze,MOUSEENTER:"mouseenter"+ze,MOUSELEAVE:"mouseleave"+ze},sn=function(t){var e,n;function i(){return t.apply(this,arguments)||this}n=t,(e=i).prototype=Object.create(n.prototype),(e.prototype.constructor=e).__proto__=n;var o=i.prototype;return o.isWithContent=function(){return this.getTitle()||this._getContent()},o.addAttachmentClass=function(t){g(this.getTipElement()).addClass($e+"-"+t)},o.getTipElement=function(){return this.tip=this.tip||g(this.config.template)[0],this.tip},o.setContent=function(){var t=g(this.getTipElement());this.setElementContent(t.find(nn),this.getTitle());var e=this._getContent();"function"==typeof e&&(e=e.call(this.element)),this.setElementContent(t.find(on),e),t.removeClass(tn+" "+en)},o._getContent=function(){return this.element.getAttribute("data-content")||this.config.content},o._cleanTipClass=function(){var t=g(this.getTipElement()),e=t.attr("class").match(Ge);null!==e&&0=this._offsets[o]&&("undefined"==typeof this._offsets[o+1]||t diff --git a/addons/default/visiosoft/location-module/resources/js/filterLocation.js b/addons/default/visiosoft/location-module/resources/js/filterLocation.js new file mode 100644 index 000000000..0679bdc66 --- /dev/null +++ b/addons/default/visiosoft/location-module/resources/js/filterLocation.js @@ -0,0 +1,155 @@ +let searchParams = new URLSearchParams(window.location.search); + +//Set Select2 Type for Location Fields +$('#cities, #countries, #districts, #neighborhoods, #village').select2({ + placeholder: select_trans +}); + + +FindLocations = (id, table, typeDb, divId, paramName = null) => { + $.ajax({ + type: 'get', + url: '/getlocations', + data: { + id: id, + table: table, + typeDb: typeDb, + }, + success: function (response) { + setLocations(response, id, table, typeDb, divId, paramName); + return response; + }, + error: function (err) { + reject(Error("It broke")); + } + }); +}; + + +setLocations = (response, id, table, typeDb, divId, paramName) => { + + //Add Options + if(divId != "#cities") + { + $(divId).append("") + } + response.forEach(function (options) { + $(divId).append("") + }); + + //Set Selected Option + if (paramName != null) { + if (divId == "#cities") { + $('#countries').val(searchParams.get('country')); + $('#countries').select2(); + $('#cities').val(findParam("city[]")); + } else { + $(divId).val(searchParams.get(paramName)); + } + $(divId).select2(); + } + +}; + +//Category Change +$('#countries').on('change', function () { + $('#cities').empty(); + var table = "cities"; + var typeDb = 'parent_country_id'; + var id = $('#countries').val(); + var divId = "#cities"; + + FindLocations(id, table, typeDb, divId); +}); + +//City Change +$('#cities, .select2-selection__choice__remove').on('change', function () { + $('#districts').empty(); + var table = "districts"; + var typeDb = 'parent_city_id'; + var id = $('#cities').val(); + var divId = "#districts"; + + FindLocations(id, table, typeDb, divId); +}); + +//Districts Change +$('#districts').on('change', function () { + var table = "neighborhoods"; + var typeDb = 'parent_district_id'; + var id = $('#districts').val(); + var divId = "#neighborhoods"; + + FindLocations(id, table, typeDb, divId); +}); + +//Neighborhoods Change +$('#neighborhoods').on('change', function () { + var table = "village"; + var typeDb = 'parent_neighborhood_id'; + var id = $('#neighborhoods').val(); + var divId = "#village"; + + FindLocations(id, table, typeDb, divId); +}); + + +jQuery(document).ready(function ($) { + +}).promise().done(function () { + + //Get City && Set Country + if (searchParams.get('country') != '') { + $('#cities').empty(); + var table = "cities"; + var typeDb = 'parent_country_id'; + var id = searchParams.get('country'); + var divId = "#cities"; + var paramName = 'city'; + + FindLocations(id, table, typeDb, divId, paramName); + } + +}).promise().done(function () { + + //get District && set city + if (findParam('city[]').length) { + $('#districts').empty(); + var table = "districts"; + var typeDb = 'parent_city_id'; + var id = findParam('city[]'); + var divId = "#districts"; + var paramName = 'district'; + + FindLocations(id, table, typeDb, divId, paramName); + } + +}).promise().done(function () { + + //get neighborhood && set districts + if (searchParams.get('district') != '') { + $('#neighborhoods').empty(); + var table = "neighborhoods"; + var typeDb = 'parent_district_id'; + var id = searchParams.get('district'); + var divId = "#neighborhoods"; + var paramName = 'neighborhood'; + + FindLocations(id, table, typeDb, divId, paramName); + } + +}).promise().done(function () { + + //get village && set neighborhoods + if (searchParams.get('neighborhood') != '') { + $('#village').empty(); + var table = "village"; + var typeDb = 'parent_neighborhood_id'; + var id = searchParams.get('neighborhood'); + var divId = "#village"; + var paramName = 'village'; + + FindLocations(id, table, typeDb, divId, paramName); + } + +}); \ No newline at end of file diff --git a/addons/default/visiosoft/location-module/resources/views/ads-list/partials/list-filter.twig b/addons/default/visiosoft/location-module/resources/views/ads-list/partials/list-filter.twig new file mode 100644 index 000000000..469211e97 --- /dev/null +++ b/addons/default/visiosoft/location-module/resources/views/ads-list/partials/list-filter.twig @@ -0,0 +1,60 @@ +
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ +{{ asset_add("scripts.js", "visiosoft.module.location::js/filterLocation.js") }} \ No newline at end of file diff --git a/addons/default/visiosoft/location-module/resources/views/list/filter.twig b/addons/default/visiosoft/location-module/resources/views/list/filter.twig deleted file mode 100644 index 67daa63af..000000000 --- a/addons/default/visiosoft/location-module/resources/views/list/filter.twig +++ /dev/null @@ -1,61 +0,0 @@ -{% if setting_value('visiosoft.module.location::list_page_location') %} -
- - -
-
-
    -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
-
-
-
-{% endif %} -{{ asset_add("scripts.js", "visiosoft.theme.base::js/filterLocation.js") }}