cartodb-4.42/lib/assets/javascripts/builder/data/user-notifications.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
var _ = require('underscore');
var Backbone = require('backbone');
/**
* User Notifications
*
*/
var UserNotifications = Backbone.Model.extend({
sync: function (method, model, options) {
return Backbone.sync('update', model, options);
},
url: function () {
var baseUrl = this._configModel.get('base_url');
return baseUrl + '/api/v3/notifications/' + this.get('key');
},
initialize: function (attrs, opts) {
if (!opts.key) throw new Error('key is required');
if (!opts.configModel) throw new Error('configModel is required');
this._configModel = opts.configModel;
this.attributes = _.extend({ notifications: attrs }, { key: opts.key });
},
getKey: function (key) {
var notifications = this.get('notifications') || {};
return notifications[key];
},
setKey: function (key, value) {
var notifications = this.get('notifications') || {};
notifications[key] = value;
this.set('notifications', notifications);
}
});
module.exports = UserNotifications;