· 6 years ago · Oct 23, 2019, 02:32 PM
1"use strict";
2
3function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
5function _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); } }
6
7function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
8
9// Generated by CoffeeScript 2.4.1
10var API, BUS, MenuLeft, Modal, form_to_table_base_app_data, initApplication, main_app_data, modal_window_data, table_base_app_data;
11
12if (API === void 0 || API === null) {
13 API = window.API = '/api';
14}
15
16if (BUS === void 0 || BUS === null) {
17 BUS = window.BUS = new Vue();
18}
19
20MenuLeft =
21/*#__PURE__*/
22function () {
23 function MenuLeft() {
24 _classCallCheck(this, MenuLeft);
25
26 this.menu_left_dom = document.querySelector('#side-menu');
27 }
28
29 _createClass(MenuLeft, [{
30 key: "bindEvent",
31 value: function bindEvent() {
32 this.menu_left_dom.addEventListener('click', this.collapse.bind(this));
33 }
34 }, {
35 key: "collapse",
36 value: function collapse(event) {
37 var menu_inside, target;
38 console.log("E:", event);
39 target = event.target;
40
41 if (target.tagName !== 'LI') {
42 while (target.tagName !== 'LI') {
43 target = target.parentNode;
44 }
45 }
46
47 menu_inside = target.querySelector('ul');
48
49 if (menu_inside) {
50 this.toggle_menu_inside(menu_inside);
51 }
52 }
53 }, {
54 key: "toggle_menu_inside",
55 value: function toggle_menu_inside(m) {
56 if (m.classList.contains('collapse')) {
57 m.classList.remove('collapse');
58 } else {
59 m.classList.add('collapse');
60 }
61 }
62 }], [{
63 key: "new",
64 value: function _new() {
65 var menu_left;
66 menu_left = new MenuLeft();
67 menu_left.bindEvent();
68 return menu_left;
69 }
70 }]);
71
72 return MenuLeft;
73}();
74
75Modal =
76/*#__PURE__*/
77function () {
78 function Modal() {
79 _classCallCheck(this, Modal);
80 }
81
82 _createClass(Modal, [{
83 key: "bindEvent",
84 value: function bindEvent() {
85 BUS.$on('show_modal', this.modalModeEnable.bind(this));
86 BUS.$on('hide_modal', this.modalModeDisable.bind(this));
87 }
88 }, {
89 key: "modalModeEnable",
90 value: function modalModeEnable() {
91 document.body.style.overflow = 'hidden';
92 }
93 }, {
94 key: "modalModeDisable",
95 value: function modalModeDisable() {
96 document.body.style.overflow = '';
97 }
98 }], [{
99 key: "new",
100 value: function _new() {
101 var modal;
102 modal = new Modal();
103 modal.bindEvent();
104 return modal;
105 }
106 }]);
107
108 return Modal;
109}();
110
111modal_window_data = {
112 data: function data() {
113 var _data;
114
115 _data = {};
116 return _data;
117 },
118 props: [],
119 methods: {},
120 computed: {},
121 created: function created() {},
122 mounted: function mounted() {}
123};
124main_app_data = {
125 data: function data() {
126 var _data;
127
128 _data = {
129 table_base: {
130 name: 'Список мероприятий',
131 item_type: 'event',
132 head: ['Наименование', 'Департамент', 'В Плане', 'Бюджет', 'Лимит'],
133 data: []
134 }
135 };
136 return _data;
137 },
138 computed: {},
139 methods: {
140 show_form_to_table: function show_form_to_table() {
141 BUS.$emit('show_form_to_table_base');
142 BUS.$emit('show_modal');
143 }
144 },
145 created: function created() {},
146 mounted: function mounted() {}
147};
148table_base_app_data = {
149 data: function data() {
150 var _data;
151
152 _data = {
153 table: {
154 name: '',
155 item_type: null,
156 head: [],
157 data: []
158 }
159 };
160 return _data;
161 },
162 props: ["table"],
163 computed: {},
164 methods: {
165 show_form_to_table: function show_form_to_table() {
166 BUS.$emit('show_form_to_table_base');
167 BUS.$emit('show_modal');
168 },
169 edit_row: function edit_row(row) {
170 BUS.$emit('show_form_to_table_base_and_edit_row', row);
171 },
172 delete_row: function delete_row(row) {
173 var self;
174 self = this;
175 postJsonWithData(API, {
176 action: 'delete_event',
177 options: row
178 }, function (response) {
179 var index;
180
181 if (response.status) {
182 index = self.table.data.findIndex(function (item) {
183 if (row.id === item.id) {
184 return true;
185 } else {
186 return false;
187 }
188 });
189
190 if (index !== null && index > -1) {
191 self.table.data.splice(index, 1);
192 }
193 }
194 });
195 },
196 add_row: function add_row(row) {
197 var self;
198 self = this;
199 postJsonWithData(API, {
200 action: 'add_new_event',
201 options: row
202 }, function (response) {
203 if (response.status) {
204 self.table.data.push(response.data);
205 }
206 });
207 },
208 update_row: function update_row(row) {
209 var self;
210 self = this;
211 postJsonWithData(API, {
212 action: 'update_event',
213 options: row
214 }, function (response) {
215 var index, key, value;
216
217 if (response.status) {
218 index = self.table.data.findIndex(function (item) {
219 if (row.id === item.id) {
220 return true;
221 } else {
222 return false;
223 }
224 });
225
226 if (index !== null && index > -1) {
227 for (key in row) {
228 value = row[key];
229 self.table.data[index][key] = value;
230 }
231 }
232 }
233 });
234 },
235 load_and_show_data: function load_and_show_data() {
236 var self;
237 self = this;
238 postJsonWithData(API, {
239 action: 'load_table_base'
240 }, function (response) {
241 if (response.status) {
242 self.table.data = response.data;
243 }
244 });
245 }
246 },
247 created: function created() {},
248 mounted: function mounted() {
249 BUS.$on('send_to_table_base', this.add_row.bind(this));
250 BUS.$on('update_to_table_base', this.update_row.bind(this));
251 this.load_and_show_data();
252 }
253};
254form_to_table_base_app_data = {
255 data: function data() {
256 var _data;
257
258 _data = {
259 title: '',
260 cls: {
261 show: false,
262 fade: false,
263 "in": false
264 },
265 form: {
266 name: '',
267 department: '',
268 in_plane: false,
269 budget: '',
270 limit: ''
271 }
272 };
273 return _data;
274 },
275 props: [],
276 computed: {},
277 methods: {
278 show_form: function show_form() {
279 this.cls = {
280 show: true,
281 fade: true,
282 "in": true
283 };
284 },
285 close_form: function close_form() {
286 this.cls = {
287 show: false,
288 fade: false,
289 "in": false
290 };
291 BUS.$emit('hide_modal');
292 },
293 reset_form: function reset_form() {
294 return this.form = {
295 name: '',
296 department: '',
297 in_plane: false,
298 budget: '',
299 limit: ''
300 };
301 },
302 save_form: function save_form() {
303 var i, key, len, number, ref, self;
304 self = this;
305 ref = ['budget', 'limit'];
306
307 for (i = 0, len = ref.length; i < len; i++) {
308 key = ref[i];
309 number = parseFloat(this.form[key]);
310
311 if (isNaN(number)) {
312 this.form[key] = null;
313 } else {
314 this.form[key] = number;
315 }
316 }
317
318 if (this.form.id != null) {
319 this.update_row(this.form, function (result) {
320 if (result) {
321 self.close_form();
322 self.reset_form();
323 }
324 });
325 } else {
326 this.save_row(this.form, function (result) {
327 if (result) {
328 self.close_form();
329 return self.reset_form();
330 }
331 });
332 }
333 },
334 update_row: function update_row(row, cb) {
335 BUS.$emit('update_to_table_base', row);
336 cb(true);
337 },
338 save_row: function save_row(row, cb) {
339 BUS.$emit('send_to_table_base', row);
340 cb(true);
341 },
342 show_form_to_new_row: function show_form_to_new_row() {
343 this.title = 'Добавить мероприятие';
344 this.reset_form();
345 this.show_form();
346 },
347 show_form_and_edit_row: function show_form_and_edit_row(row) {
348 var key, value;
349 this.title = 'Изменить мероприятие';
350
351 for (key in row) {
352 value = row[key];
353 this.form[key] = value;
354 }
355
356 this.show_form();
357 }
358 },
359 created: function created() {},
360 mounted: function mounted() {
361 BUS.$on('show_form_to_table_base', this.show_form_to_new_row.bind(this));
362 BUS.$on('show_form_to_table_base_and_edit_row', this.show_form_and_edit_row.bind(this));
363 }
364};
365
366initApplication = function initApplication() {
367 var form_to_table_base_app, form_to_table_base_template_dom, main_app, main_app_template_dom, table_base_template_dom;
368 table_base_template_dom = document.querySelector('[data-vue-template="table base"]');
369
370 if (table_base_template_dom) {
371 table_base_app_data.template = table_base_template_dom.innerHTML;
372 Vue.component('table-base-app', table_base_app_data);
373 }
374
375 form_to_table_base_template_dom = document.querySelector('[data-vue-template="form to table base"]');
376
377 if (form_to_table_base_template_dom) {
378 form_to_table_base_app_data.template = form_to_table_base_template_dom.innerHTML;
379 Vue.component('form-to-table-base-app', form_to_table_base_app_data);
380 form_to_table_base_app = new Vue({
381 el: '#form-to-table-base-app'
382 });
383 }
384
385 main_app_template_dom = document.querySelector('[data-vue-template="main app"]');
386
387 if (main_app_template_dom) {
388 main_app_data.template = main_app_template_dom.innerHTML;
389 Vue.component('main-app', main_app_data);
390 main_app = new Vue({
391 el: '#main-app'
392 });
393 }
394};
395
396document.addEventListener('DOMContentLoaded', function (event) {
397 var menu_left, modal;
398 initApplication();
399 modal = Modal["new"]();
400 window.menu_left = menu_left = MenuLeft["new"]();
401});