diff --git a/app/assets/javascripts/admin/admin.js.coffee b/app/assets/javascripts/admin/admin.js.coffee new file mode 100644 index 0000000000..474ae5ab1d --- /dev/null +++ b/app/assets/javascripts/admin/admin.js.coffee @@ -0,0 +1,3 @@ +Admin = angular.module("ofn.admin", ["ngResource", "ofn.shared_services", "ofn.shared_directives"]).config ($httpProvider) -> + $httpProvider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content") + $httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*" \ No newline at end of file diff --git a/app/assets/javascripts/admin/bulk_order_management.js.coffee b/app/assets/javascripts/admin/bulk_order_management.js.coffee index c151f4bc50..6d57d73bc9 100644 --- a/app/assets/javascripts/admin/bulk_order_management.js.coffee +++ b/app/assets/javascripts/admin/bulk_order_management.js.coffee @@ -1,16 +1,7 @@ -orderManagementModule = angular.module("ofn.bulk_order_management", ["ofn.shared_services", "ofn.shared_directives", "ofn.dropdown"]) - -orderManagementModule.config [ - "$httpProvider" - (provider) -> - provider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content") - provider.defaults.headers.common["Accept"] = "application/json" -] - -orderManagementModule.value "blankOption", -> +Admin.value "blankOption", -> { id: "0", name: "All" } -orderManagementModule.directive "ofnLineItemUpdAttr", [ +Admin.directive "ofnLineItemUpdAttr", [ "switchClass", "pendingChanges" (switchClass, pendingChanges) -> require: "ngModel" @@ -34,14 +25,14 @@ orderManagementModule.directive "ofnLineItemUpdAttr", [ switchClass( element, "update-pending", ["update-error", "update-success"], false ) ] -orderManagementModule.directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) -> +Admin.directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) -> restrict: "A" link: (scope, element, attrs) -> handler = ofnConfirmHandler scope, -> scope.fetchOrders() scope.$watch attrs.ngModel, (oldValue,newValue) -> handler() unless oldValue == undefined || newValue == oldValue -orderManagementModule.directive "ofnConfirmLinkPath", (ofnConfirmHandler) -> +Admin.directive "ofnConfirmLinkPath", (ofnConfirmHandler) -> restrict: "A" scope: path: "@ofnConfirmLinkPath" @@ -49,7 +40,7 @@ orderManagementModule.directive "ofnConfirmLinkPath", (ofnConfirmHandler) -> element.click ofnConfirmHandler scope, -> window.location = scope.path -orderManagementModule.factory "ofnConfirmHandler", (pendingChanges, $compile, $q) -> +Admin.factory "ofnConfirmHandler", (pendingChanges, $compile, $q) -> return (scope, callback) -> template = "
Unsaved changes currently exist, save now or ignore?
" dialogDiv = $compile(template)(scope) @@ -74,7 +65,7 @@ orderManagementModule.factory "ofnConfirmHandler", (pendingChanges, $compile, $q else callback() -orderManagementModule.factory "pendingChanges",[ +Admin.factory "pendingChanges",[ "dataSubmitter" (dataSubmitter) -> pendingChanges: {} @@ -108,7 +99,7 @@ orderManagementModule.factory "pendingChanges",[ ] -orderManagementModule.controller "AdminOrderMgmtCtrl", [ +Admin.controller "AdminOrderMgmtCtrl", [ "$scope", "$http", "dataFetcher", "blankOption", "pendingChanges" ($scope, $http, dataFetcher, blankOption, pendingChanges) -> @@ -290,7 +281,7 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [ $scope.quickSearch = "" ] -orderManagementModule.filter "selectFilter", (blankOption) -> +Admin.filter "selectFilter", (blankOption) -> return (lineItems,selectedSupplier,selectedDistributor,selectedOrderCycle) -> filtered = [] filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedSupplier,"0") || lineItem.supplier.id == selectedSupplier) && @@ -298,7 +289,7 @@ orderManagementModule.filter "selectFilter", (blankOption) -> (angular.equals(selectedOrderCycle,"0") || lineItem.order.order_cycle.id == selectedOrderCycle) filtered -orderManagementModule.filter "variantFilter", -> +Admin.filter "variantFilter", -> return (lineItems,selectedUnitsProduct,selectedUnitsVariant,sharedResource) -> filtered = [] filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedUnitsProduct,{}) || @@ -306,7 +297,7 @@ orderManagementModule.filter "variantFilter", -> filtered -orderManagementModule.factory "dataSubmitter", [ +Admin.factory "dataSubmitter", [ "$http", "$q", "switchClass" ($http, $q, switchClass) -> return (changeObj) -> @@ -320,7 +311,7 @@ orderManagementModule.factory "dataSubmitter", [ deferred.promise ] -orderManagementModule.factory "switchClass", [ +Admin.factory "switchClass", [ "$timeout" ($timeout) -> return (element,classToAdd,removeClasses,timeout) -> diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 20aee15b74..59de02c242 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -1,13 +1,4 @@ -productEditModule = angular.module("ofn.bulk_product_edit", ["ngResource", "ofn.shared_services", "ofn.shared_directives"]) - -productEditModule.config [ - "$httpProvider" - (provider) -> - provider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content") - provider.defaults.headers.common["Accept"] = "application/json" -] - -productEditModule.factory "Taxons", ($resource) -> +Admin.factory "Taxons", ($resource) -> resource = $resource "/admin/taxons/search" return { @@ -21,7 +12,7 @@ productEditModule.factory "Taxons", ($resource) -> data['taxons'].map (result) -> result } -productEditModule.directive "ofnTaxonAutocomplete", (Taxons) -> +Admin.directive "ofnTaxonAutocomplete", (Taxons) -> # Adapted from Spree's existing taxon autocompletion require: "ngModel" link: (scope,element,attrs,ngModel) -> @@ -43,7 +34,7 @@ productEditModule.directive "ofnTaxonAutocomplete", (Taxons) -> scope.$apply -> ngModel.$setViewValue element.val() -productEditModule.directive "ofnDecimal", -> +Admin.directive "ofnDecimal", -> require: "ngModel" link: (scope, element, attrs, ngModel) -> numRegExp = /^\d+(\.\d+)?$/ @@ -56,7 +47,7 @@ productEditModule.directive "ofnDecimal", -> viewValue -productEditModule.directive "ofnTrackProduct", ['$parse', ($parse) -> +Admin.directive "ofnTrackProduct", ['$parse', ($parse) -> require: "ngModel" link: (scope, element, attrs, ngModel) -> ngModel.$parsers.push (viewValue) -> @@ -68,7 +59,7 @@ productEditModule.directive "ofnTrackProduct", ['$parse', ($parse) -> ] -productEditModule.directive "ofnTrackVariant", ['$parse', ($parse) -> +Admin.directive "ofnTrackVariant", ['$parse', ($parse) -> require: "ngModel" link: (scope, element, attrs, ngModel) -> ngModel.$parsers.push (viewValue) -> @@ -82,7 +73,7 @@ productEditModule.directive "ofnTrackVariant", ['$parse', ($parse) -> viewValue ] -productEditModule.directive "ofnToggleVariants", -> +Admin.directive "ofnToggleVariants", -> link: (scope, element, attrs) -> if scope.displayProperties[scope.product.id].showVariants element.removeClass "icon-chevron-right" @@ -101,7 +92,7 @@ productEditModule.directive "ofnToggleVariants", -> element.removeClass "icon-chevron-right" element.addClass "icon-chevron-down" -productEditModule.controller "AdminProductEditCtrl", [ +Admin.controller "AdminProductEditCtrl", [ "$scope", "$timeout", "$http", "dataFetcher" ($scope, $timeout, $http, dataFetcher) -> $scope.updateStatusMessage = @@ -525,7 +516,7 @@ productEditModule.controller "AdminProductEditCtrl", [ Object.keys($scope.dirtyProducts).length ] -productEditModule.filter "rangeArray", -> +Admin.filter "rangeArray", -> return (input,start,end) -> input.push(i) for i in [start..end] input diff --git a/config/ng-test.conf.js b/config/ng-test.conf.js index e4d7fef84d..1887ad7903 100644 --- a/config/ng-test.conf.js +++ b/config/ng-test.conf.js @@ -13,12 +13,8 @@ module.exports = function(config) { 'app/assets/javascripts/shared/bindonce.min.js', 'app/assets/javascripts/shared/ng-infinite-scroll.min.js', - 'app/assets/javascripts/admin/shared_directives.js.coffee', - 'app/assets/javascripts/admin/shared_services.js.coffee', - 'app/assets/javascripts/admin/dropdown.js.coffee', - 'app/assets/javascripts/admin/order_cycle.js.erb.coffee', - 'app/assets/javascripts/admin/bulk_order_management.js.coffee', - 'app/assets/javascripts/admin/bulk_product_update.js.coffee', + 'app/assets/javascripts/admin/*.js.*', + 'app/assets/javascripts/admin/**/*.js*', 'app/assets/javascripts/darkswarm/*.js*', 'app/assets/javascripts/darkswarm/**/*.js*', 'spec/javascripts/unit/**/*.js*' @@ -27,7 +23,8 @@ module.exports = function(config) { exclude: [ '**/.#*', 'app/assets/javascripts/darkswarm/all.js.coffee', - 'app/assets/javascripts/darkswarm/overrides.js.coffee' + 'app/assets/javascripts/darkswarm/overrides.js.coffee', + 'app/assets/javascripts/admin/util.js.erb' ], coffeePreprocessor: { diff --git a/spec/javascripts/unit/bulk_order_management_spec.js.coffee b/spec/javascripts/unit/bulk_order_management_spec.js.coffee index 73dc80c13c..3e1c35f2d1 100644 --- a/spec/javascripts/unit/bulk_order_management_spec.js.coffee +++ b/spec/javascripts/unit/bulk_order_management_spec.js.coffee @@ -2,7 +2,7 @@ describe "AdminOrderMgmtCtrl", -> ctrl = scope = httpBackend = null beforeEach -> - module "ofn.bulk_order_management" + module "ofn.admin" beforeEach inject(($controller, $rootScope, $httpBackend) -> scope = $rootScope.$new() ctrl = $controller @@ -377,7 +377,7 @@ describe "managing pending changes", -> } beforeEach -> - module "ofn.bulk_order_management", ($provide) -> + module "ofn.admin", ($provide) -> $provide.value 'dataSubmitter', dataSubmitter return @@ -511,7 +511,7 @@ describe "dataSubmitter service", -> switchClassSpy = jasmine.createSpy('switchClass') beforeEach -> - module "ofn.bulk_order_management" , ($provide) -> + module "ofn.admin" , ($provide) -> $provide.value '$q', qMock $provide.value '$http', httpMock $provide.value 'switchClass', switchClassSpy @@ -557,7 +557,7 @@ describe "switchClass service", -> timeoutMock.cancel = jasmine.createSpy('timeout.cancel') beforeEach -> - module "ofn.bulk_order_management" , ($provide) -> + module "ofn.admin" , ($provide) -> $provide.value '$timeout', timeoutMock return diff --git a/spec/javascripts/unit/bulk_product_update_spec.js.coffee b/spec/javascripts/unit/bulk_product_update_spec.js.coffee index 942c2f109a..601b7d3c62 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js.coffee +++ b/spec/javascripts/unit/bulk_product_update_spec.js.coffee @@ -231,7 +231,7 @@ describe "filtering products for submission to database", -> describe "Maintaining a live record of dirty products and properties", -> parse = null beforeEach -> - module "ofn.bulk_product_edit" + module "ofn.admin" beforeEach inject(($parse) -> parse = $parse ) @@ -296,7 +296,7 @@ describe "AdminProductEditCtrl", -> ctrl = scope = timeout = httpBackend = null beforeEach -> - module "ofn.bulk_product_edit" + module "ofn.admin" beforeEach inject(($controller, $timeout, $rootScope, $httpBackend) -> scope = $rootScope.$new() ctrl = $controller @@ -1415,7 +1415,7 @@ describe "Taxons service", -> Taxons = $httpBackend = $resource = null beforeEach -> - module "ofn.bulk_product_edit" + module "ofn.admin" beforeEach inject (_Taxons_, _$resource_, _$httpBackend_) -> Taxons = _Taxons_