mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-08-19 21:53:19 +00:00
(js) New file structure for Angular modules
JavaScript files are now merged by the 'js' Grunt task.
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @name Dialog
|
||||
* @constructor
|
||||
*/
|
||||
function Dialog() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name alert
|
||||
* @desc Show an alert dialog box with a single "OK" button
|
||||
* @param {string} title
|
||||
* @param {string} content
|
||||
*/
|
||||
Dialog.alert = function(title, content) {
|
||||
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'
|
||||
* @param {string} title
|
||||
* @param {string} content
|
||||
* @returns a promise that resolves if the user has clicked on the 'OK' button
|
||||
*/
|
||||
Dialog.confirm = function(title, content) {
|
||||
var d = this.$q.defer(),
|
||||
confirm = this.$modal.confirm()
|
||||
.title(title)
|
||||
.content(content)
|
||||
.ok(l('OK'))
|
||||
.cancel(l('Cancel'));
|
||||
this.$modal.show(confirm).then(function() {
|
||||
d.resolve();
|
||||
}, function() {
|
||||
d.reject();
|
||||
});
|
||||
return d.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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.show({
|
||||
parent: angular.element(document.body),
|
||||
clickOutsideToClose: true,
|
||||
escapeToClose: true,
|
||||
template: [
|
||||
'<md-dialog flex="50" flex-sm="100">',
|
||||
' <md-dialog-content layout="column">',
|
||||
' <h2 class="md-title" ng-bind="title"></h2>',
|
||||
' <md-input-container>',
|
||||
' <label>' + label + '</label>',
|
||||
' <input type="' + (o.inputType || 'text') + '"',
|
||||
' aria-label="' + title + '"',
|
||||
' ng-model="name" required="required"/>',
|
||||
' </md-input-container>',
|
||||
' </md-dialog-content>',
|
||||
' <div class="md-actions">',
|
||||
' <md-button ng-click="cancel()">',
|
||||
' ' + l('Cancel'),
|
||||
' </md-button>',
|
||||
' <md-button class="md-primary" ng-click="ok()" ng-disabled="!name.length">',
|
||||
' ' + l('OK'),
|
||||
' </md-button>',
|
||||
' </div>',
|
||||
'</md-dialog>'
|
||||
].join(''),
|
||||
controller: PromptDialogController
|
||||
});
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberof Dialog
|
||||
* @desc The factory we'll register as Dialog in the Angular module SOGo.Common
|
||||
* @ngInject
|
||||
*/
|
||||
DialogService.$inject = ['$q', '$mdDialog'];
|
||||
function DialogService($q, $mdDialog) {
|
||||
angular.extend(Dialog, { $q: $q , $modal: $mdDialog });
|
||||
|
||||
return Dialog; // return constructor
|
||||
};
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
angular
|
||||
.module('SOGo.Common')
|
||||
.factory('Dialog', DialogService);
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user