-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
form.js
298 lines (247 loc) · 9.47 KB
/
form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
export default {
methods: {
/* Main */
getFiles(prev_folder = null, prev_file = null) {
this.files.next = null
this.resetInput(['sortName', 'filterName', 'selectedFile', 'currentFileIndex'])
this.noFiles('hide')
this.destroyPlyr()
if (!this.loading_files) {
this.isLoading = true
this.infoSidebar = false
this.loadingFiles('show')
}
// get data
return axios.post(this.routes.files, {
path: this.clearDblSlash(`/${this.folders.join('/')}`)
}).then(({data}) => {
// folder doesnt exist
if (data.error) {
return this.showNotif(data.error, 'danger')
}
// return data
this.files = {
path: data.files.path,
items: data.files.items.data,
next: data.files.items.next_page_url
}
this.lockedList = data.locked
this.filesListCheck(prev_folder, prev_file)
}).catch((err) => {
console.error(err)
this.isLoading = false
this.loadingFiles('hide')
this.ajaxError()
})
},
loadPaginatedFiles($state) {
return axios.post(this.files.next, {
path: this.files.path || '/'
}).then(({data}) => {
let next_page = data.files.items.next_page_url
// add extra items
this.files.items = this.files.items.concat(data.files.items.data)
this.files.next = next_page
next_page
? $state.loaded()
: $state.complete()
}).catch((err) => {
console.error(err)
this.ajaxError()
})
},
filesListCheck(prev_folder, prev_file) {
let files = this.files.items
if (this.hideExt.length) {
files = files.filter((e) => !this.checkForHiddenExt(e))
}
if (this.hidePath.length) {
files = files.filter((e) => !this.checkForHiddenPath(e))
}
// we have files
if (this.allItemsCount) {
// check for prev
if (prev_file || prev_folder) {
files.some((e, i) => {
if (
(prev_folder && e.name == prev_folder) ||
(prev_file && e.name == prev_file)
) {
return this.currentFileIndex = i
}
})
}
this.$nextTick(() => {
// no prev found
this.currentFileIndex
? this.selectFirst(this.currentFileIndex)
: this.selectFirst()
// update search
if (this.searchFor) {
this.updateSearchCount()
}
})
}
this.isLoading = false
this.loadingFiles('hide')
this.smallScreenHelper()
// we dont have files & user clicked the "refresh btn"
this.$nextTick(() => {
if (!this.allItemsCount && !this.no_files) {
this.noFiles('show')
}
})
},
/* Tool-Bar */
NewFolderForm(event) {
let folder_name = this.newFolderName
let path = this.files.path
if (!folder_name) {
return this.showNotif(this.trans('no_val'), 'warning')
}
this.toggleLoading()
axios.post(event.target.action, {
path: path,
new_folder_name: folder_name
}).then(({data}) => {
this.toggleLoading()
this.toggleModal()
this.resetInput('newFolderName')
if (data.message) {
return this.showNotif(data.message, 'danger')
}
path = path || '/'
let new_name = data.new_folder_name
let msg = this.restrictModeIsOn
? `"${new_name}"`
: `"${new_name}" at "${path}"`
this.showNotif(`${this.trans('create_success')} ${msg}`)
this.isBulkSelecting() ? this.blkSlct() : false
this.getFiles(new_name)
}).catch((err) => {
console.error(err)
this.ajaxError()
})
},
// rename
RenameFileForm(event) {
let selected = this.selectedFile
let changed = this.newFilename
let filename = selected.name
let ext = this.getExtension(filename)
let newFilename = ext == null ? changed : `${changed}.${ext}`
if (!changed) {
return this.showNotif(this.trans('no_val'), 'warning')
}
let files = this.checkForNestedLockedItems([selected])
if (!files.length) {
return this.toggleModal()
}
// remove from move list if found
if (this.inMovableList()) {
this.removeFromMovableList(this.movableList.indexOf(selected))
}
this.toggleLoading()
axios.post(event.target.action, {
file: selected,
path: this.files.path,
new_filename: newFilename
}).then(({data}) => {
this.toggleLoading()
this.toggleModal()
if (data.message) {
return this.showNotif(data.message, 'danger')
}
let savedName = data.new_filename
this.showNotif(`${this.trans('rename_success')} "${filename}" to "${savedName}"`)
selected.name = savedName
selected.path = selected.path.replace(filename, savedName)
}).catch((err) => {
console.error(err)
this.ajaxError()
})
},
// delete
DeleteFileForm(event) {
let gls_item = this.global_search_item
let files = this.checkForNestedLockedItems(
gls_item
? [gls_item]
: this.delOrMoveList()
)
if (!files.length) {
return this.toggleModal()
}
this.toggleLoading()
axios.post(event.target.action, {
path: this.files.path,
deleted_files: files
}).then(({data}) => {
this.toggleLoading()
this.toggleModal()
if (!this.globalSearchPanelIsVisible) {
data.map((item) => {
if (!item.success) {
return this.showNotif(item.message, 'danger')
}
let path = item.path
this.showNotif(`${this.trans('delete_success')} "${item.name}"`)
this.removeFromLists(path)
})
this.isBulkSelecting()
? this.blkSlct()
: this.allItemsCount
? this.selectFirst()
: false
this.$nextTick(() => {
if (this.searchFor) {
this.searchItemsCount = this.filesList.length
}
})
} else {
data.map((item) => {
EventHub.fire('global-search-deleted', this.global_search_item.path)
this.resetInput('global_search_item')
!item.success
? this.showNotif(item.message, 'danger')
: this.showNotif(`${this.trans('delete_success')} "${item.name}"`)
})
}
this.db('clr')
}).catch((err) => {
console.error(err)
this.ajaxError()
})
},
/* Ops */
removeFromLists(path, reset = true) {
if (this.filteredItemsCount) {
this.updateListsRemove(this.filterdFilesList, path)
}
if (this.movableItemsCount) {
this.updateListsRemove(this.movableList, path)
}
if (this.dirBookmarks.length) {
this.updateListsRemove(this.dirBookmarks, path, 'dir')
}
this.updateListsRemove(this.files.items, path)
if (reset) {
this.resetInput(['selectedFile', 'currentFileIndex'])
}
},
updateListsRemove(list, path, field_name = 'storage_path') {
if (field_name) {
return list.some((e, i) => {
if (e[field_name] == path) {
list.splice(i, 1)
}
})
}
return list.some((e, i) => {
if (e == path) {
list.splice(i, 1)
}
})
}
}
}