From b990158554276e7c08332b07bdbc1c566e2faf5a Mon Sep 17 00:00:00 2001 From: Tanshu Date: Thu, 1 Nov 2012 18:49:35 +0530 Subject: [PATCH] Changed angular-1.0.2 to allow injection in resolve. Dialog box for delete confirmation. Fixed forbidden view as it is not compatible with xhr --- brewman/brewman/security.py | 14 --- brewman/brewman/static/js/angular-1.0.2.js | 2 +- brewman/brewman/static/partial/issue.html | 6 +- brewman/brewman/static/partial/journal.html | 6 +- brewman/brewman/static/partial/payment.html | 6 +- brewman/brewman/static/partial/purchase.html | 6 +- brewman/brewman/static/partial/receipt.html | 6 +- .../static/scripts/angular_directive.js | 17 ++++ .../brewman/static/scripts/modal-service.js | 85 +++++++++++++++++++ brewman/brewman/static/scripts/overlord.js | 1 - brewman/brewman/templates/angular_base.mako | 3 +- brewman/brewman/views/__init__.py | 2 +- 12 files changed, 121 insertions(+), 33 deletions(-) create mode 100644 brewman/brewman/static/scripts/modal-service.js diff --git a/brewman/brewman/security.py b/brewman/brewman/security.py index 89ab4ba1..ea53aca3 100644 --- a/brewman/brewman/security.py +++ b/brewman/brewman/security.py @@ -1,19 +1,5 @@ -import functools import uuid from brewman.models.auth import User -from brewman.models.voucher import Voucher - -class VoucherFactory(object): - __acl__ = [] - - def __init__(self, request): - self.request = request - - def __getitem__(self, key): - voucher = Voucher.by_id(uuid.UUID(key)) - voucher.__parent__ = self - voucher.__name__ = key - return voucher def groupfinder(user_id, request): if type(user_id) == str: diff --git a/brewman/brewman/static/js/angular-1.0.2.js b/brewman/brewman/static/js/angular-1.0.2.js index 0e4138b1..05ec8fef 100644 --- a/brewman/brewman/static/js/angular-1.0.2.js +++ b/brewman/brewman/static/js/angular-1.0.2.js @@ -7193,7 +7193,7 @@ function $RouteProvider(){ forEach(next.resolve || {}, function(value, key) { keys.push(key); - values.push(isFunction(value) ? $injector.invoke(value) : $injector.get(value)); + values.push(isString(value) ? $injector.get(value) : $injector.invoke(value)); }); if (isDefined(template = next.template)) { } else if (isDefined(template = next.templateUrl)) { diff --git a/brewman/brewman/static/partial/issue.html b/brewman/brewman/static/partial/issue.html index b4c81dd2..8fa0a5cf 100644 --- a/brewman/brewman/static/partial/issue.html +++ b/brewman/brewman/static/partial/issue.html @@ -123,9 +123,9 @@ -
diff --git a/brewman/brewman/static/partial/journal.html b/brewman/brewman/static/partial/journal.html index c4e5d397..fc02e3d4 100644 --- a/brewman/brewman/static/partial/journal.html +++ b/brewman/brewman/static/partial/journal.html @@ -74,9 +74,9 @@ -
diff --git a/brewman/brewman/static/partial/payment.html b/brewman/brewman/static/partial/payment.html index 2872a0a7..1843a8f8 100644 --- a/brewman/brewman/static/partial/payment.html +++ b/brewman/brewman/static/partial/payment.html @@ -83,9 +83,9 @@ -
diff --git a/brewman/brewman/static/partial/purchase.html b/brewman/brewman/static/partial/purchase.html index 9895e82e..8dc60227 100644 --- a/brewman/brewman/static/partial/purchase.html +++ b/brewman/brewman/static/partial/purchase.html @@ -98,9 +98,9 @@ -
diff --git a/brewman/brewman/static/partial/receipt.html b/brewman/brewman/static/partial/receipt.html index df8a2d40..30633e5e 100644 --- a/brewman/brewman/static/partial/receipt.html +++ b/brewman/brewman/static/partial/receipt.html @@ -83,9 +83,9 @@ -
diff --git a/brewman/brewman/static/scripts/angular_directive.js b/brewman/brewman/static/scripts/angular_directive.js index 4781accf..8a489548 100644 --- a/brewman/brewman/static/scripts/angular_directive.js +++ b/brewman/brewman/static/scripts/angular_directive.js @@ -127,6 +127,23 @@ overlord_directive.directive('fadey', function () { return directiveDefinitionObject; }); +overlord_directive.directive('ngConfirm', function(modal) { + return { + restrict: 'A', + link: function postLink(scope, element, attrs) { + // Could have custom or boostrap modal options here + var options = {}; + element.bind("click", function() + { + var actionButton = {text:attrs["actionButtonText"], click:attrs["actionFunction"], class:attrs['class']}; + var cancelButton = {text:attrs["cancelButtonText"], click:attrs["cancelFunction"]}; + modal.confirm(attrs["title"], attrs["actionText"], actionButton, cancelButton, scope, options); + }); + } + }; + +}); + (function (angular) { /* diff --git a/brewman/brewman/static/scripts/modal-service.js b/brewman/brewman/static/scripts/modal-service.js new file mode 100644 index 00000000..4adced52 --- /dev/null +++ b/brewman/brewman/static/scripts/modal-service.js @@ -0,0 +1,85 @@ +overlord_service.factory('modal', function ($http, $compile) { + var modal = {}; + + modal.get = function (create) { + if (!modal.dialog && create) { + modal.dialog = $(''); + modal.dialog.appendTo('BODY'); + } + return modal.dialog; + } + + modal.compileAndRun = function (dialog, scope, options) { + $compile(dialog)(scope); + dialog.modal(options); + } + + modal.alert = function (title, text, buttonText, alertFunction, scope, options) { + text = (text) ? text : "Alert"; + buttonText = (buttonText) ? buttonText : "Ok"; + var dialog = modal.get(true), + html = ""; + if (title) { + html += "

" + title + "

"; + } + html += "
" + text + "
" + + "
"; + if (alertFunction) { + html += ""; + } + else { + html += ""; + } + html += "
"; + dialog.html(html); + if (!alertFunction) { + dialog.find(".btn").click(function () { + modal.close(); + }); + } + modal.compileAndRun(dialog, scope, options); + } + + modal.confirm = function (title, actionText, actionButton, cancelButton, scope, options) { + actionText = (actionText) ? actionText : "Are you sure?"; + actionButton.text = (actionButton.text) ? actionButton.text : "Ok"; + cancelButton.text = (cancelButton.text) ? cancelButton.text : "Cancel"; + + var dialog = modal.get(true), + html = ""; + if (title) { + html += "

" + title + "

"; + } + html += "
" + actionText + "
" + + "
"; + html += ""; + html += ""; + html += "
"; + dialog.html(html); + + dialog.find("#action").click(function () { + if (actionButton.click) { + scope.$eval(actionButton.click); + } + modal.close(); + }); + dialog.find("#cancel").click(function () { + if (cancelButton.click) { + scope.$eval(cancelButton.click); + } + modal.close(); + }); + modal.compileAndRun(dialog, scope, options); + + } + + modal.close = function () { + var popup = modal.get() + if (popup) { + popup.modal('hide'); + } + } + + return modal; + +}); diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js index fea8972d..87582db3 100644 --- a/brewman/brewman/static/scripts/overlord.js +++ b/brewman/brewman/static/scripts/overlord.js @@ -163,7 +163,6 @@ function BaseCtrl($rootScope, $scope, Auth, $location) { } }; - $rootScope.$on("$routeChangeStart", function (event, next, current) { $rootScope.$broadcast('spinnerStart', 'route'); Auth.get(function (u, putResponseHeaders) { diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako index 1cf53dc8..7b56441f 100644 --- a/brewman/brewman/templates/angular_base.mako +++ b/brewman/brewman/templates/angular_base.mako @@ -30,6 +30,7 @@ + @@ -68,7 +69,7 @@ - +