use a directive for navigation check to attach it to the page instead of the controller

This commit is contained in:
Rafael Schouten
2014-10-17 07:40:08 +11:00
parent 45b0581b7b
commit 245c1eb305
4 changed files with 8 additions and 6 deletions

View File

@@ -1,16 +1,14 @@
angular.module("admin.enterprises")
.controller "enterpriseCtrl", ($scope, longDescription, Enterprise, PaymentMethods, ShippingMethods, NavigationCheck) ->
.controller "enterpriseCtrl", ($scope, longDescription, Enterprise, PaymentMethods, ShippingMethods) ->
$scope.Enterprise = Enterprise.enterprise
$scope.PaymentMethods = PaymentMethods.paymentMethods
$scope.ShippingMethods = ShippingMethods.shippingMethods
# htmlVariable is used by textAngular wysiwyg for the long descrtiption.
$scope.htmlVariable = longDescription
# Provide a callback for a warning message displayed when leaving the page.
navigationCallback = ->
$scope.navigationCallback = ->
"You are editing an enterprise!"
NavigationCheck.register navigationCallback
for payment_method in $scope.PaymentMethods
payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids

View File

@@ -0,0 +1,4 @@
angular.module("admin.utils").directive "navigationCheck", (NavigationCheck)->
link: ($scope) ->
# Define navigationCallback on the controller.
NavigationCheck.register($scope.navigationCallback)

View File

@@ -3,7 +3,7 @@
= admin_inject_payment_methods
= admin_inject_shipping_methods
.sixteen.columns.alpha{ ng: { app: 'admin.enterprises', controller: 'enterpriseCtrl' } }
.sixteen.columns.alpha{ ng: { app: 'admin.enterprises', controller: 'enterpriseCtrl' }, "navigation-check" => "" }
.eleven.columns.alpha
= render 'form', f: f
.one.column  

View File

@@ -8,7 +8,7 @@
= render 'admin/shared/enterprises_sub_menu'
= form_for @enterprise_set, :url => main_app.bulk_update_admin_enterprises_path do |f|
= form_for @enterprise_set, url: main_app.bulk_update_admin_enterprises_path do |f|
%table#listing_enterprises.index
%colgroup
%col{style: "width: 25%;"}/