mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
This commit is contained in:
parent
990f210f34
commit
05a44d52d1
@ -219,6 +219,40 @@ $(document).ready(function () {
|
||||
|
||||
// Add dynamic option creation
|
||||
$(".options-tags").select2({
|
||||
tags: true
|
||||
tags: true,
|
||||
tokenSeparators: [',']
|
||||
});
|
||||
|
||||
let deletedOptions = [];
|
||||
$('#selectOptions').on('select2:unselect', function (e) {
|
||||
if (e.params.data.element.id) {
|
||||
const id = e.params.data.element.id.substr(9);
|
||||
deletedOptions.push(id);
|
||||
} else {
|
||||
let index = newOptions.indexOf(e.params.data.text);
|
||||
if (index > -1) {
|
||||
newOptions.splice(index, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let newOptions = [];
|
||||
$('#selectOptions').on('select2:select', function (e) {
|
||||
if (e.params.data.element) {
|
||||
let index = deletedOptions.indexOf(e.params.data.element.id.substr(9));
|
||||
if (index > -1) {
|
||||
deletedOptions.splice(index, 1);
|
||||
}
|
||||
} else {
|
||||
newOptions.push(e.params.data.text)
|
||||
}
|
||||
});
|
||||
|
||||
$('#createEditAdvForm').submit(function () {
|
||||
$(this).append(`<input type="hidden" name="deleted_options" value="${deletedOptions}" />`);
|
||||
|
||||
$(this).append(`<input type="hidden" name="new_options" value="${newOptions}" />`);
|
||||
|
||||
return true;
|
||||
})
|
||||
});
|
||||
|
||||
@ -104,7 +104,7 @@
|
||||
name="options[]">
|
||||
{% if count(options) %}
|
||||
{% for option in options %}
|
||||
<option selected="selected">{{ option.name }}</option>
|
||||
<option id="advOption{{ option.id }}" selected="selected">{{ option.name }}</option>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</select>
|
||||
|
||||
@ -575,25 +575,24 @@ class AdvsController extends PublicController
|
||||
}
|
||||
|
||||
// Create options
|
||||
$optionsIds = array();
|
||||
foreach ($request->options as $optionValue) {
|
||||
$option = $this->optionRepository->newQuery()
|
||||
->where('name', $optionValue)
|
||||
$deletedOptions = $request->deleted_options;
|
||||
$newOptions = $request->new_options;
|
||||
if (!empty($deletedOptions)) {
|
||||
$deletedOptions = explode(',', $request->deleted_options);
|
||||
$this->optionRepository->newQuery()
|
||||
->whereIn('id', $deletedOptions)
|
||||
->where('adv_id', $request->update_id)
|
||||
->first();
|
||||
if (!$option) {
|
||||
$option = $this->optionRepository->create([
|
||||
'name' => $optionValue,
|
||||
->delete();
|
||||
}
|
||||
if (!empty($newOptions)) {
|
||||
$newOptions = explode(',', $request->new_options);
|
||||
foreach ($newOptions as $option) {
|
||||
$this->optionRepository->create([
|
||||
'name' => $option,
|
||||
'adv_id' => $request->update_id,
|
||||
]);
|
||||
}
|
||||
$optionsIds[] = $option->id;
|
||||
}
|
||||
$this->optionRepository->newQuery()
|
||||
->whereNotIn('id', $optionsIds)
|
||||
->where('adv_id', $request->update_id)
|
||||
->delete();
|
||||
|
||||
|
||||
$adv->is_get_adv = $request->is_get_adv;
|
||||
$adv->save();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user