blob: 98e87f4a6b919a92e0b1ac64ac24687538f0e8d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
"use strict";
/* Used for the newcustomimage_modal actions */
function newCustomImageModalInit(){
var newCustomImgBtn = $("#create-new-custom-image-btn");
var imgCustomModal = $("#new-custom-image-modal");
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 (-).";
var duplicateImageMsg = "An image with this name already exists in this project.";
var duplicateRecipeMsg = "A non-image recipe with this name already exists.";
newCustomImgBtn.click(function(e){
e.preventDefault();
var baseRecipeId = imgCustomModal.data('recipe');
if (nameInput.val().length > 0) {
libtoaster.createCustomRecipe(nameInput.val(), baseRecipeId,
function(ret) {
if (ret.error !== "ok") {
console.warn(ret.error);
if (ret.error === "invalid-name") {
showError(invalidMsg);
} else if (ret.error === "image-already-exists") {
showError(duplicateImageMsg);
} else if (ret.error === "recipe-already-exists") {
showError(duplicateRecipeMsg);
}
} else {
imgCustomModal.modal('hide');
window.location.replace(ret.url + '?notify=new');
}
});
}
});
function showError(text){
invalidNameHelp.text(text);
invalidNameHelp.show();
nameInput.parent().addClass('error');
}
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);
nameInput.parent().addClass('error');
} else {
invalidNameHelp.hide();
newCustomImgBtn.prop("disabled", false);
nameInput.parent().removeClass('error');
}
});
}
|