mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-24 22:11:01 -06:00
This commit is contained in:
parent
990f210f34
commit
05a44d52d1
@ -219,6 +219,40 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
// Add dynamic option creation
|
// Add dynamic option creation
|
||||||
$(".options-tags").select2({
|
$(".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[]">
|
name="options[]">
|
||||||
{% if count(options) %}
|
{% if count(options) %}
|
||||||
{% for option in options %}
|
{% for option in options %}
|
||||||
<option selected="selected">{{ option.name }}</option>
|
<option id="advOption{{ option.id }}" selected="selected">{{ option.name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@ -575,25 +575,24 @@ class AdvsController extends PublicController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create options
|
// Create options
|
||||||
$optionsIds = array();
|
$deletedOptions = $request->deleted_options;
|
||||||
foreach ($request->options as $optionValue) {
|
$newOptions = $request->new_options;
|
||||||
$option = $this->optionRepository->newQuery()
|
if (!empty($deletedOptions)) {
|
||||||
->where('name', $optionValue)
|
$deletedOptions = explode(',', $request->deleted_options);
|
||||||
|
$this->optionRepository->newQuery()
|
||||||
|
->whereIn('id', $deletedOptions)
|
||||||
->where('adv_id', $request->update_id)
|
->where('adv_id', $request->update_id)
|
||||||
->first();
|
->delete();
|
||||||
if (!$option) {
|
}
|
||||||
$option = $this->optionRepository->create([
|
if (!empty($newOptions)) {
|
||||||
'name' => $optionValue,
|
$newOptions = explode(',', $request->new_options);
|
||||||
|
foreach ($newOptions as $option) {
|
||||||
|
$this->optionRepository->create([
|
||||||
|
'name' => $option,
|
||||||
'adv_id' => $request->update_id,
|
'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->is_get_adv = $request->is_get_adv;
|
||||||
$adv->save();
|
$adv->save();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user