2015-09-29 04:45:24 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-11-04 15:44:00 +00:00
|
|
|
/* Used for the newcustomimage_modal actions */
|
2015-12-07 18:44:37 +00:00
|
|
|
function newCustomImageModalInit(){
|
2015-09-29 04:45:24 +00:00
|
|
|
|
|
|
|
var newCustomImgBtn = $("#create-new-custom-image-btn");
|
|
|
|
var imgCustomModal = $("#new-custom-image-modal");
|
2016-02-02 17:46:31 +00:00
|
|
|
var invalidNameHelp = $("#invalid-name-help");
|
|
|
|
var nameInput = imgCustomModal.find('input');
|
|
|
|
|
|
|
|
var invalidMsg = "Image names cannot contain spaces or capital letters. The only allowed special character is dash (-).";
|
2015-09-29 04:45:24 +00:00
|
|
|
|
|
|
|
newCustomImgBtn.click(function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var baseRecipeId = imgCustomModal.data('recipe');
|
|
|
|
|
2016-02-02 17:46:31 +00:00
|
|
|
if (nameInput.val().length > 0) {
|
|
|
|
libtoaster.createCustomRecipe(nameInput.val(), baseRecipeId,
|
|
|
|
function(ret) {
|
2015-12-07 18:44:37 +00:00
|
|
|
if (ret.error !== "ok") {
|
|
|
|
console.warn(ret.error);
|
2016-02-02 17:46:31 +00:00
|
|
|
if (ret.error === "invalid-name") {
|
|
|
|
showError(invalidMsg);
|
|
|
|
} else if (ret.error === "already-exists") {
|
|
|
|
showError("An image with this name already exists. Image names must be unique.");
|
|
|
|
}
|
2015-12-07 18:44:37 +00:00
|
|
|
} else {
|
2016-02-02 17:46:31 +00:00
|
|
|
imgCustomModal.modal('hide');
|
2015-12-07 18:44:37 +00:00
|
|
|
window.location.replace(ret.url + '?notify=new');
|
|
|
|
}
|
|
|
|
});
|
2016-02-02 17:46:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function showError(text){
|
|
|
|
invalidNameHelp.text(text);
|
|
|
|
invalidNameHelp.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
nameInput.on('keyup', function(){
|
|
|
|
if (nameInput.val().length === 0){
|
|
|
|
newCustomImgBtn.prop("disabled", true);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nameInput.val().search(/[^a-z|0-9|-]/) != -1){
|
|
|
|
showError(invalidMsg);
|
|
|
|
newCustomImgBtn.prop("disabled", true);
|
2015-09-29 04:45:24 +00:00
|
|
|
} else {
|
2016-02-02 17:46:31 +00:00
|
|
|
invalidNameHelp.hide();
|
|
|
|
newCustomImgBtn.prop("disabled", false);
|
2015-09-29 04:45:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|