From bb05ce89c9ac407d4d2d7cef1c91551e7129b942 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 29 Apr 2015 14:17:51 -0400 Subject: [PATCH] (js) Improve Dialog service --- UI/WebServerResources/js/Common/ui-desktop.js | 96 +++++++++++-------- 1 file changed, 56 insertions(+), 40 deletions(-) diff --git a/UI/WebServerResources/js/Common/ui-desktop.js b/UI/WebServerResources/js/Common/ui-desktop.js index de83fbcac..a2b8dfa39 100644 --- a/UI/WebServerResources/js/Common/ui-desktop.js +++ b/UI/WebServerResources/js/Common/ui-desktop.js @@ -18,30 +18,19 @@ * @param {string} content */ Dialog.alert = function(title, content) { - this.$modal.open({ - template: - '

' + - '

' + - '' + l('OK') + '' + - '', - windowClass: 'small', - controller: function($scope, $modalInstance) { - $scope.title = title; - $scope.content = content; - $scope.closeModal = function() { - $modalInstance.close(); - }; - } - }); + var alert = this.$modal.alert() + .title(title) + .content(content) + .ok(l('OK')); + this.$modal.show(alert); }; /** * @name confirm - * @desc Show a confirmation dialog box with buttons "Cancel" and "OK" + * @desc Show a confirmation dialog box with buttons 'Cancel' and 'OK' * @param {string} title * @param {string} content - * @returns a promise that always resolves, but returns true only if the user user has clicked on the - * 'OK' button + * @returns a promise that resolves if the user has clicked on the 'OK' button */ Dialog.confirm = function(title, content) { var d = this.$q.defer(), @@ -58,32 +47,59 @@ return d.promise; }; - Dialog.prompt = function(title, inputPlaceholder, options) { + /** + * @name prompt + * @desc Show a primpt dialog box with a input text field and the 'Cancel' and 'OK' buttons + * @param {string} title + * @param {string} label + * @param {object} [options] - use a different input type by setting 'inputType' + * @returns a promise that resolves with the input field value + */ + Dialog.prompt = function(title, label, options) { var o = options || {}, d = this.$q.defer(); - this.$modal.open({ - template: - '

' + - '
' + - '' + l('OK') + '' + - '' + l('Cancel') + '' + - '', - windowClass: 'small', - controller: function($scope, $modalInstance) { - $scope.title = title; - $scope.inputValue = o.inputValue || ''; - $scope.closeModal = function() { - $modalInstance.close(); - d.resolve(false); - }; - $scope.confirm = function(value) { - $modalInstance.close(); - d.resolve(value); - }; - } + this.$modal.show({ + parent: angular.element(document.body), + clickOutsideToClose: true, + escapeToClose: true, + template: [ + '', + ' ', + '

', + ' ', + ' ', + ' ', + ' ', + '
', + '
', + ' ', + ' ' + l('Cancel'), + ' ', + ' ', + ' ' + l('OK'), + ' ', + '
', + '
' + ].join(''), + controller: PromptDialogController }); + + function PromptDialogController(scope, $mdDialog) { + scope.title = title; + scope.name = ""; + scope.cancel = function() { + d.reject(); + $mdDialog.hide(); + } + scope.ok = function() { + d.resolve(scope.name); + $mdDialog.hide(); + } + } + return d.promise; };