Merge remote-tracking branch 'origin/master' into HEAD

This commit is contained in:
Continuous Integration
2017-02-10 16:42:27 +11:00
11 changed files with 64 additions and 13 deletions

View File

@@ -11,7 +11,7 @@ angular.module("admin.enterprises")
$scope.StatusMessage = StatusMessage
$scope.$watch 'enterprise_form.$dirty', (newValue) ->
StatusMessage.display 'notice', 'You have unsaved changes' if newValue
StatusMessage.display 'notice', t('admin.unsaved_changes') if newValue
$scope.setFormDirty = ->
$scope.$apply ->
@@ -24,13 +24,12 @@ angular.module("admin.enterprises")
$scope.navClear()
enterprise_form.submit()
# Provide a callback for generating warning messages displayed before leaving the page. This is passed in
# from a directive "nav-check" in the page - if we pass it here it will be called in the test suite,
# and on all new uses of this contoller, and we might not want that.
enterpriseNavCallback = ->
if $scope.Enterprise.$dirty
"Your changes to the enterprise are not saved yet."
if $scope.enterprise_form.$dirty
t('admin.unsaved_confirm_leave')
# Register the NavigationCheck callback
NavigationCheck.register(enterpriseNavCallback)

View File

@@ -0,0 +1,16 @@
angular.module('admin.enterprises').directive 'enterpriseSwitcher', (NavigationCheck) ->
restrict: 'A'
require: 'ngModel'
link: (scope, element, attr, ngModel) ->
initial = element[0].getAttribute('data-initial')
element.on 'change', ->
if not NavigationCheck.confirmLeave()
# Reset the current dropdown selection if staying on page
ngModel.$setViewValue initial
ngModel.$render()
element.select2 'val', initial
return
NavigationCheck.clear() # Don't ask twice if leaving
window.location = element[0].querySelector('option[selected]').getAttribute('data-url')

View File

@@ -38,7 +38,6 @@ angular.module("admin.tagRules").controller "TagRulesCtrl", ($scope, $http, $fil
newRule.peferred_exchange_tags = []
newRule.preferred_matched_order_cycles_visibility = "visible"
tagGroup.rules.push(newRule)
$scope.enterprise_form.$setDirty()
$scope.updateRuleCounts()
$scope.addNewTag = ->
@@ -58,3 +57,4 @@ angular.module("admin.tagRules").controller "TagRulesCtrl", ($scope, $http, $fil
.success ->
tagGroup.rules.splice(index, 1)
$scope.updateRuleCounts()
$scope.enterprise_form.$setDirty()

View File

@@ -10,7 +10,6 @@ angular.module("admin.utils")
$rootScope.$on "$locationChangeStart", @locationChangeStartHandler
# Action for regular browser navigation.
onBeforeUnloadHandler: ($event) =>
message = @getMessage()
@@ -21,13 +20,17 @@ angular.module("admin.utils")
# Action for angular navigation.
locationChangeStartHandler: ($event) =>
message = @getMessage()
if message and not $window.confirm(message)
if not @confirmLeave()
$event.stopPropagation() if $event.stopPropagation
$event.preventDefault() if $event.preventDefault
$event.cancelBubble = true
$event.returnValue = false
# Check if leaving is okay
confirmLeave: =>
message = @getMessage()
!message or $window.confirm(message)
# Runs callback functions to retreive most recently added non-empty message.
getMessage: ->
message = null

View File

@@ -111,3 +111,27 @@
}
}
}
tags-input .tags li.tag-item {
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-ms-border-radius: 3px;
-o-border-radius: 3px;
border-radius: 3px;
margin: 2px 0 2px 3px;
background-image: none;
background-color: #5fa5e8;
border: none;
box-shadow: none;
color: white !important;
font-size: 85%;
height: 25px;
}
tags-input .tags .tag-item .remove-button {
color: white;
}
table th.actions .no-text[class*="icon-"], table td.actions .no-text[class*="icon-"] {
cursor: pointer;
}

View File

@@ -32,6 +32,12 @@ module EnterprisesHelper
Enterprise.managed_by(spree_current_user)
end
def editable_enterprises
OpenFoodNetwork::Permissions.new(spree_current_user).
editable_enterprises.
order('is_primary_producer ASC, name')
end
def enterprises_options enterprises
enterprises.map { |enterprise| [enterprise.name + ": " + enterprise.address.address1 + ", " + enterprise.address.city, enterprise.id.to_i] }
end

View File

@@ -2,7 +2,6 @@
-# ng-change is only valid for inputs, not for a form.
-# So we use onchange and have to get the scope to access the ng controller
= form_for [main_app, :admin, @enterprise], html: { name: "enterprise_form",
"ng-app" => 'admin.enterprises',
"ng-controller" => 'enterpriseCtrl',
'onchange' => 'angular.element(enterprise_form).scope().setFormDirty()',
} do |f|
@@ -11,8 +10,6 @@
%input.red{ type: "button", value: t(:update), ng: { click: "submit()", disabled: "!enterprise_form.$dirty" } }
%input{ type: "button", ng: { value: "enterprise_form.$dirty ? '#{t(:cancel)}' : '#{t(:close)}'", click: "cancel('#{main_app.admin_enterprises_path}')" } }
.row
.sixteen.columns.alpha
.four.columns.alpha

View File

@@ -4,7 +4,11 @@
= t('.editing')
= @enterprise.name
- content_for :app_wrapper_attrs do
= "ng-app='admin.enterprises'"
- content_for :page_actions do
%li= select :enterprise, :id, options_for_select(editable_enterprises.collect {|e| [e.name, e.id, {:'data-url' => "#{main_app.edit_admin_enterprise_path(e.permalink)}", :'ng-selected' => "selected==#{e.id}"}]}, @enterprise.id ), {}, {:'enterprise-switcher' => '', 'data-initial' => "#{@enterprise.id}", :'ng-init' => "selected='#{@enterprise.id}'", :'ng-model' => 'selected', :id => 'enterprise_switcher', :class => 'select2'}
%li= button_link_to t('.back_link'), main_app.admin_enterprises_path, icon: 'icon-arrow-left'
= render 'admin/enterprises/form_data'

View File

@@ -81,6 +81,7 @@ en-GB:
tag_has_rules: "Existing rules for this tag: %{num}"
has_one_rule: "has one rule"
has_n_rules: "has %{num} rules"
unsaved_confirm_leave: "There are unsaved changed on this page. Continue without saving?"
customers:
index:
add_customer: "Add Customer"

View File

@@ -117,6 +117,9 @@ en:
has_one_rule: "has one rule"
has_n_rules: "has %{num} rules"
unsaved_confirm_leave: "There are unsaved changed on this page. Continue without saving?"
unsaved_changes: "You have unsaved changes"
customers:
index:
add_customer: "Add Customer"

View File

@@ -28,8 +28,6 @@ describe "TagRulesCtrl", ->
scope.addNewRuleTo(scope.tagGroups[0], "DiscountOrder")
it "adds a new rule of the specified type to the rules array for the tagGroup", ->
expect(scope.enterprise_form.$setDirty).toHaveBeenCalled()
expect(scope.tagGroups[0].rules.length).toEqual 3
expect(scope.tagGroups[0].rules[2].type).toEqual "TagRule::DiscountOrder"