Initial commit
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
var Backbone = require('backbone');
|
||||
var PrivacyModel = require('./privacy-model');
|
||||
var PasswordModel = require('./privacy-password-model');
|
||||
|
||||
/**
|
||||
* Collection that holds the different privacy options.
|
||||
*/
|
||||
module.exports = Backbone.Collection.extend({
|
||||
|
||||
model: function (attrs, options) {
|
||||
if (attrs.privacy === 'PASSWORD') {
|
||||
return new PasswordModel(attrs, options);
|
||||
} else {
|
||||
return new PrivacyModel(attrs, options);
|
||||
}
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
this.bind('change:selected', this._deselectLastSelected, this);
|
||||
},
|
||||
|
||||
searchByPrivacy: function (privacy) {
|
||||
return this.findWhere({privacy: privacy});
|
||||
},
|
||||
|
||||
selectedOption: function () {
|
||||
return this.find(function (option) {
|
||||
return option.get('selected');
|
||||
});
|
||||
},
|
||||
|
||||
passwordOption: function () {
|
||||
return this.find(function (option) {
|
||||
return option.get('privacy') === 'PASSWORD';
|
||||
});
|
||||
},
|
||||
|
||||
_deselectLastSelected: function (m, isSelected) {
|
||||
if (isSelected) {
|
||||
this.each(function (option) {
|
||||
if (option !== m) {
|
||||
option.set({selected: false});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user