PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 2.0.4
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v2.0.4
3.1.4 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 All 93 releases
ultimate-store-kit / includes / controls / assets / js / usk-dynamic-select.js

usk-dynamic-select.js in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 2.0.4, at includes/controls/assets/js/usk-dynamic-select.js

125 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 !function ($) {
2 'use strict';
3 $(window).on('elementor:init', function () {
4 var widget = elementor.modules.controls.BaseData.extend({
5 isTitlesReceived: false,
6 // spinner for ajax search search input
7 addControlSpinner: function () {
8 this.ui.select.prop('disabled', true);
9 this.$el.find('.elementor-control-title').after('<span class="elementor-control-spinner">&nbsp;<i class="eicon-spinner eicon-animation-spin"></i>&nbsp;</span>');
10 },
11
12 prepareArgs : function () {
13 var self = this,
14 queryArgs = self.model.get('query_args');
15
16 if (!_.isObject(queryArgs)) {
17 queryArgs = {};
18 }
19
20 if (queryArgs.widget_props && _.isObject(queryArgs.widget_props)) {
21 _.each(queryArgs.widget_props, function (item, index) {
22 queryArgs[index] = self.container.settings.get(item);
23 });
24 }
25 return queryArgs;
26 },
27 getQueryData : function () {
28 var args = $.extend({}, this.prepareArgs());
29 delete args.widget_props;
30 return args;
31 },
32 // get the title string after search
33 getValueTitles : function () {
34 var self = this,
35 ids = this.getControlValue();
36
37 if (!ids) {
38 return;
39 }
40
41 if (!_.isArray(ids)) {
42 ids = [ids];
43 }
44
45 var params = {
46 action : usk_dynamic_select.action,
47 security: usk_dynamic_select.nonce,
48 ids : ids
49 };
50
51 var data = $.extend({}, params, self.getQueryData());
52
53 $.ajax({
54 url : ajaxurl,
55 type : 'POST',
56 data : data,
57 before : self.addControlSpinner(),
58 success: function success(ajaxData) {
59 self.isTitlesReceived = true;
60 if (!ajaxData.success) {
61 console.log('server errors:', ajaxData.data);
62 } else {
63 var values = {};
64 _.each(ajaxData.data, function (item) {
65 values[item.id] = item.text;
66 });
67
68 self.model.set('options', values);
69 self.ui.select && self.ui.select.data('select2') && self.render();
70 }
71 }
72 });
73 },
74
75 onReady : function () {
76 var self = this;
77 this.ui.select.select2({
78 minimumInputLength: self.model.get('minlen') ? self.model.get('minlen') : 2,
79 placeholder : self.model.get('placeholder') ? self.model.get('placeholder') : 'Type & Search',
80 allowClear : true,
81 ajax : {
82 url : ajaxurl,
83 dataType : 'json',
84 method : 'post',
85 delay : 300,
86 data : function (data) {
87 var params = {
88 action : usk_dynamic_select.action,
89 security : usk_dynamic_select.nonce,
90 search_text: data.term
91 };
92 return $.extend({}, params, self.getQueryData());
93 },
94 processResults: function (response) {
95 if (response.success && response.data) {
96 return {
97 results: response.data
98 };
99 } else {
100 //console.log('server error!', response.data);
101 return {
102 results: [{
103 id : -1,
104 text : 'No Data found',
105 disabled: true
106 }]
107 };
108 }
109 },
110 cache : true
111 }
112 });
113
114 if (!this.isTitlesReceived) {
115 this.getValueTitles();
116 }
117 },
118 onBeforeDestroy: function () {
119 this.ui.select.data('select2') && this.ui.select.select2('destroy');
120 this.$el.remove();
121 }
122 });
123 elementor.addControlView('usk-dynamic-select', widget);
124 });
125 }(jQuery);