Move the modal template and JS out of the newcustomimage page so that it can also be used by the image details page.
Signed-off-by: Michael Wood <[email protected]> --- .../toaster/toastergui/static/js/newcustomimage.js | 49 ---------------------- .../toastergui/static/js/newcustomimage_modal.js | 48 +++++++++++++++++++++ .../toastergui/templates/newcustomimage.html | 44 +------------------ .../toastergui/templates/newcustomimage_modal.html | 33 +++++++++++++++ 4 files changed, 83 insertions(+), 91 deletions(-) delete mode 100644 bitbake/lib/toaster/toastergui/static/js/newcustomimage.js create mode 100644 bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js create mode 100644 bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html diff --git a/bitbake/lib/toaster/toastergui/static/js/newcustomimage.js b/bitbake/lib/toaster/toastergui/static/js/newcustomimage.js deleted file mode 100644 index 935b21e..0000000 --- a/bitbake/lib/toaster/toastergui/static/js/newcustomimage.js +++ /dev/null @@ -1,49 +0,0 @@ -"use strict"; - -function newCustomImagePageInit(ctx){ - - var newCustomImgBtn = $("#create-new-custom-image-btn"); - var imgCustomModal = $("#new-custom-image-modal"); - - newCustomImgBtn.click(function(e){ - e.preventDefault(); - - var name = imgCustomModal.find('input').val(); - var baseRecipeId = imgCustomModal.data('recipe'); - - if (name.length > 0) { - createCustomRecipe(name, baseRecipeId); - imgCustomModal.modal('hide'); - } else { - console.warn("TODO No name supplied"); - } - }); - - function createCustomRecipe(name, baseRecipeId){ - var data = { - 'name' : name, - 'project' : libtoaster.ctx.projectId, - 'base' : baseRecipeId, - }; - - $.ajax({ - type: "POST", - url: ctx.xhrCustomRecipeUrl, - data: data, - headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, - success: function (ret) { - if (ret.error !== "ok") { - console.warn(ret.error); - } else { - window.location.replace(ret.url + '?notify=new'); - } - }, - error: function (ret) { - console.warn("Call failed"); - console.warn(ret); - } - }); - } - - -} diff --git a/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js b/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js new file mode 100644 index 0000000..71a28f7 --- /dev/null +++ b/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js @@ -0,0 +1,48 @@ +"use strict"; + +/* Used for the newcustomimage_modal actions */ +function newCustomImageModalInit(ctx){ + + var newCustomImgBtn = $("#create-new-custom-image-btn"); + var imgCustomModal = $("#new-custom-image-modal"); + + newCustomImgBtn.click(function(e){ + e.preventDefault(); + + var name = imgCustomModal.find('input').val(); + var baseRecipeId = imgCustomModal.data('recipe'); + + if (name.length > 0) { + createCustomRecipe(name, baseRecipeId); + imgCustomModal.modal('hide'); + } else { + console.warn("TODO No name supplied"); + } + }); + + function createCustomRecipe(name, baseRecipeId){ + var data = { + 'name' : name, + 'project' : libtoaster.ctx.projectId, + 'base' : baseRecipeId, + }; + + $.ajax({ + type: "POST", + url: ctx.xhrCustomRecipeUrl, + data: data, + headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, + success: function (ret) { + if (ret.error !== "ok") { + console.warn(ret.error); + } else { + window.location.replace(ret.url + '?notify=new'); + } + }, + error: function (ret) { + console.warn("Call failed"); + console.warn(ret); + } + }); + } +} diff --git a/bitbake/lib/toaster/toastergui/templates/newcustomimage.html b/bitbake/lib/toaster/toastergui/templates/newcustomimage.html index 4487b3e..46aed90 100644 --- a/bitbake/lib/toaster/toastergui/templates/newcustomimage.html +++ b/bitbake/lib/toaster/toastergui/templates/newcustomimage.html @@ -4,51 +4,11 @@ {% load static %} {% block pagecontent %} -<script src="{% static 'js/newcustomimage.js' %}"></script> -<script> - $(document).ready(function (){ - var ctx = { - xhrCustomRecipeUrl : "{% url 'xhr_customrecipe' %}", - }; - - try { - newCustomImagePageInit(ctx); - } catch (e) { - document.write("Sorry, An error has occurred loading this page"); - console.warn(e); - } - }); -</script> - -</script> -<div class="modal hide fade in" id="new-custom-image-modal" aria-hidden="false"> - <div class="modal-header"> - <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> - <h3>Name your custom image</h3> - </div> - <div class="modal-body"> - <div class="row-fluid"> - <span class="help-block span8">Image names must be unique. They should not contain spaces or capital letters, and the only allowed special character is dash (-).<p></p> - </span></div> - <div class="control-group controls"> - <input type="text" class="huge span5" placeholder="Type the name, something like 'core-image-myimage'"> - <span class="help-block" style="display:none">Image names cannot contain spaces or capital letters. The only allowed special character is dash (-)</span> - <span class="help-block" style="display: none">An image with this name already exists. Image names must be unique: try a different one.</span> - </div> - </div> - <div class="modal-footer"> - <a href="#" id="create-new-custom-image-btn" class="btn btn-primary btn-large" data-original-title="" title="">Create custom image</a> - </div> -</div> - +{% include "newcustomimage_modal.html" %} {% include "projecttopbar.html" %} - {% url table_name project.id as xhr_table_url %} +<h2>{{title}} (<span class="table-count-{{table_name}}">0</span>)</h2> {% include "toastertable.html" %} - - {% endblock %} - - diff --git a/bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html b/bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html new file mode 100644 index 0000000..93cf9d7 --- /dev/null +++ b/bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html @@ -0,0 +1,33 @@ +{% load static %} + +<script src="{% static 'js/newcustomimage_modal.js' %}"></script> +<script> + $(document).ready(function (){ + try { + newCustomImageModalInit(); + } catch (e) { + document.write("Sorry, An error has occurred loading this page"); + console.warn(e); + } + }); +</script> + +<div class="modal hide fade in" id="new-custom-image-modal" aria-hidden="false"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> + <h3>Name your custom image</h3> + </div> + <div class="modal-body"> + <div class="row-fluid"> + <span class="help-block span8">Image names must be unique. They should not contain spaces or capital letters, and the only allowed special character is dash (-).<p></p> + </span></div> + <div class="control-group controls"> + <input type="text" class="huge span5" placeholder="Type the name, something like 'core-image-myimage'"> + <span class="help-block" style="display:none">Image names cannot contain spaces or capital letters. The only allowed special character is dash (-)</span> + <span class="help-block" style="display: none">An image with this name already exists. Image names must be unique: try a different one.</span> + </div> + </div> + <div class="modal-footer"> + <a href="#" id="create-new-custom-image-btn" class="btn btn-primary btn-large" data-original-title="" title="">Create custom image</a> + </div> +</div> -- 2.1.4 -- _______________________________________________ toaster mailing list [email protected] https://lists.yoctoproject.org/listinfo/toaster
