Skip to content

Commit

Permalink
Minor fixes to nestedMenus
Browse files Browse the repository at this point in the history
They are more flexible within the relation plugin now, but harder to
reuse elsewhere - which is probably ok. We'll see.
Could also be that we need the same behavior in other places too.
  • Loading branch information
LFDM committed May 29, 2014
1 parent 7300063 commit 3ebc589
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
12 changes: 9 additions & 3 deletions app/js/arethusa.relation/directives/nested_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ angular.module('arethusa.relation').directive('nestedMenu', [
relObj: '=',
labelObj: '=',
label: '=',
property: '@'
property: '=',
ancestors: '='
},
link: function(scope, element, attrs) {
var html = '\
<ul\
nested-menu-collection\
current="relObj"\
property="property"\
ancestors="ancestors"\
all="labelObj.nested">\
</ul>\
';
Expand All @@ -35,9 +37,13 @@ angular.module('arethusa.relation').directive('nestedMenu', [
scope.$apply(function() {
if (event.eventPhase === 2) { // at target, three would be bubbling!
scope.selectLabel();
relation.resetAncestors(scope.relObj);
if (scope.ancestors) {
relation.resetAncestors(scope.relObj);
}
}
if (scope.ancestors) {
relation.addAncestor(scope.relObj, scope.label);
}
relation.addAncestor(scope.relObj, scope.label);
});
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ angular.module('arethusa.relation').directive('nestedMenuCollection', function()
scope: {
current: '=',
all: '=',
target: '@'
property: '=',
ancestors: '='
},
template: '\
<ul>\
Expand All @@ -16,6 +17,7 @@ angular.module('arethusa.relation').directive('nestedMenuCollection', function()
nested-menu\
property="property"\
rel-obj="current"\
ancestors="ancestors"\
label="label"\
label-obj="labelObj">\
</li>\
Expand Down
16 changes: 16 additions & 0 deletions app/js/arethusa.relation/relation.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,26 @@ angular.module('arethusa.relation').service('relation', [
return relation.ancestors.join(' > ');
};

this.suffixOrPlaceholder = function(relation) {
return relation.suffix || '---';
};

this.addAncestor = function(relation, ancestor) {
relation.ancestors.unshift(ancestor);
};

this.usePrefix = function() {
return 'prefix';
};

this.useSuffix = function() {
return 'suffix';
};

this.defineAncestors = function() {
return true;
};

this.resetAncestors = function(relation) {
var ancestors = relation.ancestors;
while (ancestors.length > 0) {
Expand Down
15 changes: 14 additions & 1 deletion app/templates/relation.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,26 @@
<li>{{ plugin.prefixWithAncestors(obj.relation) }}
<ul
nested-menu-collection
property="prefix"
property="plugin.usePrefix()"
current="obj.relation"
ancestors="plugin.defineAncestors()"
all="plugin.relationValues.labels">
</ul>
</li>
</ul>
</div>
<div class="small-4 columns">
<ul class="nested-dropdown hover">
<li>{{ plugin.suffixOrPlaceholder(obj.relation) }}
<ul
nested-menu-collection
property="plugin.useSuffix()"
current="obj.relation"
all="plugin.relationValues.suffixes">
</ul>
</li>
</ul>
</div>
</div>
</div>

0 comments on commit 3ebc589

Please sign in to comment.