2017-10-26 21:47:24 +02:00
|
|
|
|
|
|
|
|
2017-10-29 18:46:37 +01:00
|
|
|
function EditMetadataDialog(metaData, targetRowElem) {
|
2017-10-26 21:47:24 +02:00
|
|
|
this._metaDataUIs = [];
|
|
|
|
this._metaData = metaData;
|
|
|
|
|
2017-11-09 02:30:01 +01:00
|
|
|
this._MetadataUI = function(tr, key, value, project) {
|
2017-10-26 21:47:24 +02:00
|
|
|
var self = this;
|
2017-11-10 04:29:08 +01:00
|
|
|
|
2017-11-17 23:14:19 +01:00
|
|
|
if (key === "date") {
|
2017-11-10 04:29:08 +01:00
|
|
|
return;
|
2017-11-17 23:14:19 +01:00
|
|
|
}
|
2017-11-10 04:29:08 +01:00
|
|
|
|
2017-10-26 21:47:24 +02:00
|
|
|
var td0 = tr.insertCell(0);
|
2018-11-17 21:42:34 +01:00
|
|
|
|
2019-06-06 18:15:25 +02:00
|
|
|
var keyLable = $.i18n('core-index/'+key) || key;
|
2018-11-17 21:42:34 +01:00
|
|
|
$(td0).text(keyLable);
|
2017-10-26 21:47:24 +02:00
|
|
|
|
|
|
|
var td1 = tr.insertCell(1);
|
2018-11-17 21:42:34 +01:00
|
|
|
$(td1).text((value !== null) ? value : "");
|
2017-10-26 21:47:24 +02:00
|
|
|
|
|
|
|
var td2 = tr.insertCell(2);
|
2017-10-29 18:46:37 +01:00
|
|
|
|
2017-12-07 00:59:36 +01:00
|
|
|
if(key==="tags"){
|
2018-11-17 21:42:34 +01:00
|
|
|
$('<button class="button">').text($.i18n('core-index/edit')).appendTo(td2).click(function() {
|
2017-12-08 00:46:59 +01:00
|
|
|
var oldTags = $(td1).text().replace("[","").replace("]","");
|
2017-12-07 00:59:36 +01:00
|
|
|
oldTags = replaceAll(oldTags,"\"","");
|
2018-11-17 21:42:34 +01:00
|
|
|
var newTags = window.prompt($.i18n('core-index/change-metadata-value')+" " + key, $(td1).text());
|
2017-12-08 00:46:59 +01:00
|
|
|
newTags = newTags.replace("[","").replace("]","");
|
2017-12-07 00:59:36 +01:00
|
|
|
newTags = replaceAll(newTags,"\"","");
|
|
|
|
if (newTags !== null) {
|
2018-11-17 21:42:34 +01:00
|
|
|
$(td1).text(newTags);
|
2017-12-07 00:59:36 +01:00
|
|
|
metaData[key] = newTags;
|
2019-10-14 15:04:38 +02:00
|
|
|
Refine.postCSRF(
|
|
|
|
"command/core/set-project-tags",
|
|
|
|
{
|
2017-12-07 00:59:36 +01:00
|
|
|
"project" : project,
|
|
|
|
"old" : oldTags,
|
|
|
|
"new" : newTags
|
|
|
|
},
|
2019-10-14 15:04:38 +02:00
|
|
|
function(data) {},
|
|
|
|
"json"
|
|
|
|
);
|
2017-12-07 00:59:36 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 00:46:59 +01:00
|
|
|
Refine.OpenProjectUI.refreshProject(targetRowElem, metaData, project);
|
2017-12-07 00:59:36 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-11 15:43:21 +01:00
|
|
|
if (key !== "created" &&
|
|
|
|
key !== "modified" &&
|
|
|
|
key !== "rowCount" &&
|
|
|
|
key !== "importOptionMetadata" &&
|
2017-12-07 00:59:36 +01:00
|
|
|
key !== "id" &&
|
|
|
|
key !== "tags") {
|
2018-11-17 21:42:34 +01:00
|
|
|
$('<button class="button">').text($.i18n('core-index/edit')).appendTo(td2).click(function() {
|
2018-11-21 18:30:00 +01:00
|
|
|
var newValue = window.prompt($.i18n('core-index/change-metadata-value')+" " + key, value);
|
2017-11-05 16:41:17 +01:00
|
|
|
if (newValue !== null) {
|
2018-11-17 21:42:34 +01:00
|
|
|
$(td1).text(newValue);
|
2017-11-05 16:41:17 +01:00
|
|
|
metaData[key] = newValue;
|
2019-10-14 15:04:38 +02:00
|
|
|
Refine.postCSRF(
|
|
|
|
"command/core/set-project-metadata",
|
2017-11-05 16:41:17 +01:00
|
|
|
{
|
|
|
|
project : project,
|
|
|
|
name : key,
|
|
|
|
value : newValue
|
|
|
|
},
|
|
|
|
function(o) {
|
|
|
|
if (o.code === "error") {
|
|
|
|
alert(o.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-08 00:46:59 +01:00
|
|
|
Refine.OpenProjectUI.refreshProject(targetRowElem, metaData, project);
|
2017-11-05 16:41:17 +01:00
|
|
|
});
|
|
|
|
}
|
2017-11-04 00:46:07 +01:00
|
|
|
};
|
2017-10-26 21:47:24 +02:00
|
|
|
|
|
|
|
this._createDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
EditMetadataDialog.prototype._createDialog = function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var frame = $(DOM.loadHTML("core", "scripts/project/edit-metadata-dialog.html"));
|
|
|
|
this._elmts = DOM.bind(frame);
|
|
|
|
|
|
|
|
this._level = DialogSystem.showDialog(frame);
|
2018-11-21 18:30:00 +01:00
|
|
|
this._elmts.closeButton.html($.i18n('core-buttons/close'));
|
2017-12-07 00:59:36 +01:00
|
|
|
this._elmts.closeButton.click(function() { self._dismiss();Refine.OpenProjectUI.prototype._addTagFilter()});
|
2017-10-26 21:47:24 +02:00
|
|
|
|
|
|
|
var body = $("#metadata-body");
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<h1>').text($.i18n('core-index/metaDatas')).appendTo(body);
|
2017-10-26 21:47:24 +02:00
|
|
|
|
|
|
|
var metadataTable = $("<table>")
|
|
|
|
.addClass("list-table")
|
|
|
|
.addClass("preferences")
|
2018-11-17 21:42:34 +01:00
|
|
|
.html('<tr><th>'+$.i18n('core-index/key')+'</th><th>'+$.i18n('core-index/value')+'</th><th></th></tr>')
|
2017-10-26 21:47:24 +02:00
|
|
|
.appendTo(body)[0];
|
|
|
|
|
2017-10-29 18:46:37 +01:00
|
|
|
var flattenObject = function(ob, key) {
|
|
|
|
var toReturn = {};
|
|
|
|
for ( var i in ob) {
|
|
|
|
if (i !== key) {
|
|
|
|
toReturn[i] = ob[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for ( var x in ob[i]) {
|
|
|
|
toReturn[ob[i][x].name] = ob[i][x].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
};
|
|
|
|
|
2017-11-09 02:30:01 +01:00
|
|
|
var flatMetadata = flattenObject(this._metaData, "userMetadata");
|
2017-10-29 18:46:37 +01:00
|
|
|
|
2017-11-09 02:30:01 +01:00
|
|
|
for (var k in flatMetadata) {
|
2017-10-26 21:47:24 +02:00
|
|
|
var tr = metadataTable.insertRow(metadataTable.rows.length);
|
2017-11-04 01:12:57 +01:00
|
|
|
var v;
|
2017-10-26 21:47:24 +02:00
|
|
|
|
2017-11-09 02:30:01 +01:00
|
|
|
if (typeof flatMetadata[k] === 'string') {
|
|
|
|
v = flatMetadata[k].replace(/\"/g, "");
|
2017-11-04 00:46:07 +01:00
|
|
|
} else {
|
2017-11-09 02:30:01 +01:00
|
|
|
v = JSON.stringify(flatMetadata[k]);
|
2017-11-04 00:46:07 +01:00
|
|
|
}
|
2017-10-26 21:47:24 +02:00
|
|
|
|
2017-11-09 02:30:01 +01:00
|
|
|
this._metaDataUIs.push(new this._MetadataUI(tr, k, v, flatMetadata.id));
|
2017-10-26 21:47:24 +02:00
|
|
|
}
|
2017-11-09 22:23:29 +01:00
|
|
|
|
|
|
|
$(".dialog-container").css("top", Math.round(($(".dialog-overlay").height() - $(frame).height()) / 2) + "px");
|
2017-11-04 01:12:57 +01:00
|
|
|
};
|
2017-10-26 21:47:24 +02:00
|
|
|
|
|
|
|
EditMetadataDialog.prototype._dismiss = function() {
|
|
|
|
DialogSystem.dismissUntil(this._level - 1);
|
|
|
|
};
|
|
|
|
|
2017-12-07 00:59:36 +01:00
|
|
|
function escapeRegExp(str) {
|
|
|
|
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
|
|
|
|
}
|
|
|
|
|
|
|
|
function replaceAll(str, find, replace) {
|
|
|
|
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
|
|
|
|
}
|
|
|
|
|