move create macro logic from partial view macro file dialog to editor
This commit is contained in:
@@ -8,19 +8,18 @@
|
||||
var localizeCreateFolder = localizationService.localize("defaultdialog_createFolder");
|
||||
|
||||
vm.snippets = [];
|
||||
vm.snippet = "Empty";
|
||||
vm.createMacro = false;
|
||||
vm.createFolderError = "";
|
||||
vm.folderName = "";
|
||||
vm.fileName = "";
|
||||
|
||||
vm.showSnippets = false;
|
||||
vm.creatingFolder = false;
|
||||
vm.creatingFile = false;
|
||||
|
||||
vm.showCreateFolder = showCreateFolder;
|
||||
vm.showCreateFile = showCreateFile;
|
||||
vm.createFolder = createFolder;
|
||||
vm.createFile = createFile;
|
||||
vm.createFileWithoutMacro = createFileWithoutMacro;
|
||||
vm.showCreateFromSnippet = showCreateFromSnippet;
|
||||
vm.createFileFromSnippet = createFileFromSnippet;
|
||||
|
||||
function onInit() {
|
||||
codefileResource.getSnippets('partialViewMacros')
|
||||
@@ -33,12 +32,8 @@
|
||||
vm.creatingFolder = true;
|
||||
}
|
||||
|
||||
function showCreateFile() {
|
||||
vm.creatingFile = true;
|
||||
}
|
||||
|
||||
function createFolder(form) {
|
||||
if (formHelper.submitForm({scope: $scope, formCtrl: form, statusMessage: localizeCreateFolder})) {
|
||||
if (formHelper.submitForm({ scope: $scope, formCtrl: form, statusMessage: localizeCreateFolder })) {
|
||||
|
||||
codefileResource.createContainer("partialViewMacros", node.id, vm.folderName).then(function (saved) {
|
||||
|
||||
@@ -57,7 +52,7 @@
|
||||
|
||||
var section = appState.getSectionState("currentSection");
|
||||
|
||||
}, function(err) {
|
||||
}, function (err) {
|
||||
|
||||
vm.createFolderError = err;
|
||||
|
||||
@@ -71,29 +66,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
function createFile(form) {
|
||||
if (formHelper.submitForm({ scope: $scope, formCtrl: form, statusMessage: 'create file' })) {
|
||||
function createFile() {
|
||||
$location.path("/developer/partialviewmacros/edit/" + node.id).search("create", "true");
|
||||
navigationService.hideMenu();
|
||||
}
|
||||
|
||||
if (vm.createMacro) {
|
||||
var path = decodeURIComponent(node.id);
|
||||
macroResource.createPartialViewMacroWithFile(path, vm.fileName).then(function(created) {
|
||||
$location.path("/developer/partialviewmacros/edit/" + node.id).search("create", "true").search("name", vm.fileName).search("snippet", vm.snippet);
|
||||
navigationService.hideMenu();
|
||||
}, function(err) {
|
||||
vm.createFileError = err;
|
||||
function createFileWithoutMacro() {
|
||||
$location.path("/developer/partialviewmacros/edit/" + node.id).search("create", "true").search("nomacro", "true");
|
||||
navigationService.hideMenu();
|
||||
}
|
||||
|
||||
//show any notifications
|
||||
if (angular.isArray(err.data.notifications)) {
|
||||
for (var i = 0; i < err.data.notifications.length; i++) {
|
||||
notificationsService.showNotification(err.data.notifications[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$location.path("/developer/partialviewmacros/edit/" + node.id).search("create", "true").search("name", vm.fileName).search("snippet", vm.snippet);
|
||||
navigationService.hideMenu();
|
||||
}
|
||||
}
|
||||
function createFileFromSnippet(snippet) {
|
||||
$location.path("/developer/partialviewmacros/edit/" + node.id).search("create", "true").search("snippet", snippet.fileName);
|
||||
navigationService.hideMenu();
|
||||
}
|
||||
|
||||
function showCreateFromSnippet() {
|
||||
vm.showSnippets = true;
|
||||
}
|
||||
|
||||
onInit();
|
||||
|
||||
@@ -2,61 +2,56 @@
|
||||
|
||||
<div class="umbracoDialog umb-dialog-body with-footer">
|
||||
|
||||
<div class="umb-pane" ng-if="!vm.creatingFolder && !vm.creatingFile">
|
||||
|
||||
<h5><localize key="create_createUnder">Create an item under</localize> {{currentNode.name}}</h5>
|
||||
<div class="umb-pane" ng-if="!vm.creatingFolder">
|
||||
|
||||
<!-- Main options -->
|
||||
<ul class="umb-actions umb-actions-child">
|
||||
<li>
|
||||
<a href="" ng-click="vm.showCreateFile()" umb-auto-focus>
|
||||
<i class="large icon-article"></i>
|
||||
<span class="menu-label"><localize key="create_newPartialViewMacro">New partial view macro</localize></span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="" ng-click="vm.showCreateFolder()">
|
||||
<i class="large icon-folder"></i>
|
||||
<span class="menu-label"><localize key="general_folder"></localize></span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div ng-if="!vm.showSnippets">
|
||||
|
||||
</div>
|
||||
<h5><localize key="create_createUnder">Create an item under</localize> {{currentNode.name}}</h5>
|
||||
|
||||
<!-- Create file -->
|
||||
<div class="umb-pane" ng-if="vm.creatingFile">
|
||||
<form novalidate name="createFileForm"
|
||||
ng-submit="vm.createFile(createFileForm)"
|
||||
val-form-manager>
|
||||
<ul class="umb-actions umb-actions-child">
|
||||
<li>
|
||||
<a href="" ng-click="vm.createFile()" umb-auto-focus>
|
||||
<i class="large icon-article"></i>
|
||||
<span class="menu-label"><localize key="create_newPartialViewMacro">New partial view macro</localize></span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="" ng-click="vm.createFileWithoutMacro()">
|
||||
<i class="large icon-article"></i>
|
||||
<span class="menu-label"><localize key="create_newPartialViewMacroNoMacro">New partial view macro (without macro)</localize></span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="" ng-click="vm.showCreateFromSnippet()">
|
||||
<i class="large icon-article"></i>
|
||||
<span class="menu-label"><localize key="create_newPartialViewMacroFromSnippet">>New partial view macro from snippet</localize></span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="" ng-click="vm.showCreateFolder()">
|
||||
<i class="large icon-folder"></i>
|
||||
<span class="menu-label"><localize key="general_folder"></localize></span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div ng-show="vm.createFileError">
|
||||
<h5 class="text-error">{{vm.createFileError.errorMsg}}</h5>
|
||||
<p class="text-error">{{vm.createFileError.data.message}}</p>
|
||||
</div>
|
||||
<!-- Snippets list -->
|
||||
<div ng-if="vm.showSnippets">
|
||||
|
||||
<umb-control-group label="Enter a file name" hide-label="false">
|
||||
<input type="text" name="fileName" ng-model="vm.fileName" class="umb-textstring textstring input-block-level" umb-auto-focus required no-dirty-check />
|
||||
<h5>Select snippet</h5>
|
||||
|
||||
<div>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="createMacro" ng-model="vm.createMacro" ng-true-value="true" ng-false-value="false" no-dirty-check/>
|
||||
Create corresponding macro
|
||||
</label>
|
||||
</div>
|
||||
</umb-control-group>
|
||||
<ul class="umb-actions umb-actions-child">
|
||||
<li ng-repeat="snippet in vm.snippets">
|
||||
<a href="" ng-click="vm.createFileFromSnippet(snippet)" style="padding-top: 6px; padding-bottom: 6px;">
|
||||
<i class="icon-article" style="font-size: 20px;"></i>
|
||||
<span class="menu-label" style="margin-left: 0; padding-left: 5px;">{{ snippet.name }}</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<umb-control-group label="Select a snippet (or create an empty file)" hide-label="false">
|
||||
|
||||
<select name="snippet"
|
||||
class="umb-editor umb-dropdown"
|
||||
ng-model="vm.snippet"
|
||||
ng-options="snippet.fileName as snippet.name for snippet in vm.snippets"></select>
|
||||
|
||||
</umb-control-group>
|
||||
|
||||
<button type="submit" class="btn btn-primary"><localize key="general_create">Create</localize></button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Create folder -->
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function partialViewMacrosEditController($scope, $routeParams, codefileResource, assetsService, notificationsService, editorState, navigationService, appState, macroService, angularHelper, $timeout, contentEditingHelper, localizationService, templateHelper) {
|
||||
function partialViewMacrosEditController($scope, $routeParams, codefileResource, assetsService, notificationsService, editorState, navigationService, appState, macroService, angularHelper, $timeout, contentEditingHelper, localizationService, templateHelper, macroResource) {
|
||||
|
||||
var vm = this;
|
||||
var localizeSaving = localizationService.localize("general_saving");
|
||||
@@ -41,32 +41,23 @@
|
||||
redirectOnFailure: false,
|
||||
rebindCallback: function (orignal, saved) {}
|
||||
}).then(function (saved) {
|
||||
|
||||
localizationService.localize("speechBubbles_partialViewSavedHeader").then(function (headerValue) {
|
||||
localizationService.localize("speechBubbles_partialViewSavedText").then(function(msgValue) {
|
||||
notificationsService.success(headerValue, msgValue);
|
||||
|
||||
// create macro if needed
|
||||
if($routeParams.create && $routeParams.nomacro !== "true") {
|
||||
macroResource.createPartialViewMacroWithFile(saved.path, saved.name).then(function(created) {
|
||||
completeSave(saved);
|
||||
}, function(err) {
|
||||
//show any notifications
|
||||
if (angular.isArray(err.data.notifications)) {
|
||||
for (var i = 0; i < err.data.notifications.length; i++) {
|
||||
notificationsService.showNotification(err.data.notifications[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//check if the name changed, if so we need to redirect
|
||||
if (vm.partialViewMacro.id !== saved.id) {
|
||||
contentEditingHelper.redirectToRenamedContent(saved.id);
|
||||
} else {
|
||||
completeSave(saved);
|
||||
}
|
||||
else {
|
||||
vm.page.saveButtonState = "success";
|
||||
vm.partialViewMacro = saved;
|
||||
|
||||
//sync state
|
||||
editorState.set(vm.partialViewMacro);
|
||||
|
||||
// normal tree sync
|
||||
navigationService.syncTree({ tree: "partialViewMacros", path: vm.partialViewMacro.path, forceReload: true }).then(function (syncArgs) {
|
||||
vm.page.menu.currentNode = syncArgs.node;
|
||||
});
|
||||
|
||||
// clear $dirty state on form
|
||||
setFormState("pristine");
|
||||
}
|
||||
}, function (err) {
|
||||
|
||||
vm.page.saveButtonState = "error";
|
||||
@@ -81,6 +72,36 @@
|
||||
|
||||
}
|
||||
|
||||
function completeSave(saved) {
|
||||
|
||||
localizationService.localize("speechBubbles_partialViewSavedHeader").then(function (headerValue) {
|
||||
localizationService.localize("speechBubbles_partialViewSavedText").then(function (msgValue) {
|
||||
notificationsService.success(headerValue, msgValue);
|
||||
});
|
||||
});
|
||||
|
||||
//check if the name changed, if so we need to redirect
|
||||
if (vm.partialViewMacro.id !== saved.id) {
|
||||
contentEditingHelper.redirectToRenamedContent(saved.id);
|
||||
}
|
||||
else {
|
||||
vm.page.saveButtonState = "success";
|
||||
vm.partialViewMacro = saved;
|
||||
|
||||
//sync state
|
||||
editorState.set(vm.partialViewMacro);
|
||||
|
||||
// normal tree sync
|
||||
navigationService.syncTree({ tree: "partialViewMacros", path: vm.partialViewMacro.path, forceReload: true }).then(function (syncArgs) {
|
||||
vm.page.menu.currentNode = syncArgs.node;
|
||||
});
|
||||
|
||||
// clear $dirty state on form
|
||||
setFormState("pristine");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function openInsertOverlay() {
|
||||
|
||||
vm.insertOverlay = {
|
||||
|
||||
Reference in New Issue
Block a user