2015-07-28 12:29:40 -04:00
|
|
|
const UserField = Ember.Object.extend({
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
const self = this;
|
2014-09-25 11:32:08 -04:00
|
|
|
return new Ember.RSVP.Promise(function(resolve) {
|
2015-07-28 12:29:40 -04:00
|
|
|
const id = self.get('id');
|
2014-09-25 11:32:08 -04:00
|
|
|
if (id) {
|
|
|
|
return Discourse.ajax("/admin/customize/user_fields/" + id, { type: 'DELETE' }).then(function() {
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-07-28 12:29:40 -04:00
|
|
|
save(attrs) {
|
|
|
|
const id = this.get('id');
|
2014-09-25 11:32:08 -04:00
|
|
|
if (!id) {
|
|
|
|
return Discourse.ajax("/admin/customize/user_fields", {
|
|
|
|
type: "POST",
|
2014-09-26 14:48:34 -04:00
|
|
|
data: { user_field: attrs }
|
2014-09-25 11:32:08 -04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return Discourse.ajax("/admin/customize/user_fields/" + id, {
|
|
|
|
type: "PUT",
|
2014-09-26 14:48:34 -04:00
|
|
|
data: { user_field: attrs }
|
2014-09-25 11:32:08 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-28 12:29:40 -04:00
|
|
|
const UserFieldType = Ember.Object.extend({
|
|
|
|
name: Discourse.computed.i18n('id', 'admin.user_fields.field_types.%@')
|
|
|
|
});
|
|
|
|
|
2014-09-25 11:32:08 -04:00
|
|
|
UserField.reopenClass({
|
2015-07-28 12:29:40 -04:00
|
|
|
findAll() {
|
2014-09-25 11:32:08 -04:00
|
|
|
return Discourse.ajax("/admin/customize/user_fields").then(function(result) {
|
|
|
|
return result.user_fields.map(function(uf) {
|
|
|
|
return UserField.create(uf);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-07-28 12:29:40 -04:00
|
|
|
fieldTypes() {
|
2014-12-12 13:28:20 -05:00
|
|
|
if (!this._fieldTypes) {
|
|
|
|
this._fieldTypes = [
|
2015-07-28 12:29:40 -04:00
|
|
|
UserFieldType.create({ id: 'text' }),
|
|
|
|
UserFieldType.create({ id: 'confirm' }),
|
|
|
|
UserFieldType.create({ id: 'dropdown', hasOptions: true })
|
2014-12-12 13:28:20 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._fieldTypes;
|
2014-09-25 11:32:08 -04:00
|
|
|
},
|
|
|
|
|
2015-07-28 12:29:40 -04:00
|
|
|
fieldTypeById(id) {
|
2014-12-12 13:28:20 -05:00
|
|
|
return this.fieldTypes().findBy('id', id);
|
2014-09-25 11:32:08 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default UserField;
|