move addFile to file-panel.js

pull/3094/head
yann300 7 years ago
parent 985e58f374
commit 1a9a559f87
  1. 24
      src/app/files/file-explorer.js
  2. 26
      src/app/panels/file-panel.js

@ -165,30 +165,6 @@ function fileExplorer (appAPI, files) {
var textUnderEdit = null
var textInRename = false
self.api = {}
self.api.addFile = function addFile (file) {
function loadFile () {
var fileReader = new FileReader()
fileReader.onload = function (event) {
if (helper.checkSpecialChars(file.name)) {
modalDialogCustom.alert('Special characters are not allowed')
return
}
var success = files.set(name, event.target.result)
if (!success) modalDialogCustom.alert('Failed to create file ' + name)
else self.events.trigger('focus', [name])
}
fileReader.readAsText(file)
}
var name = files.type + '/' + file.name
if (!files.exists(name)) {
loadFile()
} else {
modalDialogCustom.confirm(null, `The file ${name} already exists! Would you like to overwrite it?`, () => { loadFile() })
}
}
function getElement (path) {
var label = self.element.querySelector(`label[data-path="${path}"]`)
if (label) return getLiFrom(label)

@ -1,3 +1,4 @@
/* global FileReader */
var async = require('async')
var $ = require('jquery')
var yo = require('yo-yo')
@ -143,7 +144,30 @@ function filepanel (appAPI, filesProvider) {
// the files module. Please ask the user here if they want to overwrite
// a file and then just use `files.add`. The file explorer will
// pick that up via the 'fileAdded' event from the files module.
;[...this.files].forEach(fileExplorer.api.addFile)
;[...this.files].forEach((file) => {
var files = fileExplorer.files
function loadFile () {
var fileReader = new FileReader()
fileReader.onload = function (event) {
if (helper.checkSpecialChars(file.name)) {
modalDialogCustom.alert('Special characters are not allowed')
return
}
var success = files.set(name, event.target.result)
if (!success) modalDialogCustom.alert('Failed to create file ' + name)
else self.events.trigger('focus', [name])
}
fileReader.readAsText(file)
}
var name = files.type + '/' + file.name
if (!files.exists(name)) {
loadFile()
} else {
modalDialogCustom.confirm(null, `The file ${name} already exists! Would you like to overwrite it?`, () => { loadFile() })
}
})
}
// ----------------- resizeable ui ---------------

Loading…
Cancel
Save