Browse Source

Move to one modal controller. Remove deps for dialogs.

pull/51/head
Evan Theurer 11 years ago
parent
commit
14b72542de
  1. 3
      static/js/app.js
  2. 4
      static/js/main.js
  3. 43
      static/js/services/alertify.js

3
static/js/app.js

@ -39,7 +39,6 @@ define([
'angular-humanize', 'angular-humanize',
'angular-route', 'angular-route',
'mobile-events', 'mobile-events',
'dialogs'
], function(require, $, _, angular, modernizr, moment, services, directives, filters, controllers, languages) { ], function(require, $, _, angular, modernizr, moment, services, directives, filters, controllers, languages) {
@ -64,7 +63,7 @@ define([
var initialize = function(ms) { var initialize = function(ms) {
var modules = ['ui.bootstrap', 'ngSanitize', 'ngAnimate', 'ngHumanize', 'ngRoute', 'dialogs']; var modules = ['ui.bootstrap', 'ngSanitize', 'ngAnimate', 'ngHumanize', 'ngRoute'];
if (ms && ms.length) { if (ms && ms.length) {
_.each(ms, function(module) { _.each(ms, function(module) {
modules.push(module); modules.push(module);

4
static/js/main.js

@ -107,10 +107,6 @@ require.config({
deps: ['jquery'], deps: ['jquery'],
exports: '$' exports: '$'
}, },
'dialogs': {
deps: ['angular', 'angular-sanitize'],
exports: 'angular'
},
'sjcl': { 'sjcl': {
exports: 'sjcl' exports: 'sjcl'
} }

43
static/js/services/alertify.js

@ -20,14 +20,13 @@
*/ */
define(["angular"], function(angular) { define(["angular"], function(angular) {
var controller = {}; var modalController = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) {
controller.prompt = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) {
$scope.input = { $scope.input = {
text: '' text: ''
}; };
$scope.id = data.id; $scope.id = data.id;
$scope.header = data.header || ""; $scope.header = data.header || "";
$scope.msg = data.message || "";
$scope.okButtonLabel = data.okButtonLabel || "Ok"; $scope.okButtonLabel = data.okButtonLabel || "Ok";
$scope.cancelButtonLabel = data.cancelButtonLabel || "Cancel"; $scope.cancelButtonLabel = data.cancelButtonLabel || "Cancel";
@ -42,32 +41,11 @@ define(["angular"], function(angular) {
$scope.save(); $scope.save();
} }
}; };
}];
controller.confirm = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) {
$scope.header = data.title || "";
$scope.msg = data.message || "";
$scope.ok = function() { $scope.ok = function() {
$modalInstance.close('ok'); $modalInstance.close('Ok');
}; };
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
}];
controller.notify = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) {
$scope.header = data.title || "";
$scope.msg = data.message || "";
$scope.close = function() {
$modalInstance.close('close');
};
}];
controller.error = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) {
$scope.header = data.title || "";
$scope.msg = data.message || "";
$scope.close = function() { $scope.close = function() {
$modalInstance.close('close'); $modalInstance.close('Close');
}; };
}]; }];
@ -102,7 +80,7 @@ define(["angular"], function(angular) {
var setupModal = function(data, type) { var setupModal = function(data, type) {
return $modal.open({ return $modal.open({
templateUrl: '/dialogs/' + type +'.html', templateUrl: '/dialogs/' + type +'.html',
controller: controller[type], controller: modalController,
resolve: { resolve: {
data: function() { return data; } data: function() { return data; }
} }
@ -118,7 +96,7 @@ define(["angular"], function(angular) {
if (!title) { if (!title) {
title = api.defaultMessages[n] || n; title = api.defaultMessages[n] || n;
} }
var dlg = setupModal({'title': title, 'message': message}, n); var dlg = setupModal({'header': title, 'message': message}, n);
if (ok_cb) { if (ok_cb) {
dlg.result.then(ok_cb, err_cb); dlg.result.then(ok_cb, err_cb);
} }
@ -156,6 +134,15 @@ define(["angular"], function(angular) {
err_cb(); err_cb();
} }
}); });
dlg.opened.then(function() {
// Crude hack to get auto focus.
$window.setTimeout(function() {
var element = $window.document.getElementById(id);
if (element) {
element.focus();
}
}, 100);
});
} }
}; };

Loading…
Cancel
Save