|
1 | 1 | import { Controller } from 'stimulus'; |
2 | 2 | import { events } from "../mixins/events"; |
3 | | -import axios from 'axios'; |
4 | | -import CodeMirror from 'codemirror'; |
5 | | -import 'codemirror/mode/javascript/javascript.js' |
6 | | - |
7 | 3 |
|
8 | 4 | export default class extends Controller { |
9 | 5 | static targets = ["moveButton", "listItem", "errors"]; |
10 | 6 |
|
11 | | - |
12 | | - initialize() { |
13 | | - |
14 | | - // console.log(CodeMirror) |
15 | | - |
16 | | - // var myCodeMirror = CodeMirror(this.element, { |
17 | | - // value: "function myScript(){return 100;}\n", |
18 | | - // mode: "javascript" |
19 | | - // }); |
20 | | - |
21 | | - const csrfToken = document.querySelector("meta[name=csrf-token]").content |
22 | | - axios.defaults.headers.common['X-CSRF-Token'] = csrfToken |
23 | | - } |
24 | | - |
25 | 7 | connect() { |
26 | 8 | events(this) |
27 | | - |
28 | | - if (this.hasMoveButtonTarget) { |
29 | | - this.moveButtonTarget.disabled = true |
30 | | - } |
31 | 9 | } |
32 | 10 |
|
33 | 11 | update(event) { |
@@ -82,92 +60,11 @@ export default class extends Controller { |
82 | 60 | this.emitEvent('close-alert') |
83 | 61 | } |
84 | 62 |
|
85 | | - modal_search(event) { |
86 | | - const searchTerm = event.target.value.toLowerCase(); |
87 | | - |
88 | | - this.listItemTargets.forEach(item => { |
89 | | - const folderName = item.getAttribute('data-filter-key').toLowerCase() |
90 | | - |
91 | | - if (folderName.includes(searchTerm)) { |
92 | | - item.classList.remove('hidden') |
93 | | - } else { |
94 | | - item.classList.add('hidden') |
95 | | - } |
96 | | - }) |
97 | | - } |
98 | | - |
99 | | - select_folder(event) { |
100 | | - const folderId = event.target.dataset.folderId |
101 | | - |
102 | | - if (folderId === this.selectedFolderId ) { return } |
103 | | - |
104 | | - const previousSelection = this.element.getElementsByClassName('move-snippet--item-selected')[0] |
105 | | - |
106 | | - if (previousSelection) { |
107 | | - previousSelection.classList.remove('move-snippet--item-selected') |
108 | | - previousSelection.classList.add('move-snippet--item') |
109 | | - const checkmark = document.getElementById('selected-checkmark') |
110 | | - const checkmarkClone = checkmark.cloneNode(true) |
111 | | - |
112 | | - checkmark.remove() |
113 | | - |
114 | | - event.target.insertAdjacentElement("beforeend", checkmarkClone) |
115 | | - } else { |
116 | | - event.target.insertAdjacentHTML('beforeend', '<img id="selected-checkmark" src="/icons/checked.svg" width="14">') |
117 | | - } |
118 | | - |
119 | | - event.target.classList.add('move-snippet--item-selected') |
120 | | - |
121 | | - this.selectedFolderId = folderId |
122 | | - |
123 | | - if (this.selectedFolderId === this.originalFolderId) { |
124 | | - this.moveButtonTarget.disabled = true |
125 | | - this.moveButtonTarget.classList.remove('button--cta-primary') |
126 | | - this.moveButtonTarget.classList.add('button--disabled') |
127 | | - } else { |
128 | | - this.moveButtonTarget.disabled = false |
129 | | - this.moveButtonTarget.classList.remove('button--disabled') |
130 | | - this.moveButtonTarget.classList.add('button--cta-primary') |
131 | | - } |
132 | | - } |
133 | | - |
134 | | - file() { |
135 | | - axios.post(this.confirmPath, { folder_id: this.selectedFolderId }, { headers: { 'accept': 'application/json' } }) |
136 | | - .then(res => { |
137 | | - this.toast.display(res.data.message) |
138 | | - this.emitEvent('close-modal'); |
139 | | - }) |
140 | | - .catch(error => { |
141 | | - console.error(error) |
142 | | - this.toast.display('Unable to file snippet') |
143 | | - }) |
144 | | - } |
145 | | - |
146 | 63 | get url() { |
147 | 64 | return this.data.get('url') |
148 | 65 | } |
149 | 66 |
|
150 | | - get selectedFolderId() { |
151 | | - return this.data.get('selectedFolderId') |
152 | | - } |
153 | | - |
154 | | - get originalFolderId() { |
155 | | - return this.data.get('originalFolderId') |
156 | | - } |
157 | | - |
158 | 67 | get toast() { |
159 | 68 | return document.getElementById('toast').toast |
160 | 69 | } |
161 | | - |
162 | | - get confirmPath() { |
163 | | - return this.data.get('confirmPath') |
164 | | - } |
165 | | - |
166 | | - set confirmPath(newPath) { |
167 | | - return this.data.set('confirmPath', newPath) |
168 | | - } |
169 | | - |
170 | | - set selectedFolderId(folderId) { |
171 | | - return this.data.set('selectedFolderId', folderId) |
172 | | - } |
173 | 70 | } |
0 commit comments