From 0c350e9cc1737b8bbfccff503bec0e5b72d89919 Mon Sep 17 00:00:00 2001 From: perploug Date: Thu, 26 Sep 2013 15:35:28 +0200 Subject: [PATCH] Content name directive refactor --- .../editors/umbcontentname.directive.js | 46 +++++++++++++++++ .../directives/umbcontentname.directive.js | 50 ------------------- .../views/content/content.edit.controller.js | 29 ++++++++++- .../src/views/content/edit.html | 11 ++-- .../views/directives/umb-content-name.html | 11 +++- 5 files changed, 91 insertions(+), 56 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/common/directives/editors/umbcontentname.directive.js delete mode 100644 src/Umbraco.Web.UI.Client/src/common/directives/umbcontentname.directive.js diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/editors/umbcontentname.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/editors/umbcontentname.directive.js new file mode 100644 index 0000000000..5ccfeb047b --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/directives/editors/umbcontentname.directive.js @@ -0,0 +1,46 @@ +/** +* @ngdoc directive +* @name umbraco.directives.directive:umbContentName +* @restrict E +* @function +* @description +* Used by editors that require naming an entity. Shows a textbox/headline with a required validator within it's own form. +**/ +angular.module("umbraco.directives") + .directive('umbContentName', function ($timeout) { + return { + require: "ngModel", + restrict: 'E', + replace: true, + templateUrl: 'views/directives/umb-content-name.html', + scope: { + placeholder: '@placeholder', + model: '=ngModel' + }, + link: function(scope, element, attrs, ngModel) { + + ngModel.$render = function(){ + $timeout(function(){ + if(scope.model === ""){ + scope.goEdit(); + } + }, 100); + }; + + scope.goEdit = function(){ + scope.editMode = true; + $timeout(function(){ + element.find("input").focus(); + }, 100); + }; + + scope.exitEdit = function(){ + scope.editMode = false; + + if(scope.model === ""){ + scope.model = "Empty..."; + } + }; + } + }; + }); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/umbcontentname.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/umbcontentname.directive.js deleted file mode 100644 index 3245950795..0000000000 --- a/src/Umbraco.Web.UI.Client/src/common/directives/umbcontentname.directive.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @ngdoc directive -* @name umbraco.directives.directive:umbContentName -* @restrict E -* @function -* @description -* Used by editors that require naming an entity. Shows a textbox/headline with a required validator within it's own form. -**/ -angular.module("umbraco.directives") - .directive('umbContentName', function ($timeout) { - return { - require: "ngModel", - restrict: 'E', - replace: true, - templateUrl: 'views/directives/umb-content-name.html', - scope: { - placeholder: '@placeholder', - model: '=ngModel' - }, - link: function(scope, element, attrs, modelCtrl) { - - var input = $(element).find('input'); - var h1 = $(element).find('h1'); - input.hide(); - - - input.on("blur", function () { - //Don't hide the input field if there is no value in it - var val = input.val() || "empty"; - input.hide(); - - h1.text(val); - h1.show(); - }); - - - h1.on("click", function () { - h1.hide(); - input.show().focus(); - }); - - $timeout(function(){ - if(!scope.model){ - h1.hide(); - input.show().focus(); - } - }, 500); - } - }; - }); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js index 8d04c4531c..28746df55e 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js @@ -6,7 +6,7 @@ * @description * The controller for the content editor */ -function ContentEditController($scope, $routeParams, contentResource, notificationsService, angularHelper, serverValidationManager, contentEditingHelper, fileManager, editorContextService) { +function ContentEditController($scope, $routeParams, $q, $timeout, $window, contentResource, notificationsService, angularHelper, serverValidationManager, contentEditingHelper, fileManager, editorContextService) { //initialize the file manager fileManager.clearFiles(); @@ -68,7 +68,28 @@ function ContentEditController($scope, $routeParams, contentResource, notificati }); }; + $scope.preview = function(content){ + if(!content.id){ + $scope.save().then(function(data){ + $window.open('dialogs/preview.aspx?id='+data.id,'umbpreview'); + }); + }else{ + $window.open('dialogs/preview.aspx?id='+content.id,'umbpreview'); + } + }; + + $scope.setStatus = function(status){ + //add localization + $scope.status = status; + $timeout(function(){ + $scope.status = undefined; + }, 2500); + }; + $scope.save = function () { + var deferred = $q.defer(); + + $scope.setStatus("Saving..."); $scope.$broadcast("saving", { scope: $scope }); var currentForm = angularHelper.getRequiredCurrentForm($scope); @@ -86,6 +107,8 @@ function ContentEditController($scope, $routeParams, contentResource, notificati newContent: data, rebindCallback: contentEditingHelper.reBindChangedProperties($scope.content, data) }); + + deferred.resolve(data); }, function (err) { contentEditingHelper.handleSaveError({ @@ -93,7 +116,11 @@ function ContentEditController($scope, $routeParams, contentResource, notificati allNewProps: contentEditingHelper.getAllProps(err.data), allOrigProps: contentEditingHelper.getAllProps($scope.content) }); + + deferred.reject(err); }); + + return deferred.promise; }; } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/edit.html b/src/Umbraco.Web.UI.Client/src/views/content/edit.html index 18cdfebb66..9bdc494d50 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/edit.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/edit.html @@ -13,13 +13,18 @@
+
-
- Preview page - data-hotkey="ctrl+s">Preview page +
+
+ +
+ Publish diff --git a/src/Umbraco.Web.UI.Client/src/views/directives/umb-content-name.html b/src/Umbraco.Web.UI.Client/src/views/directives/umb-content-name.html index d98664bbf0..49d53e3693 100644 --- a/src/Umbraco.Web.UI.Client/src/views/directives/umb-content-name.html +++ b/src/Umbraco.Web.UI.Client/src/views/directives/umb-content-name.html @@ -2,8 +2,15 @@ -

{{model}}

- {{model}} + +