diff --git a/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php b/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php
index 7fcddb0b28..634d69b028 100644
--- a/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php
+++ b/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php
@@ -124,6 +124,39 @@ public function addElement(Request $request, $file_id)
/** @var LazaretManipulator $lazaretManipulator */
$lazaretManipulator = $this->app['manipulator.lazaret'];
+ //Check if the chosen record is eligible to the substitution
+ $recordId = $request->request->get('record_id');
+ /** @var LazaretFile $lazaretFile */
+ $lazaretFile = $this->getLazaretFileRepository()->find($file_id);
+
+ $metadatasToSet = [];
+ if(!!$request->request->get('copy_meta', false)) {
+
+ $substitutedRecord = null;
+ foreach ($lazaretFile->getRecordsToSubstitute($this->app) as $r) {
+ if ($r->getRecordId() === (int)$recordId) {
+ $substitutedRecord = $r;
+ break;
+ }
+ }
+ if (!$substitutedRecord) {
+ $ret['message'] = $this->app->trans('The destination record provided is not allowed');
+
+ return $this->app->json($ret);
+ }
+
+ $fieldsToCopy = [];
+ foreach ($substitutedRecord->getDatabox()->get_meta_structure() as $df) {
+ if(!$df->is_readonly()) {
+ $fieldsToCopy[] = $df->get_name();
+ }
+ }
+ $metadatas = [];
+ foreach ($substitutedRecord->getCaption($fieldsToCopy) as $k=>$v) {
+ $metadatasToSet[] = ['field_name' => $k, 'value' => $v];
+ }
+ }
+
$ret = $lazaretManipulator->add($file_id, $keepAttributes, $attributesToKeep);
try{
@@ -132,7 +165,13 @@ public function addElement(Request $request, $file_id)
$postStatus = (array) $request->request->get('status');
// update status
$this->updateRecordStatus($record, $postStatus);
- }catch(\Exception $e){
+
+ if(!empty($metadatasToSet)) {
+ $actions = json_decode(json_encode(['metadatas' => $metadatasToSet]));
+ $record->setMetadatasByActions($actions);
+ }
+ }
+ catch(\Exception $e){
$ret['message'] = $this->app->trans('An error occured when wanting to change status!');
}
@@ -209,16 +248,14 @@ public function acceptElement(Request $request, $file_id)
return $this->app->json($ret);
}
- $found = false;
//Check if the chosen record is eligible to the substitution
+ $found = false;
foreach ($lazaretFile->getRecordsToSubstitute($this->app) as $record) {
- if ($record->getRecordId() !== (int) $recordId) {
- continue;
+ if ($record->getRecordId() === (int) $recordId) {
+ $found = true;
+ break;
}
-
- $found = true;
- break;
}
if (!$found) {
diff --git a/templates/web/prod/upload/lazaret.html.twig b/templates/web/prod/upload/lazaret.html.twig
index 5c8796ddd2..27e009d97d 100644
--- a/templates/web/prod/upload/lazaret.html.twig
+++ b/templates/web/prod/upload/lazaret.html.twig
@@ -33,8 +33,9 @@
+ {# @var file \Alchemy\Phrasea\Model\Entities\LazaretFile #}
{% for file in lazaretFiles %}
- -
+
-
{{ _self.lazaretElement(app, file) }}
{% endfor %}
@@ -73,6 +74,7 @@
button.closest(".btn-group").removeClass('loading');
}
+
function reloadContent(force) {
var nbItems = scope.find(".wrapper-item").length;
@@ -92,16 +94,16 @@
}
}
- /* $(".records-subititution .diapo", scope)
+ /* $(".record-proposal .diapo", scope)
.bind('click', function(e){
$(this).closest('.lazaret-proposals').find('.diapo').removeClass('selected');
$(this).addClass('selected');
}
);*/
- $(".records-subititution .captionTips", scope).tooltip();
- $(".records-subititution .infoTips", scope).tooltip();
- $(".records-subititution .previewTips", scope).tooltip();
+ $(".record-proposal .captionTips", scope).tooltip();
+ $(".record-proposal .infoTips", scope).tooltip();
+ $(".record-proposal .previewTips", scope).tooltip();
var emptying = false; // true=emptying, set to false to stop
@@ -176,17 +178,37 @@
emptying = true;
f();
});
+
+
var data;
+
+
//add lazaret file click action
$("button.add-lazaret", scope).bind('click', function () {
- var that = $(this);
+ const that = $(this);
+ const $elementRow = that.closest(".lazaretElement");
+ if(!$elementRow.attr("hasSelected")) {
+ return false;
+ }
var lazaretId = getLazaretId(that);
+
+
+ let $selectedProposals = $(".record-proposal .selected");
+ if($selectedProposals.length !== 1) {
+ alert(language.onlyOneRecord);
+ return false;
+ }
+ let recordId = $selectedProposals.first().attr("data-record_id");
+ let $form = $("FORM", $elementRow);
+
+ $(".record_id", $form).val(recordId);
+
var destinationCollectionId = getDestinationId(that);
var container = $(this).closest('.wrapper-item');
- var form = $(this).closest("form");
+
/*fix POST on firefox*/
- data = form.serializeArray();
+ data = $form.serializeArray();
var allData = that.parent().closest('.wrapper-item').find(".change-record-wrapper").html();
that.closest(".form-backup ").append(allData);
that.parent().closest('.wrapper-item').find(".change-record ").remove();
@@ -265,59 +287,64 @@
//update status list
- function resetStatus(that) {
- that.removeClass('selected');
- var html = that.parent().closest('.wrapper-item').find(".status-backup").html();
- that.parent().closest('.wrapper-item').find(".status-container").html('');
- that.parent().closest('.wrapper-item').find(".status-container").append(html);
+ function resetStatus($elementRow) {
+ let html = $(".status-backup", $elementRow).html();
+ $(".status-container", $elementRow).html('');
+ $(".status-container", $elementRow).append(html);
}
- function isRecordSelected(selected) {
+ function isRecordSelected($elementRow, selected) {
if(selected) {
- $('BUTTON.subtitute-lazaret').removeAttr('disabled');
- $('.copy_meta').show();
+ $elementRow.attr("hasSelected", true);
+// $('BUTTON.subtitute-lazaret', $elementRow).removeAttr('disabled');
+// $('BUTTON.subtitute-lazaret', $elementRow).show();
+ $('.copy_meta', $elementRow).show();
}
else {
- $('BUTTON.subtitute-lazaret').attr('disabled', "true");
- $('.copy_meta').hide();
- checkCopyMeta(false);
- $("#lazaretBox INPUT[name=copy_meta]").removeAttr("checked");
+ $elementRow.removeAttr("hasSelected");
+// $('BUTTON.subtitute-lazaret', $elementRow).attr('disabled', "true");
+// $('BUTTON.subtitute-lazaret', $elementRow).hide();
+// $('.copy_meta', $elementRow).hide();
+ $("INPUT[name=copy_meta]", $elementRow).removeAttr("checked");
+ checkCopyMeta($elementRow, false);
}
}
- function checkCopyMeta(checked) {
- const $b = $("BUTTON.add-lazaret .b_label");
+ function checkCopyMeta($elementRow, checked) {
+ const $b = $("BUTTON.add-lazaret .b_label", $elementRow);
if (checked) {
- console.log("checked");
- $b.text("checked")
+ $b.text("{{ "Add with caption" | trans }}")
}
else {
- console.log("unchecked");
- $b.text("unchecked")
+ $b.text("{{ "Add" | trans }}")
}
}
- $(".span12 img, .reset-status").click(function () {
- var that = $(this).closest('.wrapper-item').find('.lazaret-proposals .diapo');
- resetStatus(that);
+ // $(".span12 img, .reset-status").click(function () {
+ $(".reset-status").click(function () {
+ let $elementRow = $(this).closest(".lazaretElement");
+ resetStatus($elementRow);
});
- $(".records-subititution .diapo", scope).bind('click', function () {
+ $(".record-proposal .diapo", scope).bind('click', function () {
var that = $(this);
+ let $elementRow = that.closest(".lazaretElement");
+
var diapo = that.closest('.lazaret-proposals').find('.diapo');
var container = that.closest('.wrapper-item');
diapo.not(this).removeClass('selected');
/*Set selected or not to check for sending ajax request*/
if (that.hasClass("selected")) {
- resetStatus(that);
- isRecordSelected(false);
+ that.removeClass('selected');
+ resetStatus($elementRow);
+ isRecordSelected($elementRow, false);
}
else {
that.addClass('selected');
@@ -355,7 +382,7 @@
if (value['img_off'] != null) {
html += ' ';
}
- ;
+
html += '' + labelOff + '';
html += '';
html += '';
@@ -365,15 +392,15 @@
if (value['img_on'] != null) {
html += '';
}
- ;
+
html += '';
html += '';
}
- that.parent().closest('.wrapper-item').find(".status-container").html('');
- that.parent().closest('.wrapper-item').find(".status-container").append(html);
+ $(".status-container", $elementRow).html('');
+ $(".status-container", $elementRow).append(html);
- isRecordSelected(true);
+ isRecordSelected($elementRow, true);
}
},
complete: function () {
@@ -384,49 +411,39 @@
}
});
- $("INPUT[name=copy_meta]", scope).change(
+ $("INPUT[name=copy_meta]", scope).click(
function(event) {
- checkCopyMeta(event.target.checked);
+ const that = $(this);
+ const $elementRow = that.closest(".lazaretElement");
+ if(!$elementRow.attr("hasSelected")) {
+ return false;
+ }
+
+ checkCopyMeta($elementRow, event.target.checked);
}
);
//substitute lazaret file click action
- $("button.subtitute-lazaret", scope).bind('click', function () {
- var that = $(this);
- var lazaretId = getLazaretId(that);
- var container = $(this).closest('.wrapper-item');
-
- var nbProposals = $('.records-subititution', container).length;
- var elements = [];
- var nbElement = 0;
-
-
-
- if (nbProposals > 1) {
- elements = $(".selected", container);
- nbElement = elements.length;
- } else if (nbProposals == 1) {
- elements = $(".records-subititution > div", container);
- } else {
- return false;
+ $("button.subtitute-lazaret", scope).bind('click', function (event) {
+ const that = $(this);
+ const $elementRow = that.closest(".lazaretElement");
+ if(!$elementRow.attr("hasSelected")) {
+ return false;
}
- if (nbElement === 0 && nbProposals > 1) {
- alert(language.selectOneRecord);
+ var lazaretId = getLazaretId(that);
- return false;
- } else if (nbElement > 1) {
+ let $selectedProposals = $(".record-proposal .selected");
+ if($selectedProposals.length !== 1) {
alert(language.onlyOneRecord);
return false;
}
+ let recordId = $selectedProposals.first().attr("data-record_id");
+ let $form = $("FORM", $elementRow);
- var recordId = elements.first().attr("data-record_id");
- var form = $(this).closest("form");
- $(".record_id").val(recordId);
-
+ $(".record_id", $form).val(recordId);
- var form = $(this).closest("form");
- data = form.serializeArray();
+ data = $form.serializeArray();
var allData = that.parent().closest('.wrapper-item').find(".change-record-wrapper").html();
that.closest(".form-backup ").append(allData);
that.parent().closest('.wrapper-item').find(".change-record ").remove();
@@ -463,12 +480,13 @@
});
/*Toggle status block*/
$(".toggle-status").click(function () {
- debugger;
$(this).nextAll('.status-wrapper').first().toggleClass('hidden');
});
+
});
+{# @var file \Alchemy\Phrasea\Model\Entities\LazaretFile #}
{% macro lazaretElement(app, file) %}
{% import "common/thumbnail.html.twig" as thumb %}
{% set records = file.getRecordsToSubstitute(app, true) %}
@@ -510,11 +528,8 @@
{% endif %}
-
-
-