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
This commit is contained in:
Tanshu 2012-11-01 18:49:35 +05:30
parent 56f2892c0f
commit b990158554
12 changed files with 121 additions and 33 deletions

View File

@ -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:

View File

@ -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)) {

View File

@ -123,9 +123,9 @@
<button class="btn btn-danger" ng-click="resetVoucher(voucher.VoucherID)" ng-hide="voucher.Code == '(Auto)'">
New Entry
</button>
<button class="btn btn-danger" ng-click="delete()" ng-hide="voucher.Code == '(Auto)'"
ng-disabled="preventAlteration(voucher)">
Delete
<button class="btn btn-danger" ng-hide="voucher.Code == '(Auto)'" ng-disabled="preventAlteration(voucher)"
ng-confirm title="Delete Voucher" action-text="Are you sure? This cannot be undone."
action-button-text="Delete" action-function="delete()"> Delete
</button>
</div>
<div class="row-fluid">

View File

@ -74,9 +74,9 @@
<button class="btn btn-inverse" ng-click="post()" ng-hide="voucher.Code == '(Auto)'"
ng-disabled="voucher.Posted || !perms['Post Vouchers']">{{voucher.Posted | posted}}
</button>
<button class="btn btn-danger" ng-click="delete()" ng-hide="voucher.Code == '(Auto)'"
ng-disabled="preventAlteration(voucher)">
Delete
<button class="btn btn-danger" ng-hide="voucher.Code == '(Auto)'" ng-disabled="preventAlteration(voucher)"
ng-confirm title="Delete Voucher" action-text="Are you sure? This cannot be undone."
action-button-text="Delete" action-function="delete()"> Delete
</button>
</div>
<div class="row-fluid">

View File

@ -83,9 +83,9 @@
<button class="btn btn-inverse" ng-click="post()" ng-hide="voucher.Code == '(Auto)'"
ng-disabled="voucher.Posted || !perms['Post Vouchers']">{{voucher.Posted | posted}}
</button>
<button class="btn btn-danger" ng-click="delete()" ng-hide="voucher.Code == '(Auto)'"
ng-disabled="preventAlteration(voucher)">
Delete
<button class="btn btn-danger" ng-hide="voucher.Code == '(Auto)'" ng-disabled="preventAlteration(voucher)"
ng-confirm title="Delete Voucher" action-text="Are you sure? This cannot be undone."
action-button-text="Delete" action-function="delete()"> Delete
</button>
</div>
<div class="row-fluid">

View File

@ -98,9 +98,9 @@
<button class="btn btn-inverse" ng-click="post()" ng-hide="voucher.Code == '(Auto)'"
ng-disabled="voucher.Posted || !perms['Post Vouchers']">{{voucher.Posted | posted}}
</button>
<button class="btn btn-danger" ng-click="delete()" ng-hide="voucher.Code == '(Auto)'"
ng-disabled="preventAlteration(voucher)">
Delete
<button class="btn btn-danger" ng-hide="voucher.Code == '(Auto)'" ng-disabled="preventAlteration(voucher)"
ng-confirm title="Delete Voucher" action-text="Are you sure? This cannot be undone."
action-button-text="Delete" action-function="delete()"> Delete
</button>
</div>
<div class="row-fluid">

View File

@ -83,9 +83,9 @@
<button class="btn btn-inverse" ng-click="post()" ng-hide="voucher.Code == '(Auto)'"
ng-disabled="voucher.Posted || !perms['Post Vouchers']">{{voucher.Posted | posted}}
</button>
<button class="btn btn-danger" ng-click="delete()" ng-hide="voucher.Code == '(Auto)'"
ng-disabled="preventAlteration(voucher)">
Delete
<button class="btn btn-danger" ng-hide="voucher.Code == '(Auto)'" ng-disabled="preventAlteration(voucher)"
ng-confirm title="Delete Voucher" action-text="Are you sure? This cannot be undone."
action-button-text="Delete" action-function="delete()"> Delete
</button>
</div>
<div class="row-fluid">

View File

@ -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) {
/*

View File

@ -0,0 +1,85 @@
overlord_service.factory('modal', function ($http, $compile) {
var modal = {};
modal.get = function (create) {
if (!modal.dialog && create) {
modal.dialog = $('<div class="modal hide"></div>');
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 += "<div class=\"modal-header\"><h1>" + title + "</h1></div>";
}
html += "<div class=\"modal-body\">" + text + "</div>"
+ "<div class=\"modal-footer\">";
if (alertFunction) {
html += "<button class=\"btn\" ng-click=\"" + alertFunction + "\">" + buttonText + "</button>";
}
else {
html += "<button class=\"btn\">" + buttonText + "</button>";
}
html += "</div>";
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 += "<div class=\"modal-header\"><h1>" + title + "</h1></div>";
}
html += "<div class=\"modal-body\">" + actionText + "</div>"
+ "<div class=\"modal-footer\">";
html += "<button id=\"action\" class=\"" + actionButton.class + "\">" + actionButton.text + "</button>";
html += "<button id=\"cancel\" class=\"btn btn-cancel\">" + cancelButton.text + "</button>";
html += "</div>";
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;
});

View File

@ -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) {

View File

@ -30,6 +30,7 @@
<script src="/script/angular_directive.js"> </script>
<script src="/script/angular_filter.js"> </script>
<script src="/script/angular_service.js"> </script>
<script src="/script/modal-service.js"> </script>
<script src="/script/login.js"> </script>
<script src="/script/journal.js"> </script>
@ -68,7 +69,7 @@
<link rel="apple-touch-icon-precomposed" href="/img/apple-touch-icon-57-precomposed.png">
</head>
<body ng-controller="BaseCtrl">
<body ng-controller="BaseCtrl" ng-cloak>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">

View File

@ -13,7 +13,7 @@ from pyramid.view import view_config
def home(request):
return {}
@view_config(context=HTTPForbidden, renderer='brewman:templates/angular_base.mako', xhr=False)
@view_config(context=HTTPForbidden, renderer='brewman:templates/angular_base.mako')
def forbidden(request):
if 'X-Requested-With' in request.headers and request.headers['X-Requested-With'] == 'XMLHttpRequest':
response = Response("Forbidden")