Add loading and disable submit event while adding library folder

This commit is contained in:
hawken 2019-01-12 20:59:37 +00:00
parent 92aa36de0b
commit dfcad4992b

View File

@ -2,25 +2,43 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
"use strict"; "use strict";
function onSubmit(e) { function onSubmit(e) {
if (e.preventDefault(), e.stopPropagation(), 0 == pathInfos.length) return require(["alert"], function(alert) { e.preventDefault();
alert({ e.stopPropagation();
text: Globalize.translate("PleaseAddAtLeastOneFolder"),
type: "error" if (isCreating) return false;
})
}), !1; if (pathInfos.length == 0) {
var form = this, require(["alert"], function(alert) {
dlg = $(form).parents(".dialog")[0], alert({
name = $("#txtValue", form).val(), text: Globalize.translate("PleaseAddAtLeastOneFolder"),
type = $("#selectCollectionType", form).val(); type: "error"
"mixed" == type && (type = null); })
var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions")); });
return libraryOptions.PathInfos = pathInfos, ApiClient.addVirtualFolder(name, type, currentOptions.refresh, libraryOptions).then(function() { } else {
hasChanges = !0, dialogHelper.close(dlg) isCreating = true;
}, function() { loading.show();
require(["toast"], function(toast) {
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder")) var form = this,
}) dlg = $(form).parents(".dialog")[0],
}), !1 name = $("#txtValue", form).val(),
type = $("#selectCollectionType", form).val();
if (type == "mixed") type = null;
var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions"));
libraryOptions.PathInfos = pathInfos;
ApiClient.addVirtualFolder(name, type, currentOptions.refresh, libraryOptions).then(function() {
hasChanges = true;
isCreating = false;
loading.hide();
dialogHelper.close(dlg);
}, function() {
require(["toast"], function(toast) {
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"))
})
isCreating = false;
loading.hide();
});
}
return false;
} }
function getCollectionTypeOptionsHtml(collectionTypeOptions) { function getCollectionTypeOptionsHtml(collectionTypeOptions) {
@ -101,7 +119,8 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
} }
function onDialogClosed() { function onDialogClosed() {
loading.hide(), currentResolve(hasChanges) loading.hide();
currentResolve(hasChanges);
} }
function initLibraryOptions(dlg) { function initLibraryOptions(dlg) {
@ -119,7 +138,7 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
var template = this.response, var template = this.response,
dlg = dialogHelper.createDialog({ dlg = dialogHelper.createDialog({
size: "medium-tall", size: "medium-tall",
modal: !1, modal: false,
removeOnClose: !0, removeOnClose: !0,
scrollY: !1 scrollY: !1
}); });
@ -130,6 +149,6 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
}) })
} }
} }
var currentResolve, hasChanges, currentOptions, pathInfos = []; var currentResolve, hasChanges, currentOptions, pathInfos = [], isCreating = false;
return editor return editor
}); });