diff --git a/brewman/brewman/__init__.py b/brewman/brewman/__init__.py index 57a5e630..9c192643 100644 --- a/brewman/brewman/__init__.py +++ b/brewman/brewman/__init__.py @@ -120,6 +120,8 @@ def main(global_config, **settings): config.add_route('profit_loss', '/ProfitLoss') config.add_route('purchase_entries', '/PurchaseEntries') + config.add_route('auth', '/Auth') + config.add_route('services_session_current_date', '/Services/CurrentDate') config.add_route('services_session_period_start', '/Services/PeriodStart') config.add_route('services_session_period_finish', '/Services/PeriodFinish') @@ -137,7 +139,6 @@ def main(global_config, **settings): config.add_route('services_product_add_inventory', '/Services/AddInventory') config.add_route('services_batch_list', '/Services/Batches') - config.add_route('user_permissions', '/Permissions') config.add_route('account_type_list', '/AccountTypes') config.add_route('voucher', '/Voucher/{id}') diff --git a/brewman/brewman/factories.py b/brewman/brewman/factories.py index 13bad604..197b3977 100644 --- a/brewman/brewman/factories.py +++ b/brewman/brewman/factories.py @@ -11,7 +11,6 @@ class RootFactory(object): (Allow, Authenticated, 'post')] for permission in Role.list(): acl.append((Allow, permission.name, permission.name)) - print(acl) return acl def __init__(self, request): pass \ No newline at end of file diff --git a/brewman/brewman/helpers.py b/brewman/brewman/helpers.py deleted file mode 100644 index dc2f5170..00000000 --- a/brewman/brewman/helpers.py +++ /dev/null @@ -1,283 +0,0 @@ -import string - -from brewman.views.nav_bar import login_menu, report_menu, voucher_menu, entry_menu, employee_menu, master_menu - -class Form(object): - """Make absolute URL from the relative one. - """ - def __init__(self, action, method = "post"): - self.text = "
" - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class FormToUrl(object): - """Make absolute URL from the relative one. - """ - def __init__(self, request, action, method = "post"): - self.text = "" - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class CsrfToken(object): - def __init__(self, session): - self.text = "" - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class EndForm(object): - """Make absolute URL from the relative one. - """ - def __init__(self): - self.text = "
" - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class CssLink(object): - """Make absolute URL from the relative one. - """ - def __init__(self, request, file, media = "screen"): - self.text = "" - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class JsLink(object): - """Make absolute URL from the relative one. - """ - def __init__(self, request, file): - if file.startswith("http"): - self.text = "" - else: - self.text = "" - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class ScriptLink(object): - """Make absolute URL from the relative one. - """ - def __init__(self, request, file): - if file.startswith("http"): - self.text = "" - else: - self.text = "" - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class Span(object): - def __init__(self, text, css_class = ""): - if len(css_class) > 0: - css_class = "class=\"{0}\"".format(css_class) - self.text = "{1}".format(css_class, text) - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class Label(object): - def __init__(self, text, label_for, css_class = ""): - if len(css_class) > 0: - css_class = "class=\"{0}\"".format(css_class) - self.text = "".format(label_for, css_class, text) - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class TextInput(object): - def __init__(self, name, id = None, value="", css_class = "", required = "", disabled = "", placeholder = "", autocomplete = ""): - if id is None: - id = name - if len(css_class) > 0: - css_class = " class=\"{0}\"".format(css_class) - - disabled = disabled.lower() - if disabled == 'disabled' or disabled == 'true' or disabled == 1 or disabled == 'yes': - disabled = ' disabled=\"disabled\"' - else: - disabled = '' - - if len(placeholder) > 0: - placeholder = ' placeholder=\"{0}\"'.format(placeholder) - - autocomplete = autocomplete.lower() - if len(autocomplete) > 0 and (autocomplete == 'off' or autocomplete == 'disabled' or autocomplete == 0 or autocomplete == 'false'): - autocomplete = ' autocomplete=\"off\"' - else: - autocomplete = '' - - required = required.lower() - if len(required) > 0 and (required == 'required' or required == 'true' or requred == 1 or required == 'yes'): - required = ' required' - else: - required = '' - if value == "": - value = " " - else: - value = " value=\"{0}\"".format(value) - self.text = "".format(name, id, css_class, required, value, disabled, placeholder, autocomplete) - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class CheckBoxInput(object): - def __init__(self, name, id = None, value = False, css_class = ""): - if id is None: - id = name - if len(css_class) > 0: - css_class = " class=\"{0}\"".format(css_class) - if value: - value = " checked=\"checked\"" - else: - value = " " - self.text = "".format(name, id, css_class, value) - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class Password(object): - def __init__(self, name, id = None, css_class = "", required = "", placeholder = ""): - if id is None: - id = name - if len(css_class) > 0: - css_class = " class=\"{0}\"".format(css_class) - required = required.lower() - if len(required) > 0 and (required == 'required' or required == 'true' or requred == 1 or required == 'yes'): - required = ' required' - else: - required = '' - if len(placeholder) > 0: - placeholder = ' placeholder=\"{0}\"'.format(placeholder) - - self.text = "".format(name, id, css_class, required, placeholder) - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class SubmitButton(object): - def __init__(self, id, text, css_class = ""): - if len(css_class) > 0: - css_class = " class=\"{0}\"".format(css_class) - self.text = "".format(id, text, css_class) - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class SelectInput(object): - def __init__(self, name, id = None, list = None, displayField = "", valueField = "", defaultValue = "", css_class = ""): - if id is None: - id = name - if len(css_class) > 0: - css_class = " class=\"{0}\"".format(css_class) - options = '' - if not list is None: - for item in list: - if type(item) == dict: - display = item[displayField] - value = item[valueField] - else: - display = getattr(item, displayField) - value = getattr(item, valueField) - selected = '' - if value == defaultValue: - selected = ' selected' - options += "".format(str(value), selected, display) - - self.text = "".format(name, id, css_class, options) - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class HiddenInput(object): - def __init__(self, id, value=""): - if not value == "": - value = " value=\"{0}\"".format(value) - self.text = "".format(id, value) - - def __str__(self): - return self.text - - __unicode__ = __str__ - - def __html__(self): - return self.text - -class Literal(object): - def __init__(self, s): - self.s = s - - def __html__(self): - return self.s \ No newline at end of file diff --git a/brewman/brewman/models/auth.py b/brewman/brewman/models/auth.py index 187fc19f..5c59ba8a 100644 --- a/brewman/brewman/models/auth.py +++ b/brewman/brewman/models/auth.py @@ -77,7 +77,7 @@ class User(Base): @classmethod def get_by_name(cls, name): - return DBSession.query(cls).filter(cls.name == name).one() + return DBSession.query(cls).filter(cls.name == name).first() @classmethod def get_by_id(cls, id): diff --git a/brewman/brewman/security.py b/brewman/brewman/security.py index 1148c044..c614acb2 100644 --- a/brewman/brewman/security.py +++ b/brewman/brewman/security.py @@ -1,5 +1,4 @@ import uuid -from pyramid.security import Allow, ALL_PERMISSIONS from brewman.models.auth import User class VoucherFactory(object): @@ -25,7 +24,6 @@ def groupfinder(user_id, request): perms.append(perm.name) perms = f7(perms) request.session['perms'] = perms - print(perms) return perms diff --git a/brewman/brewman/static/js/angular-1.0.1.js b/brewman/brewman/static/js/angular-1.0.2.js similarity index 98% rename from brewman/brewman/static/js/angular-1.0.1.js rename to brewman/brewman/static/js/angular-1.0.2.js index 2e63152e..0e4138b1 100644 --- a/brewman/brewman/static/js/angular-1.0.1.js +++ b/brewman/brewman/static/js/angular-1.0.2.js @@ -1,5 +1,5 @@ /** - * @license AngularJS v1.0.1 + * @license AngularJS v1.0.2 * (c) 2010-2012 Google, Inc. http://angularjs.org * License: MIT */ @@ -1178,7 +1178,7 @@ function setupModuleLoader(window) { * @param {Function} directiveFactory Factory function for creating new instance of * directives. * @description - * See {@link ng.$compileProvider.directive $compileProvider.directive()}. + * See {@link ng.$compileProvider#directive $compileProvider.directive()}. */ directive: invokeLater('$compileProvider', 'directive'), @@ -1247,11 +1247,11 @@ function setupModuleLoader(window) { * - `codeName` – `{string}` – Code name of the release, such as "jiggling-armfat". */ var version = { - full: '1.0.1', // all of these placeholder strings will be replaced by rake's + full: '1.0.2', // all of these placeholder strings will be replaced by rake's major: 1, // compile task minor: 0, - dot: 1, - codeName: 'thorium-shielding' + dot: 2, + codeName: 'debilitating-awesomeness' }; @@ -1529,7 +1529,7 @@ function JQLite(element) { var div = document.createElement('div'); // Read about the NoScope elements here: // http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx - div.innerHTML = '
 
' + element; // IE insanity to make NoScope elements work! + div.innerHTML = '
 
' + element; // IE insanity to make NoScope elements work! div.removeChild(div.firstChild); // remove the superfluous div JQLiteAddNodes(this, div.childNodes); this.remove(); // detach the elements from the temporary DOM div. @@ -3441,7 +3441,7 @@ var NON_ASSIGNABLE_MODEL_EXPRESSION = 'Non-assignable model expression: '; * can then be used to link {@link ng.$rootScope.Scope scope} and the template together. * * The compilation is a process of walking the DOM tree and trying to match DOM elements to - * {@link ng.$compileProvider.directive directives}. For each match it + * {@link ng.$compileProvider#directive directives}. For each match it * executes corresponding template function and collects the * instance functions into a single template function which is then returned. * @@ -3559,20 +3559,6 @@ var NON_ASSIGNABLE_MODEL_EXPRESSION = 'Non-assignable model expression: '; * * @description */ - -/** - * @ngdoc function - * @name ng.$compileProvider#directive - * @methodOf ng.$compileProvider - * @function - * - * @description - * Register a new directive with compiler - * - * @param {string} name name of the directive. - * @param {function} directiveFactory An injectable directive factory function. - * @returns {ng.$compileProvider} Self for chaining. - */ $CompileProvider.$inject = ['$provide']; function $CompileProvider($provide) { var hasDirectives = {}, @@ -3584,17 +3570,18 @@ function $CompileProvider($provide) { /** * @ngdoc function - * @name ng.$compileProvider.directive + * @name ng.$compileProvider#directive * @methodOf ng.$compileProvider * @function * * @description - * Register directives with the compiler. + * Register a new directives with the compiler. * * @param {string} name Name of the directive in camel-case. (ie ngBind which will match as * ng-bind). * @param {function} directiveFactory An injectable directive factroy function. See {@link guide/directive} for more * info. + * @returns {ng.$compileProvider} Self for chaining. */ this.directive = function registerDirective(name, directiveFactory) { if (isString(name)) { @@ -3720,6 +3707,15 @@ function $CompileProvider($provide) { } }; + var startSymbol = $interpolate.startSymbol(), + endSymbol = $interpolate.endSymbol(), + denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}') + ? identity + : function denormalizeTemplate(template) { + return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol); + }; + + return compile; //================================ @@ -3733,7 +3729,7 @@ function $CompileProvider($provide) { // not be able to attach scope data to them, so we will wrap them in forEach($compileNode, function(node, index){ if (node.nodeType == 3 /* text node */) { - $compileNode[index] = jqLite(node).wrap('').parent()[0]; + $compileNode[index] = jqLite(node).wrap('').parent()[0]; } }); var compositeLinkFn = compileNodes($compileNode, transcludeFn, $compileNode, maxPriority); @@ -3999,14 +3995,17 @@ function $CompileProvider($provide) { } } - if (directiveValue = directive.template) { + if ((directiveValue = directive.template)) { assertNoDuplicate('template', templateDirective, directive, $compileNode); templateDirective = directive; - - $template = jqLite('
' + trim(directiveValue) + '
').contents(); - compileNode = $template[0]; + directiveValue = denormalizeTemplate(directiveValue); if (directive.replace) { + $template = jqLite('
' + + trim(directiveValue) + + '
').contents(); + compileNode = $template[0]; + if ($template.length != 1 || compileNode.nodeType !== 1) { throw new Error(MULTI_ROOT_TEMPLATE_ERROR + directiveValue); } @@ -4319,6 +4318,8 @@ function $CompileProvider($provide) { success(function(content) { var compileNode, tempTemplateAttrs, $template; + content = denormalizeTemplate(content); + if (replace) { $template = jqLite('
' + trim(content) + '
').contents(); compileNode = $template[0]; @@ -4663,13 +4664,13 @@ function $ExceptionHandlerProvider() { } /** - * @ngdoc function + * @ngdoc object * @name ng.$interpolateProvider * @function * * @description * - * Used for configuring the interpolation markup. Deafults to `{{` and `}}`. + * Used for configuring the interpolation markup. Defaults to `{{` and `}}`. */ function $InterpolateProvider() { var startSymbol = '{{'; @@ -4682,7 +4683,8 @@ function $InterpolateProvider() { * @description * Symbol to denote start of expression in the interpolated string. Defaults to `{{`. * - * @prop {string=} value new value to set the starting symbol to. + * @param {string=} value new value to set the starting symbol to. + * @returns {string|self} Returns the symbol when used as getter and self if used as setter. */ this.startSymbol = function(value){ if (value) { @@ -4700,14 +4702,15 @@ function $InterpolateProvider() { * @description * Symbol to denote the end of expression in the interpolated string. Defaults to `}}`. * - * @prop {string=} value new value to set the ending symbol to. + * @param {string=} value new value to set the ending symbol to. + * @returns {string|self} Returns the symbol when used as getter and self if used as setter. */ this.endSymbol = function(value){ if (value) { endSymbol = value; return this; } else { - return startSymbol; + return endSymbol; } }; @@ -4749,7 +4752,7 @@ function $InterpolateProvider() { * against. * */ - return function(text, mustHaveExpression) { + function $interpolate(text, mustHaveExpression) { var startIndex, endIndex, index = 0, @@ -4801,7 +4804,43 @@ function $InterpolateProvider() { fn.parts = parts; return fn; } - }; + } + + + /** + * @ngdoc method + * @name ng.$interpolate#startSymbol + * @methodOf ng.$interpolate + * @description + * Symbol to denote the start of expression in the interpolated string. Defaults to `{{`. + * + * Use {@link ng.$interpolateProvider#startSymbol $interpolateProvider#startSymbol} to change + * the symbol. + * + * @returns {string} start symbol. + */ + $interpolate.startSymbol = function() { + return startSymbol; + } + + + /** + * @ngdoc method + * @name ng.$interpolate#endSymbol + * @methodOf ng.$interpolate + * @description + * Symbol to denote the end of expression in the interpolated string. Defaults to `}}`. + * + * Use {@link ng.$interpolateProvider#endSymbol $interpolateProvider#endSymbol} to change + * the symbol. + * + * @returns {string} start symbol. + */ + $interpolate.endSymbol = function() { + return endSymbol; + } + + return $interpolate; }]; } @@ -5433,27 +5472,25 @@ function $LocationProvider(){ * The main purpose of this service is to simplify debugging and troubleshooting. * * @example - - - -
-

Reload this page with open console, enter text and hit the log button...

- Message: - - - - - -
-
- - -
+ + + function LogCtrl($scope, $log) { + $scope.$log = $log; + $scope.message = 'Hello World!'; + } + + +
+

Reload this page with open console, enter text and hit the log button...

+ Message: + + + + + +
+
+
*/ function $LogProvider(){ @@ -6810,8 +6847,9 @@ function $RouteProvider(){ * * Object properties: * - * - `controller` – `{function()=}` – Controller fn that should be associated with newly - * created scope. + * - `controller` – `{(string|function()=}` – Controller fn that should be associated with newly + * created scope or the name of a {@link angular.Module#controller registered controller} + * if passed as a string. * - `template` – `{string=}` – html template as a string that should be used by * {@link ng.directive:ngView ngView} or * {@link ng.directive:ngInclude ngInclude} directives. @@ -6821,7 +6859,7 @@ function $RouteProvider(){ * - `resolve` - `{Object.=}` - An optional map of dependencies which should * be injected into the controller. If any of these dependencies are promises, they will be * resolved and converted to a value before the controller is instantiated and the - * `$aftreRouteChange` event is fired. The map object is: + * `$afterRouteChange` event is fired. The map object is: * * - `key` – `{string}`: a name of a dependency to be injected into the controller. * - `factory` - `{string|function}`: If `string` then it is an alias for a service. @@ -7587,9 +7625,9 @@ function $RootScopeProvider(){ * * Usually you don't call `$digest()` directly in * {@link ng.directive:ngController controllers} or in - * {@link ng.$compileProvider.directive directives}. + * {@link ng.$compileProvider#directive directives}. * Instead a call to {@link ng.$rootScope.Scope#$apply $apply()} (typically from within a - * {@link ng.$compileProvider.directive directives}) will force a `$digest()`. + * {@link ng.$compileProvider#directive directives}) will force a `$digest()`. * * If you want to be notified whenever `$digest()` is called, * you can register a `watchExpression` function with {@link ng.$rootScope.Scope#$watch $watch()} @@ -7875,8 +7913,8 @@ function $RootScopeProvider(){ * @param {function(event)} listener Function to call when the event is emitted. * @returns {function()} Returns a deregistration function for this listener. * - * The event listener function format is: `function(event)`. The `event` object passed into the - * listener has the following attributes + * The event listener function format is: `function(event, args...)`. The `event` object + * passed into the listener has the following attributes: * * - `targetScope` - {Scope}: the scope on which the event was `$emit`-ed or `$broadcast`-ed. * - `currentScope` - {Scope}: the current scope which is handling the event. @@ -10105,7 +10143,12 @@ function ngDirective(directive) { return valueFn(directive); } -/* +/** + * @ngdoc directive + * @name ng.directive:a + * @restrict E + * + * @description * Modifies the default behavior of html A tag, so that the default action is prevented when href * attribute is empty. * @@ -10673,41 +10716,65 @@ function FormController(element, attrs) { */ -var formDirectiveDir = { - name: 'form', - restrict: 'E', - controller: FormController, - compile: function() { - return { - pre: function(scope, formElement, attr, controller) { - if (!attr.action) { - formElement.bind('submit', function(event) { - event.preventDefault(); - }); - } +var formDirectiveFactory = function(isNgForm) { + return ['$timeout', function($timeout) { + var formDirective = { + name: 'form', + restrict: 'E', + controller: FormController, + compile: function() { + return { + pre: function(scope, formElement, attr, controller) { + if (!attr.action) { + // we can't use jq events because if a form is destroyed during submission the default + // action is not prevented. see #1238 + // + // IE 9 is not affected because it doesn't fire a submit event and try to do a full + // page reload if the form was destroyed by submission of the form via a click handler + // on a button in the form. Looks like an IE9 specific bug. + var preventDefaultListener = function(event) { + event.preventDefault + ? event.preventDefault() + : event.returnValue = false; // IE + }; - var parentFormCtrl = formElement.parent().controller('form'), - alias = attr.name || attr.ngForm; + addEventListenerFn(formElement[0], 'submit', preventDefaultListener); - if (alias) { - scope[alias] = controller; - } - if (parentFormCtrl) { - formElement.bind('$destroy', function() { - parentFormCtrl.$removeControl(controller); - if (alias) { - scope[alias] = undefined; + // unregister the preventDefault listener so that we don't not leak memory but in a + // way that will achieve the prevention of the default action. + formElement.bind('$destroy', function() { + $timeout(function() { + removeEventListenerFn(formElement[0], 'submit', preventDefaultListener); + }, 0, false); + }); } - extend(controller, nullFormCtrl); //stop propagating child destruction handlers upwards - }); - } + + var parentFormCtrl = formElement.parent().controller('form'), + alias = attr.name || attr.ngForm; + + if (alias) { + scope[alias] = controller; + } + if (parentFormCtrl) { + formElement.bind('$destroy', function() { + parentFormCtrl.$removeControl(controller); + if (alias) { + scope[alias] = undefined; + } + extend(controller, nullFormCtrl); //stop propagating child destruction handlers upwards + }); + } + } + }; } }; - } + + return isNgForm ? extend(copy(formDirective), {restrict: 'EAC'}) : formDirective; + }]; }; -var formDirective = valueFn(formDirectiveDir); -var ngFormDirective = valueFn(extend(copy(formDirectiveDir), {restrict: 'EAC'})); +var formDirective = formDirectiveFactory(); +var ngFormDirective = formDirectiveFactory(true); var URL_REGEXP = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/; var EMAIL_REGEXP = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/; @@ -11928,7 +11995,7 @@ var ngListDirective = function() { ctrl.$parsers.push(parse); ctrl.$formatters.push(function(value) { - if (isArray(value) && !equals(parse(ctrl.$viewValue), value)) { + if (isArray(value)) { return value.join(', '); } @@ -13045,11 +13112,14 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp whenExp = element.attr(attr.$attr.when), // this is because we have {{}} in attrs offset = attr.offset || 0, whens = scope.$eval(whenExp), - whensExpFns = {}; + whensExpFns = {}, + startSymbol = $interpolate.startSymbol(), + endSymbol = $interpolate.endSymbol(); forEach(whens, function(expression, key) { whensExpFns[key] = - $interpolate(expression.replace(BRACE, '{{' + numberExp + '-' + offset + '}}')); + $interpolate(expression.replace(BRACE, startSymbol + numberExp + '-' + + offset + endSymbol)); }); scope.$watch(function() { @@ -14273,7 +14343,6 @@ var optionDirective = ['$interpolate', function($interpolate) { return { restrict: 'E', priority: 100, - require: '^select', compile: function(element, attr) { if (isUndefined(attr.value)) { var interpolateFn = $interpolate(element.text(), true); @@ -14282,8 +14351,13 @@ var optionDirective = ['$interpolate', function($interpolate) { } } - return function (scope, element, attr, selectCtrl) { - if (selectCtrl.databound) { + return function (scope, element, attr) { + var selectCtrlName = '$selectController', + parent = element.parent(), + selectCtrl = parent.data(selectCtrlName) || + parent.parent().data(selectCtrlName); // in case we are in optgroup + + if (selectCtrl && selectCtrl.databound) { // For some reason Opera defaults to true and if not overridden this messes up the repeater. // We don't want the view to drive the initialization of the model anyway. element.prop('selected', false); diff --git a/brewman/brewman/static/js/angular-resource-1.0.1.js b/brewman/brewman/static/js/angular-resource-1.0.2.js similarity index 99% rename from brewman/brewman/static/js/angular-resource-1.0.1.js rename to brewman/brewman/static/js/angular-resource-1.0.2.js index 1b8f16e1..7e99e3c3 100644 --- a/brewman/brewman/static/js/angular-resource-1.0.1.js +++ b/brewman/brewman/static/js/angular-resource-1.0.2.js @@ -1,5 +1,5 @@ /** - * @license AngularJS v1.0.1 + * @license AngularJS v1.0.2 * (c) 2010-2012 Google, Inc. http://angularjs.org * License: MIT */ diff --git a/brewman/brewman/static/partial/404.html b/brewman/brewman/static/partial/404.html new file mode 100644 index 00000000..5cf0c35e --- /dev/null +++ b/brewman/brewman/static/partial/404.html @@ -0,0 +1,7 @@ +
+
+

404

+ +

It looks like that page you were looking has been lost, sorry.

+
+
diff --git a/brewman/brewman/static/partial/closing-stock.html b/brewman/brewman/static/partial/closing-stock.html index d56061c9..e5b89ab5 100644 --- a/brewman/brewman/static/partial/closing-stock.html +++ b/brewman/brewman/static/partial/closing-stock.html @@ -4,7 +4,7 @@
- +
diff --git a/brewman/brewman/static/partial/login.html b/brewman/brewman/static/partial/login.html new file mode 100644 index 00000000..7f55d499 --- /dev/null +++ b/brewman/brewman/static/partial/login.html @@ -0,0 +1,31 @@ +
+

Login

+ +
+ +
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ Forgot Username / Password +
+
+
+ +
+
+
diff --git a/brewman/brewman/static/scripts/angular_service.js b/brewman/brewman/static/scripts/angular_service.js index 611fdf9c..6e27acb4 100644 --- a/brewman/brewman/static/scripts/angular_service.js +++ b/brewman/brewman/static/scripts/angular_service.js @@ -39,11 +39,6 @@ overlord_service.factory('ProductLedger', ['$resource', function ($resource) { return $resource('/ProductLedger/:id'); }]); -// TODO: Replace hardcoded url with route_url -overlord_service.factory('Permission', ['$resource', function ($resource) { - return $resource('/Permissions'); -}]); - // TODO: Replace hardcoded url with route_url overlord_service.factory('CostCenter', ['$resource', function ($resource) { return $resource('/CostCenter/:id', @@ -143,3 +138,10 @@ overlord_service.factory('LedgerService', ['$resource', function ($resource) { return $resource('/Services/Accounts/:type'); }]); +// TODO: Replace hardcoded url with route_url +overlord_service.factory('Auth', ['$resource', function ($resource) { + return $resource('/Auth', {}, { + login:{method:'GET', params:{list:true}, isArray:true} + }); +}]); + diff --git a/brewman/brewman/static/scripts/autocomplete.js b/brewman/brewman/static/scripts/autocomplete.js deleted file mode 100644 index ff849582..00000000 --- a/brewman/brewman/static/scripts/autocomplete.js +++ /dev/null @@ -1,22 +0,0 @@ -function AutoComplete(matchFieldName, lookupURL) { - $(matchFieldName).autocomplete({ - source:function (request, response) { - $.ajax({ - type:"POST", - url:lookupURL, - contentType:"application/json; charset=utf-8", - dataType:"json", - async:true, - data:JSON.stringify({prefixText:request.term, count:20}), - success:function (data) { - response(data); - }, - error:function (XMLHttpRequest, textStatus, errorThrown) { - showError(textStatus.responseText); - } - }); - }, - minLength:1, - autoFocus:true - }); -} diff --git a/brewman/brewman/static/scripts/closing-stock.js b/brewman/brewman/static/scripts/closing-stock.js index 94c23903..0f58f3d9 100644 --- a/brewman/brewman/static/scripts/closing-stock.js +++ b/brewman/brewman/static/scripts/closing-stock.js @@ -1,17 +1,37 @@ - -function ClosingStockCtrl($scope, $routeParams, $location, ClosingStock) { - if (typeof $routeParams.date === 'undefined') { - $scope.info = ClosingStock.get({}); - } else { - $scope.info = ClosingStock.get({date:$routeParams.date}); - - } +function ClosingStockCtrl($scope, $routeParams, $location, info) { + $scope.info = info; $scope.show = function () { - $scope.info = ClosingStock.get({id:$scope.info.Date}, function (u, putResponseHeaders) { - $location.path('/ClosingStock/' + u.Date); - }, function (data, status) { - $scope.toasts.push({Type:'Error', Message:data.data}); - }); + $location.path('/ClosingStock/' + $scope.info.Date); }; $('#txtDate').focus(); } +ClosingStockCtrl.resolve = { + info:function ($q, $route, ClosingStock) { + var deferred = $q.defer(); + + var date = $route.current.params.date; + + var successCb = function(result){ + deferred.resolve(result); + }; + + if (typeof date === 'undefined') { + return ClosingStock.get({}, successCb); + } else { + return ClosingStock.get({date:date}, successCb); + } + return deferred.promise; + } +} + +//LedgerCtrl.resolve = { +// ledger_data:function ($route, Ledger) { +// var params = $route.current.params; +// if (typeof params.id === 'undefined') { +// return Ledger.get({}); +// } else { +// return Ledger.get({id:params.id, StartDate:params.StartDate, FinishDate:params.FinishDate}); +// +// } +// } +//} \ No newline at end of file diff --git a/brewman/brewman/static/scripts/jquery.easing.1.3.js b/brewman/brewman/static/scripts/jquery.easing.1.3.js deleted file mode 100644 index 304000f1..00000000 --- a/brewman/brewman/static/scripts/jquery.easing.1.3.js +++ /dev/null @@ -1,205 +0,0 @@ -/* - * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/ - * - * Uses the built in easing capabilities added In jQuery 1.1 - * to offer multiple easing options - * - * TERMS OF USE - jQuery Easing - * - * Open source under the BSD License. - * - * Copyright © 2008 George McGinley Smith - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * Neither the name of the author nor the names of contributors may be used to endorse - * or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ - -// t: current time, b: begInnIng value, c: change In value, d: duration -jQuery.easing['jswing'] = jQuery.easing['swing']; - -jQuery.extend( jQuery.easing, -{ - def: 'easeOutQuad', - swing: function (x, t, b, c, d) { - //alert(jQuery.easing.default); - return jQuery.easing[jQuery.easing.def](x, t, b, c, d); - }, - easeInQuad: function (x, t, b, c, d) { - return c*(t/=d)*t + b; - }, - easeOutQuad: function (x, t, b, c, d) { - return -c *(t/=d)*(t-2) + b; - }, - easeInOutQuad: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t + b; - return -c/2 * ((--t)*(t-2) - 1) + b; - }, - easeInCubic: function (x, t, b, c, d) { - return c*(t/=d)*t*t + b; - }, - easeOutCubic: function (x, t, b, c, d) { - return c*((t=t/d-1)*t*t + 1) + b; - }, - easeInOutCubic: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t + b; - return c/2*((t-=2)*t*t + 2) + b; - }, - easeInQuart: function (x, t, b, c, d) { - return c*(t/=d)*t*t*t + b; - }, - easeOutQuart: function (x, t, b, c, d) { - return -c * ((t=t/d-1)*t*t*t - 1) + b; - }, - easeInOutQuart: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t*t + b; - return -c/2 * ((t-=2)*t*t*t - 2) + b; - }, - easeInQuint: function (x, t, b, c, d) { - return c*(t/=d)*t*t*t*t + b; - }, - easeOutQuint: function (x, t, b, c, d) { - return c*((t=t/d-1)*t*t*t*t + 1) + b; - }, - easeInOutQuint: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; - return c/2*((t-=2)*t*t*t*t + 2) + b; - }, - easeInSine: function (x, t, b, c, d) { - return -c * Math.cos(t/d * (Math.PI/2)) + c + b; - }, - easeOutSine: function (x, t, b, c, d) { - return c * Math.sin(t/d * (Math.PI/2)) + b; - }, - easeInOutSine: function (x, t, b, c, d) { - return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; - }, - easeInExpo: function (x, t, b, c, d) { - return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; - }, - easeOutExpo: function (x, t, b, c, d) { - return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; - }, - easeInOutExpo: function (x, t, b, c, d) { - if (t==0) return b; - if (t==d) return b+c; - if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; - return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; - }, - easeInCirc: function (x, t, b, c, d) { - return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; - }, - easeOutCirc: function (x, t, b, c, d) { - return c * Math.sqrt(1 - (t=t/d-1)*t) + b; - }, - easeInOutCirc: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; - return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; - }, - easeInElastic: function (x, t, b, c, d) { - var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); - return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; - }, - easeOutElastic: function (x, t, b, c, d) { - var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); - return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; - }, - easeInOutElastic: function (x, t, b, c, d) { - var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); - if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; - return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; - }, - easeInBack: function (x, t, b, c, d, s) { - if (s == undefined) s = 1.70158; - return c*(t/=d)*t*((s+1)*t - s) + b; - }, - easeOutBack: function (x, t, b, c, d, s) { - if (s == undefined) s = 1.70158; - return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; - }, - easeInOutBack: function (x, t, b, c, d, s) { - if (s == undefined) s = 1.70158; - if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; - return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; - }, - easeInBounce: function (x, t, b, c, d) { - return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b; - }, - easeOutBounce: function (x, t, b, c, d) { - if ((t/=d) < (1/2.70)) { - return c*(7.5625*t*t) + b; - } else if (t < (2/2.70)) { - return c*(7.5625*(t-=(1.5/2.70))*t + .70) + b; - } else if (t < (2.5/2.70)) { - return c*(7.5625*(t-=(2.25/2.70))*t + .9370) + b; - } else { - return c*(7.5625*(t-=(2.625/2.70))*t + .984370) + b; - } - }, - easeInOutBounce: function (x, t, b, c, d) { - if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b; - return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b; - } -}); - -/* - * - * TERMS OF USE - EASING EQUATIONS - * - * Open source under the BSD License. - * - * Copyright © 2001 Robert Penner - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * Neither the name of the author nor the names of contributors may be used to endorse - * or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ \ No newline at end of file diff --git a/brewman/brewman/static/scripts/login.js b/brewman/brewman/static/scripts/login.js new file mode 100644 index 00000000..664c76bd --- /dev/null +++ b/brewman/brewman/static/scripts/login.js @@ -0,0 +1,13 @@ +function LoginCtrl($scope, $http, $location) { + $scope.submit = function () { + $http. + post('/login', {'username':$scope.name, 'password':$scope.password}). + success(function () { + $location.path('/') + }). + error(function (errorMessage) { + $scope.toasts.push({Type:'Error', Message:errorMessage}); + }); + } + $('#username').focus(); +} diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js index b34fe2b6..a2dadfa2 100644 --- a/brewman/brewman/static/scripts/overlord.js +++ b/brewman/brewman/static/scripts/overlord.js @@ -4,6 +4,7 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { $routeProvider. when('/', {templateUrl:'/partial/home.html'}). + when('/login', {templateUrl:'/partial/login.html', controller:LoginCtrl}). when('/Journal', {templateUrl:'/partial/journal.html', controller:JournalCtrl}). when('/Journal/:id', {templateUrl:'/partial/journal.html', controller:JournalCtrl}). @@ -43,8 +44,8 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte when('/TrialBalance', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}). when('/TrialBalance/:date', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}). - when('/ClosingStock', {templateUrl:'/partial/closing-stock.html', controller:ClosingStockCtrl}). - when('/ClosingStock/:date', {templateUrl:'/partial/closing-stock.html', controller:ClosingStockCtrl}). + when('/ClosingStock', {templateUrl:'/partial/closing-stock.html', controller:ClosingStockCtrl, resolve:ClosingStockCtrl.resolve}). + when('/ClosingStock/:date', {templateUrl:'/partial/closing-stock.html', controller:ClosingStockCtrl, resolve:ClosingStockCtrl.resolve}). when('/Accounts', {templateUrl:'/partial/account-list.html', controller:AccountListCtrl}). when('/Account', {templateUrl:'/partial/account-detail.html', controller:AccountCtrl}). @@ -72,9 +73,10 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte when('/Groups', {templateUrl:'/partial/group-list.html', controller:GroupListCtrl}). when('/Group', {templateUrl:'/partial/group-detail.html', controller:GroupCtrl}). - when('/Group/:id', {templateUrl:'/partial/group-detail.html', controller:GroupCtrl}); -// .otherwise({redirectTo: '/phones'}); - $locationProvider.html5Mode(true); + when('/Group/:id', {templateUrl:'/partial/group-detail.html', controller:GroupCtrl}). + + otherwise({templateUrl:'/partial/404.html'}); + $locationProvider.html5Mode(true).hashPrefix('!'); }]) .config(function ($httpProvider) { $httpProvider.responseInterceptors.push('spinnerInterceptor'); @@ -95,11 +97,13 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte return $q.reject(response); }); }; - }) - ; + }); -function BaseCtrl($scope, Permission) { - $scope.perms = Permission.get(); +function BaseCtrl($rootScope, $scope, Auth) { + $scope.auth = Auth.get(function (u, putResponseHeaders) { + console.log('got perms'); + $scope.perms = u.perms; + }); $scope.toasts = []; $scope.clearToast = function (item) { @@ -111,4 +115,15 @@ function BaseCtrl($scope, Permission) { }); } }; + + + $rootScope.$on("$routeChangeStart", function (event, next, current) { + $scope.toasts.push("Loading..."); + }); + $rootScope.$on("$routeChangeSuccess", function (event, current, previous) { + $scope.toasts.push("Successfully changed routes :)"); + }); + $rootScope.$on("$routeChangeError", function (event, current, previous, rejection) { + $scope.toasts.push("ROUTE CHANGE ERROR: " + rejection); + }); } diff --git a/brewman/brewman/static/scripts/scripts.js b/brewman/brewman/static/scripts/scripts.js deleted file mode 100644 index e4441f8c..00000000 --- a/brewman/brewman/static/scripts/scripts.js +++ /dev/null @@ -1,319 +0,0 @@ -jQuery.noConflict(); - -jQuery(document).ready(function($) { - /* Tweet widgets -------------------------------------------------------- */ - $(".widget-tweets .widget-content").tweet({ - username: "envato", - count: 3 - }); - - if($(".widget-last-tweet").length){ - $(".widget-last-tweet .widget-content").tweet({ - username: "envato", - count: 1 - }); - } - - - /* Forms validation ----------------------------------------------------- */ - //Validate form and send data to defined url file - $("#contact-form, #contact-form-widget").each(function () { - var url = $(this).attr('action'); /* Define server side script witch sends mail */ - var formItem = $(this); - - formItem.validate({ - submitHandler: function() { - var datastring = formItem.serialize(); - - $.ajax({ - type: "POST", - url: url, - data: datastring, - success: function(data){ - formItem.slideUp(); - formItem.next('.form-sent').fadeIn().html(data); - } - }); - } - }); - }); - - /* Widget contact form */ - $('#contact-form-widget p').each(function() { - labelText = $.trim($(this).find('label').text().replace('(Required *)', '')); - myInput = $(this).find('input:not(:submit), textarea'); - - // Hide label - $(this).find('label').remove(); - - $(myInput).val(labelText); - - // Remove placeholders - myInput.bind('focusin', {label: labelText}, function(event) { - if($(this).val() == event.data.label) { - $(this).val(''); - } - }); - - // Add placeholders - myInput.bind('focusout', {label: labelText}, function(event) { - if($(this).val() == '') { - $(this).val(event.data.label); - } - }); - }); - - /* Comment form validation */ - $('#comment-reply').validate(); - - - /* Remove no-js class from html attribute if JavaScript is enabled */ - $('html').removeClass('no-js'); - - - /* HTML5 Video player --------------------------------------------------- */ - VideoJS.setupAllWhenReady(); - - - /* Top navigation ------------------------------------------------------- */ - $("#header-navigation ul ul").css({display: "none"}); - $("#header-navigation a").removeAttr('title'); - - $("#header-navigation li:last").addClass('last'); - $("#header-navigation li li ul").parent().children('a').addClass('with-subnav'); - - // Background shift (background image offset -60px) + (link margin 21px) - $("#header-navigation > ul > li").each(function() { - shift = -60 + 21 + ($(this).children('a').width() / 2); - $(this).children('ul').css({backgroundPosition: shift + 'px -430px'}); - }); - - // Top level color animation - $("#header-navigation li").hover(function(){ - // Get color from page link element - linkColor = $('.navigation-wrapper').css('backgroundColor'); - $(this).children('a').stop(true, true).animate({color: linkColor}); - }, function() { - $(this).children('a').stop(true, true).animate({color: '#fff'}); - }); - - // Dropdown li a background - $("#header-navigation ul ul a").hover(function(){ - // Get color from navigation ul element - ddColor = $('#header-navigation').css('backgroundColor'); - $(this).stop().animate({backgroundColor: "#222"}, 'normal'); - }, function() { - $(this).stop().animate({backgroundColor: "#333"}, 'normal'); - }); - - // Dropdown animation - $("#header-navigation li").hover(function(){ - $(this).children('ul:first').css({visibility: "visible"}).stop(true, true).slideDown(400); - },function(){ - $(this).children('ul:first').stop(true, true).delay(100).fadeOut('fast'); - }); - - - /* Nivo slider ---------------------------------------------------------- */ - if($('.slider-nivo .slider-content, .gallery-inner').length) { - $('.slider-nivo .slider-content, .gallery-inner').nivoSlider({ - directionNav:true, - pauseTime: 5000 - }); - } - - - /* Accordion slider ----------------------------------------------------- */ - if($('.slider-kwicks').length) { - $('.slider-kwicks .slider-content').kwicks({ - isVertical: false, - sticky: false, - defaultKwick: 0, - spacing: 0, - max: 800, - duration: 1750, - easing: 'easeOutBack', - descrAnim: 700, - descrOpacity: 0.8 - }); - - - $(".slider-kwicks li .slide_caption").fadeTo(500, 0.4); - - $(".slider-kwicks li").hover(function(){ - $(this).find('.slide_caption').fadeTo(500, 1); - }, - function () { - $(this).find('.slide_caption').fadeTo(500, 0.4); - }); - } - - /* Carousel slider ------------------------------------------------------ */ - if($('.slider-carousel').length) { - $('.slider-carousel .slider-content').jcarousel({ - auto: 5, - animation: 'slow', - easing: 'jswing' - }); - } - - /* Static header */ - if($('.slider-wrapper').length) { - var getHeight = $('.slider-wrapper').height() + 140; - $('.navigation-wrapper').height(getHeight); - } - - if($('.slider-static').length) { - var getHeight = $('.slider-static').height() + 80; - $('.navigation-wrapper').height(getHeight); - } - - - /* Prettyphoto ---------------------------------------------------------- */ - if($("a[rel^='prettyPhoto']").length) { - $("a[rel^='prettyPhoto']").prettyPhoto({overlay_gallery: false}); - - $("a[rel^='prettyPhoto']").each(function(){ - // Get image sizes - if($(this).find('.portfolio-image-inner, .gallery-image-inner').length) { - width = $(this).find('.portfolio-image-inner, .gallery-image-inner').width(); - height = $(this).find('.portfolio-image-inner, .gallery-image-inner').height(); - } else { - width = $(this).find('img').width(); - height = $(this).find('img').height(); - } - - // Add "prettyPhoto" class and add a hidden span - $(this).addClass('prettyPhoto').append(''); - $(this).find('.zoom-frame').width(width).height(height); - - // Show "frame" on hover - $(this).hover(function() { - $(this).find('.zoom-frame').stop(true, true).fadeIn(); - }, function() { - $(this).find('.zoom-frame').stop(true, true).fadeOut(); - }); - }); - } - - - /* Search top ----------------------------------------------------------- */ - if($.browser.webkit) { - $('#title-search #seachField').css({height: '30px'}); - } - - $('#title-search #seachField') - .animate({width: '50px'}) - .blur(function(){ - if($('#title-search #seachField').val() == '') { - $(this).animate({width: '50px'}); - } - }); - - $('#title-search').hover(function(){ - $('#title-search #seachField').stop(true, true).animate({width: '180px'}); - }, function() { - if(($('#title-search #seachField').val() == '') && !($('#title-search #seachField').is(":focus"))) { - $('#title-search #seachField').stop(true, true).animate({width: '50px'}, 'slow'); - } - }); - - - /* Images preloader ----------------------------------------------------- */ - if($.browser.msie != true) { - $("img").hide(); - $("img").fadeIn("normal"); - } - - /* Widgets hover hint --------------------------------------------------- */ - $('.widget-hint').css({display: 'none'}); - $('.widget-hint').parent().css({position: "relative"}).hover(function() { - $(this).find('.widget-hint').stop(true, true).fadeIn(); - }, function() { - $(this).find('.widget-hint').stop(true, true).fadeOut(); - }); - - - /* Rounded corners for member's avatar - opera and firefox < v.4 fix ---- */ - if($.browser.opera || parseInt($.browser.mozilla) < 2){ - $('.team-member-img').each(function() { - background = $(this).children('img').attr('src'); - $(this).children('img').remove(); - - $('
').appendTo(this); - }); - }; - - - /* Tipsy ---------------------------------------------------------------- */ - $('.social a, .social-dark a, .pager-first a, .pager-last a, .postlist-footer a').tipsy({fade: true, gravity: 'n'}); - - - /* Tabs ----------------------------------------------------------------- */ - if($(".tabs-block").length) { - $('.tabs-block').each(function() { - // Hide all tabs content - $(this).find(".tabs-content").hide(); - - // Activate first tab - $(this).find(".tabs-controller li:first").addClass("active").show(); - $(this).find(".tabs-content:first").show(); - - // Click tab and make magic - $(this).find(".tabs-controller li").click(function() { - // Add "active" class to the current tab and remove it from others - $(this).addClass("active").siblings().removeClass("active"); - $(".tabs-content").hide(); - - // Get an ID of selected tab and show it - var activeTab = $(this).find("a").attr("href"); - $(activeTab).fadeIn(); - - // Disable link click - return false; - }); - }); - } - - - /* Toggles -------------------------------------------------------------- */ - if($('.toggle-block').length) { - $('.toggle-block').each(function() { - // Hide all toggles content - $(this).find(".toggle-content").hide(); - - // Click on toggle trigger and show the content - $(this).find(".toggle-trigger").click(function() { - $(this).toggleClass("active").next().stop(true, true).slideToggle('normal'); - - // Disable link click - return false; - }); - }); - } - - - /* Accordions ----------------------------------------------------------- */ - if($('.toggle-block').length) { - $('.accordion-block').each(function() { - // Hide all accordions content - $(this).find('.accordion-content').hide(); - - // Click on accordion item trigger and show the content - $(this).find('.accordion-trigger').click(function() { - // On click we close all slides and removes "on" class - $('.accordion-trigger').removeClass('active'); - $('.accordion-content').slideUp('normal'); - - // Open next to this trigger slider - if($(this).next().is(':hidden') == true) { - $(this).addClass('active'); - $(this).next().slideDown('normal'); - } - - // Disable link click - return false; - }); - }); - } -}); \ No newline at end of file diff --git a/brewman/brewman/static/scripts/session.js b/brewman/brewman/static/scripts/session.js deleted file mode 100644 index 120f93f9..00000000 --- a/brewman/brewman/static/scripts/session.js +++ /dev/null @@ -1,142 +0,0 @@ -function CurrentDate(matchFieldName, url) { - $.ajax({ - type:"POST", - contentType:"application/json; charset=utf-8", - url:url, - async:false, - data:{}, - dataType:"json", - success:function (response) { - $(matchFieldName).val(response); - }, - error:function (jqXHR, textStatus) { - $("#ctl00_statusDiv").removeClass().addClass("error"); - var msg = $.parseJSON(jqXHR.responseText).Message; - $("#ctl00_statusDiv").html(msg); - } - }); -} - -function StartDate(matchFieldName, url) { - $.ajax({ - type:"POST", - contentType:"application/json; charset=utf-8", - url:url, - async:false, - data:{}, - dataType:"json", - success:function (response) { - $(matchFieldName).val(response); - }, - error:function (jqXHR, textStatus) { - $("#ctl00_statusDiv").removeClass().addClass("error"); - var msg = $.parseJSON(jqXHR.responseText).Message; - $("#ctl00_statusDiv").html(msg); - } - }); -} - -function FinishDate(matchFieldName, url) { - $.ajax({ - type:"POST", - contentType:"application/json; charset=utf-8", - url:url, - async:false, - data:{}, - dataType:"json", - success:function (response) { - $(matchFieldName).val(response); - }, - error:function (jqXHR, textStatus) { - $("#ctl00_statusDiv").removeClass().addClass("error"); - var msg = $.parseJSON(jqXHR.responseText).Message; - $("#ctl00_statusDiv").html(msg); - } - }); -} - -function IsUserInRoles(roles, callback) { - $.ajax({ - type:"POST", - contentType:"application/json; charset=utf-8", - url:roles_url, - data:JSON.stringify({ roles:roles }), - dataType:"json", - success:callback, - error:function (jqXHR, textStatus) { - var msg = jqXHR.responseText; - $("#toast").html(msg); - } - }); -} -function getParameterByName(name) { - name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); - var regexS = "[\\?&]" + name + "=([^&#]*)"; - var regex = new RegExp(regexS); - var results = regex.exec(window.location.href); - if (results == null) - return ""; - else - return decodeURIComponent(results[1].replace(/\+/g, " ")); -} - -function getUrlFilename() { - var url = window.location.href; - matches = url.match(/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})/) - if (matches == null) - return null - else - return matches[1] -} - -function getUrlDate() { - var url = window.location.href; - matches = url.match(/([0-9]{2}-[a-zA-Z]{3}-[0-9]{4})/) - if (matches == null) - return null - else - return matches[1] -} - -Number.prototype.toAccounts = function () { - var n = this, c = 2, d = '.', t = ',', sign = (n < 0) ? ' Cr' : ' Dr', i = parseInt(n = Math.abs(n).toFixed(c)) + ''; - - var out = (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '') + sign; - - var pos = -1; - for (x = i.length; x >= 0; x--, pos++) { - if (pos == 3 || ((pos % 2) == 1 && pos > 3)) { - out = t + out; - } - out = i.charAt(x) + out; - } - return out; -} - -function SimpleDate(dateString) { - var date = new Date(parseInt(dateString.slice(6, -2))); - return date.format("dd-MMM-yyyy"); -} - - -function Login(url, csrf, username, password) { - var csrf = $("#_csrf").val(); - var username = $("#username").val(); - var password = $("#password").val(); - $.ajax({ - type:"POST", - contentType:"application/json; charset=utf-8", - url:url, - dataType:"json", - async:true, - data:JSON.stringify({name:username, password:password}), - success:function (response) { - alert(response.myid); - console.log("Parsed:!", response.myid); - }, - error:function (jqXHR, textStatus) { - alert(textStatus); - console.log(jqXHR.statusText); - } - }); -} diff --git a/brewman/brewman/static/scripts/sse.html b/brewman/brewman/static/scripts/sse.html deleted file mode 100644 index 4c679818..00000000 --- a/brewman/brewman/static/scripts/sse.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/brewman/brewman/static/scripts/voucher.js b/brewman/brewman/static/scripts/voucher.js deleted file mode 100644 index 29fc6e3e..00000000 --- a/brewman/brewman/static/scripts/voucher.js +++ /dev/null @@ -1,253 +0,0 @@ -var Voucher = Backbone.Model.extend({ - initialize:function () { - - if (!this.get('Journals')) { - this.set({Journals:new Journals()}); - } else { - this.Journals = new Journals(this.get('Journals')) - } - }, -// url:save_voucher_url - url:function () { - return document.URL; - } -}); - -var VoucherView = Backbone.View.extend({ - events:{ - 'change #txtDate':'change_date', - 'change #txtNarration':'change_narration' - }, - - initialize:function () { - this.model.on('change:Code', this.codeChanged, this); - this.model.on('change:Date', this.dateChanged, this); - this.model.on('change:Narration', this.narrationChanged, this); - this.model.on('change:VoucherID', this.idChanged, this); - this.idChanged(); - }, - change_date:function (ev) { - this.model.set({Date:$('#txtDate').val()}, {silent:true}) - }, - change_narration:function (ev) { - this.model.set({Narration:$('#txtNarration').val()}, {silent:true}) - }, - codeChanged:function (ev) { - $('#txtCode').val(this.model.get('Code')); - }, - narrationChanged:function (ev) { - $('#txtNarration').val(this.model.get('Narration')); - }, - dateChanged:function (ev) { - $('#txtDate').val(this.model.get('Date')); - }, - idChanged:function (ev) { - var isNew = (typeof this.model.get('VoucherID')) != 'undefined' ? false : true; - if (isNew) { - $("#btnSave").show(); - $("#btnUpdate").hide(); - $("#btnDelete").hide(); - $("#btnPost").hide(); - } - else { - $("#btnSave").hide(); - $("#btnUpdate").show(); - $("#btnDelete").show(); - $("#btnPost").show(); - } - } -}); - -var VoucherOps = Backbone.View.extend({ - events:{ - 'click #btnSave':'save', - 'click #btnUpdate':'save', - 'click #btnDelete':'delete', - 'click #btnPost':'post' - }, - save:function (ev) { - ev.preventDefault(); - this.model.save({}, { - wait:true, - success:function (model, response) { - var newModel = model.toJSON(); - var message = "Voucher with Code " + newModel.Code + " Created / Updated"; - $("#status").append('
Success! ' + message + '
'); - }, - error:showError}); - }, - delete:function (ev) { - ev.preventDefault(); - Delete($.proxy(function () { - this.model.clear(); - this.model.trigger("destroy"); - }, this)); - }, - post:function (ev) { - ev.preventDefault(); - Post($.proxy(function () { - this.model.set('Posted', true); - }, this)); - } -}); - -function Post(callback) { - $.ajax({ - type:"POST", - contentType:"application/json; charset=utf-8", - url:post_url, - data:{}, - dataType:"json", - success:function (response) { - callback(); - }, - error: showError - }); -} - -function Delete(callback) { - $.ajax({ - type:"POST", - contentType:"application/json; charset=utf-8", - url:delete_url, - data:{}, - dataType:"json", - success:function (response) { - callback(); - }, - error:showError - }); -} - -function backboneRoles(roles) { - IsUserInRoles(roles, function (response) { - var permissions = new Perms(); - $.each(response, function (index, row) { - if (row.Role == 'EditPosted') { - permissions.set('EditPosted', row.Allowed) - } else if (row.Role == 'PostTransactions') { - permissions.set('PostTransactions', row.Allowed) - } else if (row.Role.substr(-7) === ' Delete') { - permissions.set('Delete', row.Allowed) - } else if (row.Role.substr(-7) === ' Create') { - permissions.set('Create', row.Allowed) - } else if (row.Role.substr(-7) === ' Update') { - permissions.set('Update', row.Allowed) - } else { - permissions.set(row.Role, row.Allowed) - } - }) - window.perms.set(permissions.toJSON()); - }); -} - -var Perms = Backbone.Model.extend({ - defaults:{ - "EditPosted":false, - "PostTransactions":false, - "Delete":false, - "Create":false, - "Update":false - } -}); - -var RolesView = Backbone.View.extend({ - initialize:function () { - this.perms = this.options.perms; - this.voucher = this.options.voucher; - this.perms.on('change', this.rolesUpdated, this); - this.voucher.on('change:VoucherID', this.rolesUpdated, this); - this.voucher.on('change:Posted', this.rolesUpdated, this); - }, - - rolesUpdated:function (ev) { - function buttonShow(button, value) { - if (value) { - button.removeAttr('disabled'); - } - else { - button.attr('disabled', 'disabled'); - } - return value; - } - - var isNew = (typeof this.voucher.get('VoucherID')) != 'undefined' ? false : true; - var posted = (typeof this.voucher.get('Posted')) == 'undefined' ? false : this.voucher.get('Posted'); - - $("#btnPost").attr("value", posted ? 'Posted' : 'Post'); - - - if (isNew || posted || !this.perms.get('PostTransactions')) { - var postButton = false; - } else { - var postButton = true; - } - buttonShow($("#btnPost"), postButton); - - if (!isNew || !this.perms.get('Create')) { - var saveButton = false; - } else { - var saveButton = true; - } - buttonShow($("#btnSave"), saveButton); - - if (isNew || !this.perms.get('Update')) { - var updateButton = false; - } else if (posted && !this.perms.get('EditPosted')) { - var updateButton = false; - } else { - var updateButton = true; - } - buttonShow($("#btnUpdate"), updateButton); - - if (isNew || !this.perms.get('Delete')) { - var deleteButton = false; - } else if (posted && !this.perms.get('EditPosted')) { - var deleteButton = false; - } else { - var deleteButton = true; - } - buttonShow($("#btnDelete"), deleteButton); - } -}); - -function showError(jqXHR, response) { - $("#status").append('
Error! ' + response.responseText + '
'); -} - -function showSimpleError(error) { - $("#status").append('
Error! ' + error + '
'); -} - -var ShowAmountBox = Backbone.View.extend({ - events:{ - 'dblclick td.Editable':'show', - 'dblclick input.Editable':'hide' - }, - show:function (ev) { - ev.preventDefault(); - var cid = $(ev.target).closest("tr").attr("id"); - var model = this.collection.getByCid(cid); - var $input = $(''); - $input.attr("placeholder", model.get($(ev.target).data("column"))); - $(ev.target).html($input); - $(ev.target).toggleClass('Editable'); - }, - hide:function (ev) { - ev.preventDefault(); - var cid = $(ev.target).closest("tr").attr("id"); - var model = this.collection.getByCid(cid); - var originalValue = model.get($(ev.target).data("column")); - var newValue = $(ev.target).val(); - if (newValue != "" && newValue != originalValue) { - var column = $(ev.target).data("column"); - var ob = {}; - ob[column] = newValue; - model.set(ob); - } else { - $(ev.target).closest("td").toggleClass('Editable'); - $(ev.target).replaceWith(originalValue); - } - } -}); - diff --git a/brewman/brewman/subscribers.py b/brewman/brewman/subscribers.py index a67d0693..9ffe100f 100644 --- a/brewman/brewman/subscribers.py +++ b/brewman/brewman/subscribers.py @@ -1,18 +1,4 @@ -from pyramid.events import BeforeRender, subscriber, NewRequest -from brewman import helpers - -from pyramid.renderers import get_renderer - -@subscriber(BeforeRender) -def add_renderer_globals(event): - event['h'] = helpers - - -#@subscriber(BeforeRender) -#def add_base_template(event): -# base = get_renderer('brewman:templates/base.mako').implementation() -# event.update({'base': base}) - +from pyramid.events import subscriber, NewRequest @subscriber(NewRequest) def csrf_validation(event): diff --git a/brewman/brewman/templates/404.mako b/brewman/brewman/templates/404.mako deleted file mode 100644 index 827f78f0..00000000 --- a/brewman/brewman/templates/404.mako +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -<%inherit file="base.mako"/> -<%block name="content"> -
-
-

404

-

It looks like that page you were looking has been lost, sorry.

-
-
- - diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako index 0f1c7c25..4abdb8ce 100644 --- a/brewman/brewman/templates/angular_base.mako +++ b/brewman/brewman/templates/angular_base.mako @@ -8,56 +8,54 @@ - ${h.CssLink(request, 'style.css')} + - ${h.CssLink(request, 'bootstrap-responsive.css')} + + + - ${h.CssLink(request, 'jquery-ui-1.8.16.custom.css')} + + + - ${h.CssLink(request, 'spinner.css')} + + - ${h.JsLink(request, 'jquery-1.7.1.min.js')} - ${h.JsLink(request, 'jquery-ui-1.8.17.custom.min.js')} - ${h.JsLink(request, 'bootstrap.js')} + + + + + - ${h.JsLink(request, 'angular-1.0.1.js')} - ${h.JsLink(request, 'angular-resource-1.0.1.js')} + + + + + - ${h.ScriptLink(request, 'overlord.js')} - ${h.ScriptLink(request, 'angular_directive.js')} - ${h.ScriptLink(request, 'angular_filter.js')} - ${h.ScriptLink(request, 'angular_service.js')} - ${h.ScriptLink(request, 'session.js')} + + + + + + + + + + - ${h.ScriptLink(request, 'journal.js')} - ${h.ScriptLink(request, 'payment.js')} - ${h.ScriptLink(request, 'receipt.js')} - ${h.ScriptLink(request, 'purchase.js')} - ${h.ScriptLink(request, 'issue.js')} - - ${h.ScriptLink(request, 'ledger.js')} - ${h.ScriptLink(request, 'product-ledger.js')} - ${h.ScriptLink(request, 'trial-balance.js')} - ${h.ScriptLink(request, 'closing-stock.js')} - ${h.ScriptLink(request, 'profit-loss.js')} - ${h.ScriptLink(request, 'purchase-entries.js')} - ${h.ScriptLink(request, 'cash-flow.js')} - ${h.ScriptLink(request, 'raw-material-cost.js')} - ${h.ScriptLink(request, 'daybook.js')} - ${h.ScriptLink(request, 'unposted.js')} - - ${h.ScriptLink(request, 'account.js')} - ${h.ScriptLink(request, 'employee.js')} - ${h.ScriptLink(request, 'user.js')} - ${h.ScriptLink(request, 'group.js')} - ${h.ScriptLink(request, 'cost-center.js')} - ${h.ScriptLink(request, 'product.js')} - ${h.ScriptLink(request, 'product-group.js')} + + + + + + + @@ -73,7 +71,7 @@ - -
+
diff --git a/brewman/brewman/templates/auth/login.mako b/brewman/brewman/templates/auth/login.mako deleted file mode 100644 index f9a2bf3b..00000000 --- a/brewman/brewman/templates/auth/login.mako +++ /dev/null @@ -1,32 +0,0 @@ -# -*- coding: utf-8 -*- -<%inherit file="../base.mako"/> -<%block name="content"> -
-

Login

-
- ${h.CsrfToken(request.session)} - ${h.HiddenInput('came_from', value=came_from)} -
- -
- -
-
-
- -
- -
-
-
- -
- Forgot Username / Password -
-
-
- -
-
-
- \ No newline at end of file diff --git a/brewman/brewman/templates/base.mako b/brewman/brewman/templates/base.mako deleted file mode 100644 index dba9acc3..00000000 --- a/brewman/brewman/templates/base.mako +++ /dev/null @@ -1,103 +0,0 @@ - - - - - ${title} - - - - - - ${h.CssLink(request, 'style.css')} - - ${h.CssLink(request, 'bootstrap-responsive.css')} - - ${h.CssLink(request, 'jquery-ui-1.8.16.custom.css')} - - ${h.JsLink(request, 'jquery-1.7.1.min.js')} - ${h.JsLink(request, 'jquery-ui-1.8.17.custom.min.js')} - ${h.JsLink(request, 'bootstrap.js')} - ${h.JsLink(request, 'angular-1.0.1.js')} - ${h.JsLink(request, 'angular-resource-1.0.1.js')} - - - - ${h.ScriptLink(request, 'autocomplete.js')} - ${h.ScriptLink(request, 'session.js')} - - <%block name="header" /> - - - - - - - - - - - - - -
-
-
-
- - {{toast.Type}}! {{toast.Message}} -
-
-
- - <%block name="content"/> - ${self.body()} -
- -
-

© Company 2012

-
- -
- - - - - - diff --git a/brewman/brewman/templates/nav_bar/employee.pt b/brewman/brewman/templates/nav_bar/employee.pt deleted file mode 100644 index a0a9bd95..00000000 --- a/brewman/brewman/templates/nav_bar/employee.pt +++ /dev/null @@ -1,16 +0,0 @@ - diff --git a/brewman/brewman/templates/nav_bar/entry.pt b/brewman/brewman/templates/nav_bar/entry.pt deleted file mode 100644 index 2bea4682..00000000 --- a/brewman/brewman/templates/nav_bar/entry.pt +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/brewman/brewman/templates/nav_bar/login.pt b/brewman/brewman/templates/nav_bar/login.pt deleted file mode 100644 index 370ba061..00000000 --- a/brewman/brewman/templates/nav_bar/login.pt +++ /dev/null @@ -1,20 +0,0 @@ - diff --git a/brewman/brewman/templates/nav_bar/master.mako b/brewman/brewman/templates/nav_bar/master.mako deleted file mode 100644 index b2964702..00000000 --- a/brewman/brewman/templates/nav_bar/master.mako +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/brewman/brewman/templates/nav_bar/report.mako b/brewman/brewman/templates/nav_bar/report.mako deleted file mode 100644 index d6d35bf8..00000000 --- a/brewman/brewman/templates/nav_bar/report.mako +++ /dev/null @@ -1,26 +0,0 @@ - diff --git a/brewman/brewman/templates/nav_bar/voucher.mako b/brewman/brewman/templates/nav_bar/voucher.mako deleted file mode 100644 index 84463f30..00000000 --- a/brewman/brewman/templates/nav_bar/voucher.mako +++ /dev/null @@ -1,14 +0,0 @@ - diff --git a/brewman/brewman/views/__init__.py b/brewman/brewman/views/__init__.py index 2e3573ad..2919c217 100644 --- a/brewman/brewman/views/__init__.py +++ b/brewman/brewman/views/__init__.py @@ -4,11 +4,12 @@ import uuid from pyramid.view import view_config @view_config(route_name='home', renderer='brewman:templates/angular_base.mako') +@view_config(request_method='GET', route_name='login', renderer='brewman:templates/angular_base.mako', + xhr=False) def home(request): return {} - class DecimalAsFloatHack(float): def __init__(self, d): self.d = d diff --git a/brewman/brewman/views/employee.py b/brewman/brewman/views/employee.py index e1a6b99e..1dcd56bd 100644 --- a/brewman/brewman/views/employee.py +++ b/brewman/brewman/views/employee.py @@ -6,7 +6,6 @@ from pyramid.security import authenticated_userid from pyramid.view import view_config from sqlalchemy.sql.expression import or_ import transaction -from brewman.helpers import Literal from brewman.models import DBSession from brewman.models.master import CostCenter, Employee, AttendanceType diff --git a/brewman/brewman/views/nav_bar.py b/brewman/brewman/views/nav_bar.py deleted file mode 100644 index 5e792cea..00000000 --- a/brewman/brewman/views/nav_bar.py +++ /dev/null @@ -1,30 +0,0 @@ -import uuid -from pyramid.decorator import reify - -from brewman.models.auth import User - -from pyramid.renderers import render -from pyramid.security import authenticated_userid - -def report_menu(request): - return render('brewman:templates/nav_bar/report.mako', {'request': request}) - -def voucher_menu(request): - return render('brewman:templates/nav_bar/voucher.mako', {'request': request}) - -def entry_menu(request): - return render('brewman:templates/nav_bar/entry.pt', {'request': request}) - -def employee_menu(request): - return render('brewman:templates/nav_bar/employee.pt', {'request': request}) - -def master_menu(request): - return render('brewman:templates/nav_bar/master.mako', {'request': request}) - -def login_menu(request): - user_id = authenticated_userid(request) - if user_id == None: - user = None - else: - user = User.get_by_id(uuid.UUID(user_id)) - return render('brewman:templates/nav_bar/login.pt', {'request': request, 'user': user}) \ No newline at end of file diff --git a/brewman/brewman/views/pages.py b/brewman/brewman/views/pages.py index 60172612..f1ea31b9 100644 --- a/brewman/brewman/views/pages.py +++ b/brewman/brewman/views/pages.py @@ -1,70 +1,18 @@ import os -from pyramid.httpexceptions import HTTPNotFound, HTTPFound, HTTPForbidden -from pyramid.response import Response, FileResponse -from pyramid.security import remember, forget +from pyramid.httpexceptions import HTTPFound +from pyramid.response import FileResponse +from pyramid.security import forget from pyramid.view import view_config -from brewman.models.auth import User - - -@view_config(context=HTTPNotFound, renderer='brewman:templates/404.mako') -def not_found(request): - return {'title': '404', - 'pageclass': "page-404 skin-9", - 'pagecontentclass': "page-content", - 'top_block': "", - 'page_header': ''} - - -@view_config(context=HTTPForbidden, renderer='brewman:templates/auth/login.mako') -@view_config(route_name='login', renderer='brewman:templates/auth/login.mako') -def login_submit(request): - login_url = request.route_url('login') - referrer = request.url - if referrer == login_url: - referrer = request.route_url('home') # never use the login form itself as came_from - came_from = referrer - if request.method == 'POST': - if request.POST['came_from'] != '': - came_from = request.POST['came_from'] - - username = request.POST['username'] - password = request.POST['password'] - - found, user = User.auth(username, password) - if found: - headers = remember(request, str(user.id)) - return HTTPFound(location=came_from, headers=headers) - return {'title': 'Login', - 'pageclass': "page-gallery skin-7", - 'pagecontentclass': "page-content", - 'page_header': '', - 'came_from': came_from} - @view_config(route_name='logout') def logout(request): request.session.invalidate() - request.session.flash('Logged out successfully.') headers = forget(request) return HTTPFound(location=request.route_url('home'), headers=headers) -@view_config(request_method='POST', route_name='login', renderer='json', xhr=True) -def login_ajax(request): - username = request.json_body['name'] - password = request.json_body['password'] - - found, user = User.auth(username, password) - if found: - headers = remember(request, str(user.id)) - request.session.flash('Logged in successfully.') - return HTTPFound(location=request.route_url('home'), headers=headers) - else: - return Response('name ' + username + ' Login Failure ' + password) - - @view_config(route_name='favicon') def favicon(request): here = os.path.dirname(__file__) diff --git a/brewman/brewman/views/reports/closing_stock.py b/brewman/brewman/views/reports/closing_stock.py index 4f5c2316..fddb06da 100644 --- a/brewman/brewman/views/reports/closing_stock.py +++ b/brewman/brewman/views/reports/closing_stock.py @@ -19,11 +19,13 @@ def get_html(request): @view_config(request_method='GET', route_name='closing_stock', renderer='json', xhr=True) def report_blank(request): + print('getting closing stock') return {'Date': services_session_period_finish(request), 'Body': []} @view_config(request_method='GET', route_name='closing_stock_date', renderer='json', xhr=True) def report_data(request): + print('getting closing stock date') date = request.matchdict.get('date', None) return {'Date': date, 'Body': build_report(date)} diff --git a/brewman/brewman/views/services/session.py b/brewman/brewman/views/services/session.py index b0238771..44687638 100644 --- a/brewman/brewman/views/services/session.py +++ b/brewman/brewman/views/services/session.py @@ -1,9 +1,12 @@ from datetime import date, timedelta import json -from pyramid.security import authenticated_userid +import uuid +from pyramid.httpexceptions import HTTPFound +from pyramid.response import Response +from pyramid.security import authenticated_userid, remember from pyramid.view import view_config -from brewman.models.auth import Role +from brewman.models.auth import Role, User from brewman.views.transactions import session_current_date @view_config(route_name='services_session_current_date', renderer='json', xhr=True) @@ -47,14 +50,39 @@ def is_user_in_roles(request): return roles -@view_config(route_name='user_permissions', renderer='json', xhr=True) +@view_config(route_name='auth', renderer='json', xhr=True) def user_permission(request): user_id = authenticated_userid(request) - session_perms = request.session['perms'] if user_id else [] - perms = {} - for item in Role.list(): - perms[item.name] = True if item.name in session_perms else False - return perms + if user_id is None: + auth = {'isAuthenticated': False, 'perms': {}} + else: + user = User.get_by_id(uuid.UUID(user_id)) + auth = {'isAuthenticated': True, 'Name': user.name} + session_perms = request.session['perms'] + perms = {} + for item in Role.list(): + perms[item.name] = True if item.name in session_perms else False + auth['perms'] = perms + return auth + + +@view_config(request_method='POST', route_name='login', renderer='json') +def login(request): + username = request.POST['username'] + password = request.POST['password'] + login_url = request.route_url('login') + referrer = request.url + if referrer == login_url: + referrer = request.route_url('home') # never use the login form itself as came_from + came_from = referrer + found, user = User.auth(username, password) + if found: + headers = remember(request, str(user.id)) + return HTTPFound(location=came_from, headers=headers) + else: + response = Response("Login failed") + response.status_int = 500 + return response def get_first_day(dt, d_years=0, d_months=0): diff --git a/brewman/brewman/views/transactions/__init__.py b/brewman/brewman/views/transactions/__init__.py index bc7bae5d..420dbdef 100644 --- a/brewman/brewman/views/transactions/__init__.py +++ b/brewman/brewman/views/transactions/__init__.py @@ -1,6 +1,5 @@ from datetime import date from pyramid.view import view_config -from brewman.helpers import Literal @view_config(request_method='GET', route_name='journal_id', renderer='brewman:templates/angular_base.mako', diff --git a/brewman/brewman/views/transactions/purchase_return.py b/brewman/brewman/views/transactions/purchase_return.py index 70eea144..32e41f08 100644 --- a/brewman/brewman/views/transactions/purchase_return.py +++ b/brewman/brewman/views/transactions/purchase_return.py @@ -8,7 +8,6 @@ from pyramid.response import Response from pyramid.security import authenticated_userid from pyramid.view import view_config -from brewman.helpers import Literal from brewman.models import DBSession from brewman.models.auth import User