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

985: Complete branding of custom searches

Task-Url: https://pm.winseda.de/issues/985
parent 338e0aa5
......@@ -9,7 +9,6 @@ $(document).ready(function() {
$("#btn-add-user").click(function() { editor.triggerAddUser(); });
$("#btn-add-collection").click(function() { editor.triggerAssignCollection(); });
});
var CustomSearchEditor = function() {
......@@ -30,7 +29,11 @@ var CustomSearchEditor = function() {
"~eu.dariah.de.minfba.common.error.servererror.body",
"~eu.dariah.de.minfba.search.view.custom_search.view.dialog.confirm_delete_custom_search",
"~eu.dariah.de.minfba.search.view.custom_search.view.dialog.confirm_remove_collection_assignment",
"~eu.dariah.de.minfba.search.view.custom_search.view.dialog.confirm_remove_user"]);
"~eu.dariah.de.minfba.search.view.custom_search.view.dialog.confirm_remove_user",
"~eu.dariah.de.minfba.search.view.custom_search.view.info.image_too_large",
"~eu.dariah.de.minfba.search.view.custom_search.view.info.image_not_an_image",
"~eu.dariah.de.minfba.search.view.custom_search.view.info.no_image",
"~eu.dariah.de.minfba.metamodel.common.id"]);
__translator.getTranslations();
};
......@@ -243,18 +246,19 @@ CustomSearchEditor.prototype.refreshDetails = function() {
}
if (data.searchImageSrc!=null) {
$("#user-collection-detail-search_logo").prop("src", data.searchImageSrc);
$("#user-collection-detail-search_logo").prop("src", data.searchImageSrc + "/THUMBNAIL");
$("#user-collection-detail-search_logo").removeClass("hide");
} else {
$("#user-collection-detail-search_logo").prop("src", "#");
$("#user-collection-detail-search_logo").addClass("hide");
}
if (data.organizationImageSrc!=null) {
$("#user-collection-detail-organization_logo").prop("src", data.organizationImageSrc);
$("#user-collection-detail-organization_logo").removeClass("hide");
} else {
$("#user-collection-detail-organization_logo").prop("src", "#");
$("#user-collection-detail-organization_logo").addClass("hide");
$("#user-collection-detail-organization_logo_container").text("");
if (data.organizationImageIdSrcMap!=null) {
for (var id in data.organizationImageIdSrcMap) {
if (data.organizationImageIdSrcMap.hasOwnProperty(id)) {
$("#user-collection-detail-organization_logo_container").append("<img style='margin-right: 10px; margin-bottom: 10px;' src='" + data.organizationImageIdSrcMap[id] + "/THUMBNAIL' />");
}
}
}
}
});
......@@ -332,32 +336,10 @@ CustomSearchEditor.prototype.getEditUserCollectionForm = function(ucId) {
$(this).colorpicker('setValue', $(this).val());
}
});
//$(".custom-image-file").bind("change", _this.triggerUploadImage);
}
});
modalFormHandler.fileUploadElements.push({
selector: "#search_image", // selector for identifying where to put widget
preexisting: "#searchImageName",
elementChangeCallback: function(data) {
_this.setImageValue("#searchImageName", "#searchImage", data);
},
formSource: "/form/sourceSelection", // where is the form
uploadTarget: "/async/handleFile", // where to we upload the file(s) to
multiFiles: false, // one or multiple files
});
modalFormHandler.fileUploadElements.push({
selector: "#orga_image", // selector for identifying where to put widget
preexisting: "#organizationImageName",
elementChangeCallback: function(data) {
_this.setImageValue("#organizationImageName", "#organizationImage", data);
},
formSource: "/form/sourceSelection", // where is the form
uploadTarget: "/async/handleFile", // where to we upload the file(s) to
multiFiles: false, // one or multiple files
});
modalFormHandler.show("newGroup");
};
......@@ -512,4 +494,99 @@ CustomSearchEditor.prototype.createModalForm = function(id, form_identifier, url
setupCallback: setupCallback
});
modalFormHandler.show(form_identifier);
};
CustomSearchEditor.prototype.triggerUploadImage = function(e, btn) {
var _this = editor;
var container = $(btn).closest(".custom-image-container");
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
var files = e.target.files; // FileList object
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
$(container).find(".custom-image-hint").html(__translator.translate("~eu.dariah.de.minfba.search.view.custom_search.view.info.image_too_large"));
continue;
}
if (f.size>_this.imageMaxFileSize) {
$(container).find(".custom-image-hint").html(__translator.translate("~eu.dariah.de.minfba.search.view.custom_search.view.info.image_not_an_image") + " 5 MB");
continue;
}
var formData = new FormData();
formData.append("file", f, f.name);
$.ajax({
url: __util.composeUrl("image/async/upload"),
data: formData,
type: "POST",
beforeSend: function( xhr ) {
xhr.setRequestHeader("X-File-Name", f.name);
xhr.setRequestHeader("X-File-Size", f.size);
xhr.setRequestHeader("X-File-Type", f.type);
},
cache: false,
contentType: false,
processData: false,
timeout: 20000,
success: function(data) {
if (data.success) {
$(container).find(".custom-image-preview").prop("href", data.pojo.imageUri);
$(container).find(".custom-image-preview img").prop("src", data.pojo.thumbUri);
$(container).find(".custom-image-hint").html("<a href='" + data.pojo.baseUri + "' target='_blank'>" + __translator.translate("~eu.dariah.de.minfba.metamodel.common.id") + ": " + data.pojo.name + "</a>");
$(container).find(".custom-image-preview").show();
$(container).find(".custom-image-placeholder").hide();
$(container).find(".custom-image-id").val(data.pojo.id);
$(container).find(".btn-remove-custom-image").show();
} else {
_this.triggerRemoveCollectionImage();
$(container).find(".custom-image-hint").html(data.objectErrors[0]);
}
}
});
}
}
};
CustomSearchEditor.prototype.triggerAddOrganizationImage = function(btn) {
$.ajax({
url: __util.composeUrl("searches/incl/organizationImageContainer"),
type: "GET",
dataType: "text",
success: function(template) {
var container = $("<div class='col-sm-9 col-sm-offset-3'>");
container.append(template);
$("#organization-image-container").append(container);
},
error : function() {}
});
};
CustomSearchEditor.prototype.triggerRemoveImage = function(btn) {
var container = $(btn).closest(".custom-image-container");
$.ajax({
url: __util.composeUrl("image/" + $(container).find(".custom-image-id").val() + "/delete"),
type: "GET"
});
$(container).find(".custom-image-preview").prop("href", "");
$(container).find(".custom-image-preview img").prop("src", "");
$(container).find(".custom-image-hint").html(__translator.translate("~eu.dariah.de.minfba.search.view.custom_search.view.info.no_image"));
$(container).find(".custom-image-preview").hide();
$(container).find(".custom-image-placeholder").show();
$(container).find(".custom-image-file").val(null);
$(container).find(".custom-image-id").val(null);
$(container).find(".btn-remove-custom-image").hide();
};
\ 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