diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/buttons/umbbutton.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/buttons/umbbutton.directive.js
index 642ba3b529..047d67ffef 100644
--- a/src/Umbraco.Web.UI.Client/src/common/directives/components/buttons/umbbutton.directive.js
+++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/buttons/umbbutton.directive.js
@@ -67,103 +67,107 @@ Use this directive to render an umbraco button. The directive can be used to gen
@param {boolean=} disabled Set to true to disable the button.
**/
-(function() {
- 'use strict';
+(function () {
+ 'use strict';
- function ButtonDirective($timeout) {
+ angular
+ .module('umbraco.directives')
+ .component('umbButton', {
+ transclude: true,
+ templateUrl: 'views/components/buttons/umb-button.html',
+ controller: UmbButtonController,
+ controllerAs: 'vm',
+ bindings: {
+ action: "&?",
+ href: "@?",
+ type: "@",
+ buttonStyle: "@?",
+ state: "",
+ shortcut: "@?",
+ shortcutWhenHidden: "@",
+ label: "@?",
+ labelKey: "@?",
+ icon: "@?",
+ disabled: "",
+ size: "@?",
+ alias: "@?"
+ }
+ });
- function link(scope, el, attr, ctrl) {
+ UmbButtonController.$inject = ['$timeout'];
- scope.style = null;
- scope.innerState = "init";
+ function UmbButtonController($timeout) {
- function activate() {
+ var vm = this;
- scope.blockElement = false;
+ vm.$onInit = onInit;
+ vm.$onChanges = onChanges;
+ vm.clickButton = clickButton;
- if (scope.buttonStyle) {
+ function onInit() {
+
+ vm.blockElement = false;
+ vm.style = null;
+ vm.innerState = "init";
+
+ if (vm.buttonStyle) {
// make it possible to pass in multiple styles
- if(scope.buttonStyle.startsWith("[") && scope.buttonStyle.endsWith("]")) {
+ if(vm.buttonStyle.startsWith("[") && vm.buttonStyle.endsWith("]")) {
// when using an attr it will always be a string so we need to remove square brackets
// and turn it into and array
- var withoutBrackets = scope.buttonStyle.replace(/[\[\]']+/g,'');
+ var withoutBrackets = vm.buttonStyle.replace(/[\[\]']+/g,'');
// split array by , + make sure to catch whitespaces
var array = withoutBrackets.split(/\s?,\s?/g);
angular.forEach(array, function(item){
- scope.style = scope.style + " " + "btn-" + item;
+ vm.style = vm.style + " " + "btn-" + item;
if(item === "block") {
- scope.blockElement = true;
+ vm.blockElement = true;
}
});
} else {
- scope.style = "btn-" + scope.buttonStyle;
- if(scope.buttonStyle === "block") {
- scope.blockElement = true;
+ vm.style = "btn-" + vm.buttonStyle;
+ if(vm.buttonStyle === "block") {
+ vm.blockElement = true;
}
}
}
- }
+ }
- activate();
+ function onChanges(changes) {
- var unbindStateWatcher = scope.$watch('state', function(newValue, oldValue) {
- if (newValue) {
- scope.innerState = newValue;
+ // watch for state changes
+ if (changes.state) {
+ if(changes.state.currentValue) {
+ vm.innerState = changes.state.currentValue;
+ }
+ if (changes.state.currentValue === 'success' || changes.state.currentValue === 'error') {
+ // set the state back to 'init' after a success or error
+ $timeout(function () {
+ vm.innerState = 'init';
+ }, 2000);
+ }
}
- if (newValue === 'success' || newValue === 'error') {
- $timeout(function() {
- scope.innerState = 'init';
- }, 2000);
+ // watch for disabled changes
+ if(changes.disabled) {
+ if(changes.disabled.currentValue) {
+ vm.disabled = changes.disabled.currentValue;
+ }
}
+ }
- });
-
- scope.clickButton = function(event) {
- if(scope.action) {
- scope.action({$event: event});
+ function clickButton(event) {
+ if(vm.action) {
+ vm.action({$event: event});
}
- };
+ }
- scope.$on('$destroy', function() {
- unbindStateWatcher();
- });
-
- }
-
- var directive = {
- transclude: true,
- restrict: 'E',
- replace: true,
- templateUrl: 'views/components/buttons/umb-button.html',
- link: link,
- scope: {
- action: "&?",
- href: "@?",
- type: "@",
- buttonStyle: "@?",
- state: "=?",
- shortcut: "@?",
- shortcutWhenHidden: "@",
- label: "@?",
- labelKey: "@?",
- icon: "@?",
- disabled: "=",
- size: "@?",
- alias: "@?"
- }
- };
-
- return directive;
-
- }
-
- angular.module('umbraco.directives').directive('umbButton', ButtonDirective);
+ }
})();
diff --git a/src/Umbraco.Web.UI.Client/src/views/components/buttons/umb-button.html b/src/Umbraco.Web.UI.Client/src/views/components/buttons/umb-button.html
index 383c3bb067..a214a5a58f 100644
--- a/src/Umbraco.Web.UI.Client/src/views/components/buttons/umb-button.html
+++ b/src/Umbraco.Web.UI.Client/src/views/components/buttons/umb-button.html
@@ -1,35 +1,34 @@
-