PageSourceSearch

https://esse.store/catalog/view/javascript/progroman/jquery.progroman.citymanager.js?v=8.3-0

js esse.store collected 2026-10-08 12:57:29 UTC 7,421 bytes, 253 lines download raw bytes

1/* ProgRoman - CityManager Pro v8.3 */
2if (window.Prmn === undefined) { Prmn = {}; }
3
4Prmn.CityManager = function(options) {
5    this.switchers = [];
6    this.messages = [];
7    this.options = $.extend({}, Prmn.CityManager.DEFAULTS, options);
8    this.url_module = this.getHttpHost() + 'index.php?route=extension/module/progroman/citymanager';
9    this.cities_popup = null;
10    this.confirm_shown = false;
11
12    if ($('#prmn-cmngr-cities').length) {
13        this.cities_popup = $('#prmn-cmngr-cities');
14        this.initCitiesPopup();
15    }
16};
17
18Prmn.CityManager.DEFAULTS = {
19    base_path: 'auto'
20};
21
22Prmn.CityManager.prototype.addSwitcher = function(el) {
23    this.switchers.push(new Prmn.CitySwitcher(el));
24};
25
26Prmn.CityManager.prototype.addMessage = function(el) {
27    this.messages.push(new Prmn.CityMessage(el));
28};
29
30Prmn.CityManager.prototype.loadData = function() {
31    var self = this, i;
32    var need_ajax = this.messages.length > 0;
33
34    if (!need_ajax) {
35        for (i in this.switchers) {
36            if (!this.switchers[i].loaded) {
37                need_ajax = true;
38            }
39        }
40    }
41    if (need_ajax) {
42        $.ajax({
43            url: this.url_module + '/init',
44            data: {url: location.pathname + location.search},
45            dataType: 'json',
46            cache: false,
47            success: function(json) {
48                var i, j;
49                for (i in self.switchers) if (self.switchers.hasOwnProperty(i)) {
50                    if (!self.switchers[i].loaded) {
51                        self.switchers[i].setContent(json.content);
52                    }
53                }
54
55                if (json.messages) {
56                    for (i in json.messages) {
57                        for (j in self.messages) if (self.messages.hasOwnProperty(j)) {
58                            if (self.messages[j].key === i) {
59                                self.messages[j].setContent(json.messages[i]);
60                            }
61                        }
62                    }
63                }
64
65                for (i in self.messages) if (self.messages.hasOwnProperty(i)) {
66                    self.messages[i].setDefault();
67                }
68            }
69        });
70    }
71};
72
73Prmn.CityManager.prototype.showCitiesPopup = function() {
74    if (this.cities_popup !== 'loading') {
75        var self = this;
76        if (!this.cities_popup) {
77            this.cities_popup = 'loading';
78            $.ajax({
79                url: this.url_module + '/cities',
80                dataType: 'html',
81                cache: false,
82                success: function (html) {
83                    self.hideAllConfirm();
84                    self.cities_popup = $(html);
85                    $('body').append(self.cities_popup);
86                    self.initCitiesPopup();
87                    self.cities_popup.modal('show');
88                }
89            });
90        } else {
91            self.hideAllConfirm();
92            self.cities_popup.modal('show');
93        }
94    }
95};
96
97Prmn.CityManager.prototype.initCitiesPopup = function() {
98    var self = this;
99    this.cities_popup.find('.prmn-cmngr-cities__city-name').click(function(ev) {
100        ev.preventDefault();
101        self.setFias($(this).data('id'));
102        self.cities_popup.modal('hide');
103    });
104    this.autocomplete(this.cities_popup.find('.prmn-cmngr-cities__search'));
105    self.cities_popup.on('shown.bs.modal', function() {
106        self.cities_popup.find('.prmn-cmngr-cities__search').focus();
107    });
108};
109
110Prmn.CityManager.prototype.hideAllConfirm = function() {
111    var i;
112    for (i in this.switchers) {
113        this.switchers[i].hideConfirm();
114    }
115};
116
117Prmn.CityManager.prototype.autocomplete = function(el) {
118    var self = this;
119    el.prmnAutocomplete({
120        'source': self.url_module + '/search',
121        'select': function(item) {
122            el.val(item.name);
123            self.setFias(item.value);
124            self.cities_popup.modal('hide');
125        }
126    });
127    el.siblings('ul.dropdown-menu').css({'maxHeight': 300, 'overflowY': 'auto', 'overflowX': 'hidden'});
128};
129
130Prmn.CityManager.prototype.setFias = function(id) {
131    $.ajax({
132        url: this.url_module + '/save&fias_id=' + id,
133        dataType: 'json',
134        cache: false,
135        success: function(json) {
136            if (json.success) {
137                location.reload();
138            }
139        }
140    });
141};
142
143Prmn.CityManager.prototype.getHttpHost = function() {
144    if (!Prmn.CityManager.host) {
145        Prmn.CityManager.host = location.protocol + '//' + location.host + '/';
146
147        if (this.options.base_path === 'auto') {
148            var base = $('base').attr('href'), matches;
149            if (base && (matches = base.match(/^http(?:s)?:\/\/[^/]*\/(.*)/))) {
150                Prmn.CityManager.host += matches[1];
151            }
152        } else if (this.options.base_path) {
153            Prmn.CityManager.host += this.options.base_path;
154        }
155    }
156
157    return Prmn.CityManager.host;
158};
159
160Prmn.CityManager.prototype.confirmShown = function() {
161    if (!this.confirm_shown) {
162        this.confirm_shown = true;
163        $.get(this.url_module + '/confirmshown');
164    }
165};
166
167/**
168 * CitySwitcher
169 * @constructor
170 */
171Prmn.CitySwitcher = function(el) {
172    this.$element = el;
173    this.loaded = !el.is(':empty');
174    this.confirm = el.find('.prmn-cmngr__confirm');
175    var self = this;
176
177    el.on('click', '.prmn-cmngr__city', function() {
178        Prmn.citymanager.showCitiesPopup();
179    });
180
181    el.on('click', '.prmn-cmngr__confirm-btn', function() {
182        $.get(Prmn.citymanager.url_module + '/confirmclick');
183
184        if ($(this).data('value') === 'no') {
185            Prmn.citymanager.showCitiesPopup();
186        } else if ($(this).data('redirect')) {
187            location.href = $(this).data('redirect');
188        }
189
190        Prmn.citymanager.hideAllConfirm();
191    });
192
193    this.showConfirm();
194};
195
196Prmn.CitySwitcher.prototype.setContent = function(html) {
197    if (!this.loaded) {
198        html = $(html);
199        this.$element.html(html);
200        this.loaded = true;
201        this.confirm = this.$element.find('.prmn-cmngr__confirm');
202        this.showConfirm();
203    }
204};
205
206Prmn.CitySwitcher.prototype.showConfirm = function() {
207    if (this.confirm.length) {
208        Prmn.citymanager.confirmShown();
209
210        if (!(this.$element.data('confirm') === false)) {
211            this.confirm.show();
212        } else {
213            this.confirm.remove();
214        }
215    }
216};
217
218Prmn.CitySwitcher.prototype.hideConfirm = function() {
219    this.confirm.hide();
220};
221
222/**
223 * CityMessage
224 * @constructor
225 */
226Prmn.CityMessage = function(el) {
227    this.$element = el;
228    this.key = el.data('key');
229    this.default = el.data('default');
230    this.$element.removeAttr('data-key').removeAttr('data-default');
231    this.found = false;
232};
233
234Prmn.CityMessage.prototype.setContent = function(html) {
235    this.$element.html(html);
236    this.found = true;
237};
238
239Prmn.CityMessage.prototype.setDefault = function() {
240    if (!this.found) {
241        this.$element.html(this.default);
242    }
243};
244
245$(function() {
246    var switchers = $('.prmn-cmngr'), messages = $('.prmn-cmngr-message');
247    if (switchers.length || messages.length) {
248        Prmn.citymanager = Prmn.city_manager = new Prmn.CityManager();
249        switchers.each(function() { Prmn.citymanager.addSwitcher($(this)); });
250        messages.each(function() { Prmn.citymanager.addMessage($(this)); });
251        Prmn.citymanager.loadData();
252    }
253});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.