Commit ccba1703 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

598: Implement CustomSearch as successor of user collections

Task-Url: https://pm.winseda.de/issues/598
parent a747db18
......@@ -292,6 +292,7 @@ table.state-table tbody tr.state-row-ok td {
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
/* This is the dangerous one in WebKit, as it breaks things wherever */
......
......@@ -17,8 +17,7 @@ var CustomSearchEditor = function() {
this.loadCustomSearches(function() {
_this.setActiveSearch($("#user-collection-selectedUcId").val());
_this.refreshDetails();
_this.collectionEditor = new CollectionEditor();
_this.shareEditor = new ShareEditor();
});
__translator.addTranslations(["~eu.dariah.de.minfba.search.view.custom_search.view.info.owned_by_user",
......@@ -66,7 +65,7 @@ CustomSearchEditor.prototype.showCustomSearches = function(data) {
var uc = data[i].entity;
var element = '<li class="source-select-ucId" id="source-select-ucId-' + uc.id + '">' +
'<a href="#" onclick="editor.setActiveSearch(\'' + uc.id + '\'); editor.refresh(); return false;">' +
'<a href="javascript:void(0)" onclick="editor.setActiveSearch(\'' + uc.id + '\'); editor.refresh(); return false;">' +
'<span class="glyphicon glyphicon-chevron-right pull-right"></span>' +
'<span class="source-select-ucId-title">';
if (uc.ownedByUser) {
......@@ -81,11 +80,11 @@ CustomSearchEditor.prototype.showCustomSearches = function(data) {
element += '<span class="glyphicon glyphicon-lock" title="' + __translator.translate("~eu.dariah.de.minfba.search.view.custom_search.view.info.not_editable_by_user") + '"><input type="hidden" class="user-collection-editable" value="false" /></span> ';
}
if (uc.shared) {
/*if (uc.shared) {
element += '<span class="glyphicon glyphicon-eye-open" title="' + __translator.translate("~eu.dariah.de.minfba.search.view.custom_search.view.info.shared") + '"><input type="hidden" class="user-collection-shared" value="true" /></span> ';
} else {
element += '<span class="glyphicon glyphicon-eye-close" title="' + __translator.translate("~eu.dariah.de.minfba.search.view.custom_search.view.info.not_shared") + '"><input type="hidden" class="user-collection-shared" value="false" /></span> ';
}
}*/
if (uc.brandedSearchActive) {
element += '<span class="glyphicon glyphicon-globe"></span> ';
......@@ -102,7 +101,7 @@ CustomSearchEditor.prototype.showCustomSearches = function(data) {
CustomSearchEditor.prototype.setActiveSearch = function(ucId) {
if (ucId===undefined || ucId==null || ucId=="") {
ucId = "0";
return;
}
$("#user-collection-selectedUcId").val(ucId);
......@@ -117,43 +116,65 @@ CustomSearchEditor.prototype.setActiveSearch = function(ucId) {
});
// Most options and actions not available on the list of all collections
if (ucId==="0") {
$("#user-collection-shares-tab").addClass("hide");
$("#user-collection-details-tab").addClass("hide");
// Most options and actions not available on the list of all collections
var edit = $("#user-collection-subheader").find(".user-collection-editable").val()=="true" ? true : false;
$("#custom-search-details-container").removeClass("hide");
if (edit) {
$("#btn-add-collection").removeClass("disabled");
$("#btn-add-share").removeClass("disabled");
$("#btn-custom-search-edit").removeProp("disabled");
$("#btn-custom-search-delete").removeProp("disabled");
} else {
$("#btn-add-collection").addClass("disabled");
$("#btn-add-share").addClass("disabled");
$("#btn-custom-search-edit").prop("disabled", "disabled");
$("#btn-custom-search-delete").prop("disabled", "disabled");
}
var owner = $("#user-collection-subheader").find(".user-collection-owned").val()=="true" ? true : false;
if (owner) {
$("#btn-user-collection-delete").removeClass("hide");
$("#btn-user-collection-edit").removeClass("hide");
} else {
$("#btn-user-collection-delete").addClass("hide");
$("#btn-user-collection-edit").addClass("hide");
$("#user-collection-shares").addClass("hide");
$('#user-collection-tab a[href="#user-collection-collections"]').tab("show");
} else {
var edit = $("#user-collection-subheader").find(".user-collection-editable").val()=="true" ? true : false;
if (edit) {
$("#btn-add-collection").removeClass("disabled");
$("#btn-add-share").removeClass("disabled");
} else {
$("#btn-add-collection").addClass("disabled");
$("#btn-add-share").addClass("disabled");
}
var owner = $("#user-collection-subheader").find(".user-collection-owned").val()=="true" ? true : false;
if (owner) {
$("#btn-user-collection-delete").removeClass("hide");
$("#btn-user-collection-edit").removeClass("hide");
} else {
$("#btn-user-collection-delete").addClass("hide");
$("#btn-user-collection-edit").addClass("hide");
}
$("#user-collection-shares-tab").removeClass("hide");
$("#user-collection-shares").removeClass("hide");
$("#user-collection-details-tab").removeClass("hide");
$('#user-collection-tab a[href="#user-collection-details"]').tab("show");
}
$("#user-collection-shares-tab").removeClass("hide");
$("#user-collection-shares").removeClass("hide");
$("#user-collection-details-tab").removeClass("hide");
$('#user-collection-tab a[href="#user-collection-details"]').tab("show");
};
CustomSearchEditor.prototype.refresh = function() {
this.refreshDetails();
this.collectionEditor.refresh();
this.shareEditor.refresh();
this.refreshCollections();
};
CustomSearchEditor.prototype.refreshCollections = function() {
var _this = this;
var customSearchId = $("#user-collection-selectedUcId").val();
$.ajax({
url: __util.composeRelativeUrl(customSearchId + "/async/collections"),
type: "GET",
dataType: "json",
success: function(data) {
$("#user-collection-collections-table").html("");
for (var i=0; i<data.length; i++) {
$("#user-collection-collections-table").append("<tr>" +
"<td><a href='javascript:void(0)' onclick='editor.triggerRemoveCollection(\"" + data[i].id + "\");'><i class='fa fa-trash' aria-hidden='true'></i></a></td>" +
"<td width='100%'>" + data[i].name + "</td>" +
"</tr>");
}
}
});
};
CustomSearchEditor.prototype.refreshDetails = function() {
......@@ -164,6 +185,7 @@ CustomSearchEditor.prototype.refreshDetails = function() {
$.ajax({
url: __util.composeRelativeUrl(customSearchId + "/async/get"),
type: "GET",
dataType: "json",
success: function(data) {
$("#user-collection-detail-name").text(data.name);
$("#user-collection-detail-description").text(data.description);
......@@ -202,13 +224,12 @@ CustomSearchEditor.prototype.triggerDeleteCustomSearch = function(collectionId)
bootbox.confirm(__translator.translate("~eu.dariah.de.minfba.search.view.custom_search.view.dialog.confirm_delete_custom_search"), function(result) {
if(result) {
$.ajax({
url: window.location.pathname + "/async/deleteUserCollection?ucId=" + ucId,
url: __util.composeUrl("searches/" + ucId + "/async/delete"),
type: "GET",
dataType: "json",
success: function(data) {
_this.loadCustomSearches(function() {
_this.setActiveSearch(0);
_this.collectionEditor.refresh();
});
},
error: function(textStatus) {
......@@ -239,7 +260,7 @@ CustomSearchEditor.prototype.getEditUserCollectionForm = function(ucId) {
var _this = this;
modalFormHandler = new ModalFormHandler({
formUrl: __util.composeUrl(ucId + "/forms/edit"),
formFullUrl: __util.composeUrl("searches/" + ucId + "/forms/edit"),
identifier: "newGroup",
additionalModalClasses: "wider-modal",
completeCallback: function(data) {
......@@ -333,11 +354,11 @@ CustomSearchEditor.prototype.triggerRemoveCollection = function(collectionId) {
bootbox.confirm(__translator.translate("~eu.dariah.de.minfba.search.view.custom_search.view.dialog.confirm_remove_collection_assignment"), function(result) {
if(result) {
$.ajax({
url: window.location.pathname + "/async/removeCollectionAssignment?ucId=" + ucId + "&cId=" + collectionId,
url: __util.composeUrl("/searches/" + ucId + "/async/removeCollection?cId=" + collectionId),
type: "GET",
dataType: "json",
success: function(data) {
_this.collectionEditor.refresh();
_this.refreshCollections();
},
error: function(textStatus) {
__notifications.showTranslatedMessage(NOTIFICATION_TYPES.ERROR,
......@@ -358,7 +379,7 @@ CustomSearchEditor.prototype.triggerRemoveShare = function(currentUcId, userId)
type: "GET",
dataType: "json",
success: function(data) {
_this.shareEditor.refresh();
},
error: function(textStatus) {
__notifications.showTranslatedMessage(NOTIFICATION_TYPES.ERROR,
......@@ -377,7 +398,7 @@ CustomSearchEditor.prototype.getCurrentUcId = function() {
if (ucId===null || ucId===undefined || ucId=="") {
return 0;
} else {
return parseInt(ucId);
return ucId;
}
};
......@@ -397,7 +418,7 @@ CustomSearchEditor.prototype.triggerAssignCollection = function() {
});
},
function() {
_this.collectionEditor.refresh();
_this.refreshCollections();
});
......@@ -433,13 +454,7 @@ CustomSearchEditor.prototype.triggerAddUser = function() {
items: 4,
source: userSuggestionEngine.ttAdapter()
});
},
function() { _this.shareEditor.refresh(); });
};
CustomSearchEditor.prototype.triggerEditShare = function(ucId, userId) {
var _this = this;
this.createModalForm(-1, "addShare", "/async/getEditShareForm?ucId=" + ucId + "&userId=" + userId, "", null, function() { _this.shareEditor.refresh(); });
});
};
CustomSearchEditor.prototype.createModalForm = function(id, form_identifier, url, modalType, setupCallback, completeCallback) {
......@@ -451,93 +466,4 @@ CustomSearchEditor.prototype.createModalForm = function(id, form_identifier, url
setupCallback: setupCallback
});
modalFormHandler.show(form_identifier);
};
/**
* Collection Editor
*/
var CollectionEditor = function() {
this.createTable();
};
CollectionEditor.prototype = new BaseTable(__util.getBaseUrl() + "/async/collections", "#user-collection-collections");
CollectionEditor.prototype.createTable = function() {
var _this = this;
this._base.table = $('#user-collection-collections-table').DataTable($.extend(true, {
"order": [[1, "asc"]],
"columnDefs": [
{
"targets": [0], "class": "td-no-wrap",
"sortable" : false,
"data": function (row, type, val, meta) { return _this.renderActionColumn(row, type, val, meta); },
}, {
"targets": [1],
"data": "name",
"width" : "100%"
}
]
}));
};
CollectionEditor.prototype.renderActionColumn = function(row, type, val, meta) {
var show = $("#user-collection-subheader").find(".user-collection-editable").val()=="true" ? true : false;
if(show==true) {
return "<button onclick='editor.triggerRemoveCollection(" + row.entity.id + ");' class='btn btn-default btn-xs' type='button'><span class='glyphicon glyphicon-trash'></span></button>";
} else {
return "";
}
};
/**
* Share Editor
*/
/*
var ShareEditor = function() {
this.createTable();
};
ShareEditor.prototype = new BaseTable(__util.getBaseUrl() + $("#user-collection-selectedUcId").val() + "/async/users", "#user-collection-shares-table");
ShareEditor.prototype.createTable = function() {
var _this = this;
this._base.table = $('#user-collection-shares-table').dataTable({
"order": [[1, "asc"]],
"columnDefs": [
{
"targets": [0],
"sortable" : false,
"data": function (row, type, val, meta) { return _this.renderBadgeColumn(row, type, val, meta);}
}, {
"targets": [1], "class": "td-no-wrap",
"data": function (row, type, val, meta) { return _this.renderActionColumn(row, type, val, meta);},
"width" : "100%"
}, {
"targets": [2],
"data": "username",
"width" : "100%"
}
]
});
};
ShareEditor.prototype.renderBadgeColumn = function(row, type, val, meta) {
if (row.entity.id=="OWNER") {
return '<span class="label label-info">' + row.entity.id + '</span> ';
} else if (row.entity.id=="VIEWER") {
return '<span class="label label-success">' + row.entity.id + '</span> ';
} else {
return '<span class="label label-warning">' + row.entity.id + '</span> ';
}
};
ShareEditor.prototype.renderActionColumn = function(row, type, val, meta) {
var show = $("#user-collection-subheader").find(".user-collection-editable").val()=="true" ? true : false;
if(row.mappingType!="OWNER" && show==true) {
return "<button onclick='editor.triggerEditShare(" + row.userCollectionId + ", " + row.userId + ");' class='btn btn-default btn-xs' type='button'><span class='glyphicon glyphicon-edit'></span></button>" +
"<button onclick='editor.triggerRemoveShare(" + row.userCollectionId + ", " + row.userId + ");' class='btn btn-default btn-xs' type='button'><span class='glyphicon glyphicon-trash'></span></button>";
}
return "";
};*/
\ No newline at end of file
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment