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