Isolated custom field removal
Dieser Commit ist enthalten in:
Ursprung
848a0dc0ca
Commit
155eabd377
8 geänderte Dateien mit 78 neuen und 17 gelöschten Zeilen
|
@ -13,7 +13,8 @@ export default Component.extend({
|
|||
tagName: 'tr',
|
||||
topicSerializers: ['topic_view', 'topic_list_item'],
|
||||
postSerializers: ['post'],
|
||||
categorySerializers: ['basic_category', 'topic_view', 'topic_list_item'],
|
||||
groupSerializers: ['basic_group'],
|
||||
categorySerializers: ['basic_category'],
|
||||
klassContent: generateContent(['topic', 'post', 'group', 'category'], 'klass'),
|
||||
typeContent: generateContent(['string', 'boolean', 'integer', 'json'], 'type'),
|
||||
showInputs: or('field.new', 'field.edit'),
|
||||
|
@ -37,9 +38,12 @@ export default Component.extend({
|
|||
close() {
|
||||
if (this.field.edit) {
|
||||
this.set('field.edit', false);
|
||||
} else {
|
||||
}
|
||||
},
|
||||
|
||||
destroy() {
|
||||
this.set('removing', true);
|
||||
this.removeField(this.field);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
|
@ -11,14 +11,10 @@ export default Controller.extend({
|
|||
actions: {
|
||||
addField() {
|
||||
this.get('customFields').pushObject(
|
||||
CustomWizardCustomField.create()
|
||||
CustomWizardCustomField.create({ edit: true })
|
||||
);
|
||||
},
|
||||
|
||||
removeField(field) {
|
||||
this.get('customFields').removeObject(field);
|
||||
},
|
||||
|
||||
saveFields() {
|
||||
this.set('saving', true);
|
||||
CustomWizardCustomField.saveFields(this.customFields)
|
||||
|
@ -29,9 +25,17 @@ export default Controller.extend({
|
|||
this.set('saveIcon', 'times');
|
||||
}
|
||||
setTimeout(() => this.set('saveIcon', ''), 5000);
|
||||
this.get('customFields').setEach('edit', false);
|
||||
}).finally(() => {
|
||||
this.set('saving', false);
|
||||
});
|
||||
},
|
||||
|
||||
removeField(field) {
|
||||
CustomWizardCustomField.removeField(field)
|
||||
.then(result => {
|
||||
this.get('customFields').removeObject(field);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
|
@ -23,6 +23,12 @@ CustomWizardCustomField.reopenClass({
|
|||
custom_fields: customFields
|
||||
})
|
||||
}).catch(popupAjaxError);
|
||||
},
|
||||
|
||||
removeField(field) {
|
||||
return ajax(`${basePath}/${field.name}`, {
|
||||
type: 'DELETE'
|
||||
}).catch(popupAjaxError);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -39,6 +39,14 @@
|
|||
<td><label>{{field.name}}</label></td>
|
||||
<td>
|
||||
{{d-button action="edit" icon="pencil-alt"}}
|
||||
{{#if field.edit}}
|
||||
{{d-button action="close" icon="times"}}
|
||||
{{else}}
|
||||
{{#if destroying}}
|
||||
{{loading-spinner size="small"}}
|
||||
{{else}}
|
||||
{{d-button action="destroy" icon="trash-alt"}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</td>
|
||||
{{/if}}
|
|
@ -589,6 +589,11 @@
|
|||
|
||||
td {
|
||||
vertical-align: top;
|
||||
|
||||
label {
|
||||
margin: 0;
|
||||
line-height: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
td:not(:last-of-type) {
|
||||
|
|
|
@ -21,6 +21,7 @@ Discourse::Application.routes.append do
|
|||
|
||||
get 'admin/wizards/custom-fields' => 'admin_custom_fields#index'
|
||||
put 'admin/wizards/custom-fields' => 'admin_custom_fields#update'
|
||||
delete 'admin/wizards/custom-fields/:name' => 'admin_custom_fields#destroy'
|
||||
|
||||
get 'admin/wizards/submissions' => 'admin_submissions#index'
|
||||
get 'admin/wizards/submissions/:wizard_id' => 'admin_submissions#show'
|
||||
|
|
|
@ -12,12 +12,17 @@ class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
|
|||
|
||||
if saved_field = CustomWizard::CustomField.find(field_param[:name])
|
||||
CustomWizard::CustomField::ATTRS.each do |attr|
|
||||
field_data[attr] = field_param[attr] || saved_field.send(attr)
|
||||
field_data[attr] = saved_field.send(attr)
|
||||
end
|
||||
field_id = saved_field.id
|
||||
end
|
||||
|
||||
fields_to_save.push(CustomWizard::CustomField.new(field_id, field_data))
|
||||
CustomWizard::CustomField::ATTRS.each do |attr|
|
||||
field_data[attr] = field_param[attr]
|
||||
end
|
||||
|
||||
field = CustomWizard::CustomField.new(field_id, field_data)
|
||||
fields_to_save.push(field)
|
||||
end
|
||||
|
||||
PluginStoreRow.transaction do
|
||||
|
@ -34,6 +39,16 @@ class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
|
|||
render json: success_json
|
||||
end
|
||||
|
||||
def destroy
|
||||
params.require(:name)
|
||||
|
||||
if CustomWizard::CustomField.destroy(params[:name])
|
||||
render json: success_json
|
||||
else
|
||||
render json: failed_json
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def custom_field_params
|
||||
|
|
|
@ -50,7 +50,7 @@ class ::CustomWizard::CustomField
|
|||
end
|
||||
|
||||
if self.class.save_to_store(id, key, data)
|
||||
self.class.reset
|
||||
self.class.invalidate_cache
|
||||
true
|
||||
else
|
||||
false
|
||||
|
@ -65,8 +65,10 @@ class ::CustomWizard::CustomField
|
|||
value = send(attr)
|
||||
i18n_key = "wizard.custom_field.error"
|
||||
|
||||
if REQUIRED.include?(attr) && value.blank?
|
||||
I18n.t("#{i18n_key}.required_attribute", attr: attr)
|
||||
if value.blank?
|
||||
if REQUIRED.include?(attr)
|
||||
add_error(I18n.t("#{i18n_key}.required_attribute", attr: attr))
|
||||
end
|
||||
next
|
||||
end
|
||||
|
||||
|
@ -170,4 +172,20 @@ class ::CustomWizard::CustomField
|
|||
record.save
|
||||
end
|
||||
end
|
||||
|
||||
def self.destroy(name)
|
||||
if exists?(name)
|
||||
PluginStoreRow.where(plugin_name: NAMESPACE, key: name).destroy_all
|
||||
invalidate_cache
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def self.invalidate_cache
|
||||
self.reset
|
||||
Discourse.clear_readonly!
|
||||
Discourse.request_refresh!
|
||||
end
|
||||
end
|
Laden …
In neuem Issue referenzieren