Have tags selected be handled universally throughout the entire repository view page.
This commit is contained in:
parent
ea61a68bcb
commit
347bf31f2d
9 changed files with 154 additions and 85 deletions
|
@ -2,9 +2,14 @@
|
|||
* Service which provides helper methods for performing some simple UI operations.
|
||||
*/
|
||||
angular.module('quay').factory('UIService', [function() {
|
||||
var CheckStateController = function(items) {
|
||||
var CheckStateController = function(items, opt_checked) {
|
||||
this.items = items;
|
||||
this.checked = [];
|
||||
this.checked = opt_checked || [];
|
||||
this.listeners_ = [];
|
||||
};
|
||||
|
||||
CheckStateController.prototype.listen = function(callback) {
|
||||
this.listeners_.push(callback);
|
||||
};
|
||||
|
||||
CheckStateController.prototype.isChecked = function(item) {
|
||||
|
@ -25,22 +30,32 @@ angular.module('quay').factory('UIService', [function() {
|
|||
} else {
|
||||
this.checked = this.items.slice();
|
||||
}
|
||||
this.callListeners_();
|
||||
};
|
||||
|
||||
CheckStateController.prototype.checkByFilter = function(filter) {
|
||||
this.checked = $.grep(this.items, filter);
|
||||
this.callListeners_();
|
||||
};
|
||||
|
||||
CheckStateController.prototype.checkItem = function(item) {
|
||||
this.checked.push(item);
|
||||
this.callListeners_();
|
||||
};
|
||||
|
||||
CheckStateController.prototype.uncheckItem = function(item) {
|
||||
this.checked = $.grep(this.checked, function(cItem) {
|
||||
return cItem != item;
|
||||
});
|
||||
this.callListeners_();
|
||||
};
|
||||
|
||||
CheckStateController.prototype.callListeners_ = function() {
|
||||
var checked = this.checked;
|
||||
this.listeners_.map(function(listener) {
|
||||
listener(checked);
|
||||
});
|
||||
};
|
||||
|
||||
var uiService = {};
|
||||
|
||||
|
@ -73,8 +88,8 @@ angular.module('quay').factory('UIService', [function() {
|
|||
}
|
||||
};
|
||||
|
||||
uiService.createCheckStateController = function(items) {
|
||||
return new CheckStateController(items);
|
||||
uiService.createCheckStateController = function(items, opt_checked) {
|
||||
return new CheckStateController(items, opt_checked);
|
||||
};
|
||||
|
||||
return uiService;
|
||||
|
|
Reference in a new issue