|
4 | 4 | import StreamBlock from '@/components/StreamBlock.vue' |
5 | 5 | import AbstractBlock from '@/components/AbstractBlock.vue' |
6 | 6 |
|
7 | | - let |
8 | | - text_area, |
9 | | - delete_blocks_from_db, |
10 | | - popup_size; |
11 | | -
|
12 | 7 | function id_to_windowname(text) { |
13 | 8 | text = text.replace(/\./g, '__dot__'); |
14 | 9 | text = text.replace(/\-/g, '__dash__'); |
|
31 | 26 | stream: [], // [{model_name: ..., id: ...}, ...] |
32 | 27 | model_info: {}, // {'model_name': model.__doc__}, |
33 | 28 | base_admin_url: "", |
34 | | - stream_texts: window.stream_texts |
| 29 | + stream_texts: window.stream_texts, |
| 30 | + text_area: null, |
| 31 | + delete_blocks_from_db: null, |
| 32 | + popup_size: null |
35 | 33 | } |
36 | 34 | }, |
37 | 35 | beforeMount: function() { |
38 | | - text_area = this.app_node.querySelector('textarea') |
39 | | - delete_blocks_from_db = Boolean(text_area.hasAttribute('delete_blocks_from_db')) |
40 | | - popup_size = text_area.dataset.popup_size ? JSON.parse(text_area.dataset.popup_size) : [1000, 500] |
| 36 | + this.text_area = this.app_node.querySelector('textarea') |
| 37 | + this.delete_blocks_from_db = Boolean(this.text_area.hasAttribute('delete_blocks_from_db')) |
| 38 | + this.popup_size = this.text_area.dataset.popup_size ? JSON.parse(this.text_area.dataset.popup_size) : [1000, 500] |
41 | 39 |
|
42 | | - this.base_admin_url = text_area.getAttribute('base_admin_url') |
43 | | - this.stream = JSON.parse(text_area.innerHTML) |
44 | | - this.model_info = JSON.parse(text_area.getAttribute('model_list_info')) |
| 40 | + this.base_admin_url = this.text_area.getAttribute('base_admin_url') |
| 41 | + this.stream = JSON.parse(this.text_area.innerHTML) |
| 42 | + this.model_info = JSON.parse(this.text_area.getAttribute('model_list_info')) |
45 | 43 |
|
46 | 44 | if (this.stream.length && !this.stream[0].hasOwnProperty('collapsed')) { |
47 | 45 | this.setAllCollapsed(false) |
48 | 46 | } |
49 | 47 | |
50 | 48 | // delete removed instances from db when form submit |
51 | | - if ( delete_blocks_from_db ) { |
| 49 | + if ( this.delete_blocks_from_db ) { |
52 | 50 | let app = this |
53 | | - django.jQuery('input[type="submit"]', text_area.closest('form')).on('click', function(e){ |
| 51 | + django.jQuery('input[type="submit"]', this.text_area.closest('form')).on('click', function(e){ |
54 | 52 | if ( !app.will_removed.length ) return; |
55 | 53 | |
56 | 54 | e.preventDefault(); |
|
80 | 78 |
|
81 | 79 | }); // EventListener |
82 | 80 | } |
83 | | -
|
84 | 81 | }, |
85 | 82 | methods: { |
86 | 83 | isAbstract: function(block) { |
|
173 | 170 | let triggeringLink = e.target; |
174 | 171 | let name = id_to_windowname(triggeringLink.id.replace(/^(change|add|delete)_/, '')); |
175 | 172 | let href = triggeringLink.href; |
176 | | - let win = window.open(href, name, 'height=' + popup_size[1] + ',width=' + popup_size[0] + ',resizable=yes,scrollbars=yes'); |
| 173 | + let win = window.open(href, name, 'height=' + this.popup_size[1] + ',width=' + this.popup_size[0] + ',resizable=yes,scrollbars=yes'); |
177 | 174 | win.focus(); |
178 | 175 | return false; |
179 | 176 | } |
180 | 177 | }, |
181 | 178 | watch: { |
182 | 179 | stream: { |
183 | 180 | handler(nv) { |
184 | | - text_area.innerHTML = JSON.stringify(nv.map(function(i){ |
| 181 | + this.text_area.innerHTML = JSON.stringify(nv.map(function(i){ |
185 | 182 | // return only fields that in initial data |
186 | 183 | return { |
187 | 184 | unique_id: i.unique_id, |
|
190 | 187 | options: i.options, |
191 | 188 | collapsed: i.collapsed |
192 | 189 | }; |
193 | | - })); |
| 190 | + })); |
194 | 191 | }, |
195 | 192 | deep: true |
196 | 193 | } |
|
210 | 207 | </div> |
211 | 208 |
|
212 | 209 | <div class="streamfield-models"> |
213 | | - <draggable v-model="stream" group="stream" handle=".block-move" item-key="unique_id"> |
| 210 | + <draggable v-model="stream" :group="app_node.id" handle=".block-move" item-key="unique_id"> |
214 | 211 | <template #item="{element: block}"> |
215 | 212 | <StreamBlock v-if="!isAbstract(block)" :block="block" :ref="block.unique_id"/> |
216 | 213 | <AbstractBlock v-else :block="block" :ref="block.unique_id" /> |
|
0 commit comments