// Generated by CoffeeScript 1.12.7
/**
* Get tags and vote for them
* @module
*/
'use strict';
app.directive('tags', [
'constantService', 'messageService', 'tooltipService', '$sce', function(constants, messages, tooltips, $sce) {
return {
restrict: 'E',
templateUrl: 'site/tags.html',
scope: {
targetFn: '&target',
editFn: '&?edit'
},
link: function($scope, $element, $attrs) {
var edit, include, keyword, t, target;
target = $scope.targetFn();
$scope.keyword = keyword = 'keyword' in $attrs;
edit = typeof $scope.editFn === "function" ? $scope.editFn() : void 0;
include = keyword ? function(t) {
return t.keyword;
} : function(t) {
return t.weight;
};
$scope.tags = (function() {
var j, len, ref, results;
ref = target.tags;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
t = ref[j];
if (include(t)) {
results.push(t);
}
}
return results;
})();
if (edit) {
$scope.target = target["class"] === 'volume' ? target.top : target;
$scope.vote = function(name, vote) {
messages.clear($scope);
return $scope.target.setTag(name, vote, keyword).then(function(tag) {
var i, ref, ref1;
if ((ref = tag.keyword) != null ? ref.length : void 0) {
tag.keyword = true;
}
if ((ref1 = tag.vote) != null ? ref1.length : void 0) {
tag.vote = true;
}
i = $scope.tags.findIndex(function(t) {
return t.id === tag.id;
});
if (i === -1) {
i = $scope.tags.length;
}
if (include(tag)) {
$scope.tags[i] = tag;
} else {
$scope.tags.splice(i, 1);
}
messages.add({
type: 'green',
body: constants.message('tags.vote.success.' + (vote ? 'up' : 'null'), {
sce: $sce.HTML
}, tag.id),
owner: $scope
});
tooltips.clear();
}, function(res) {
messages.addError({
body: constants.message('tags.vote.error', {
sce: $sce.HTML
}, name),
report: res,
owner: $scope
});
});
};
}
}
};
}
]);
//# sourceMappingURL=tags.js.map