cartodb-4.42/lib/assets/javascripts/builder/components/modals/publish/privacy-collection.js
2024-04-06 05:25:13 +00:00

48 lines
1.1 KiB
JavaScript
Executable File

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});
}
});
}
}
});