| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- var chooseRecipePopup = null;
- function searchForRecipe(webContext,rowIndex) {
- var url = webContext +'/chooseRecipeForMeal.do?mode='+rowIndex;
-
- var width = 500;
- var height = 300;
- var top = (screen.height - height ) / 2;
- var left = (screen.width - width ) / 2;
-
- var windowOpts = "titlebar,toolbar=no,resizable,scrollbars,left=" +left
- +",top=" +top +",width=" +width +",height=" +height;
- if ( chooseRecipePopup != null && !chooseRecipePopup.closed ) {
- chooseRecipePopup.close();
- }
- chooseRecipePopup = window.open(url, "choose_recipe", windowOpts);
- chooseRecipePopup.focus();
- }
- function addRecipe() {
- // get the recipe table
- var row = document.getElementById('recipe_row');
-
- // get the add row to insert the cloned row into
- var addRow = document.getElementById('recipe_add_row');
-
- // clone the recipe row
- var newRow = row.cloneNode(true);
-
- // remove 'id' attribute
- newRow.removeAttribute('id');
-
- // clear out quantity
- var quantity = findNodeWithAttributeValue(newRow,'name','\\.quantity$');
- if ( !quantity ) {
- alert("Did not find quantity!");
- } else {
- quantity.value = "1";
- }
-
- // set new course to selected index 0
- var course = findNodeWithAttributeValue(newRow,'name','\\.courseId$');
- if ( !course ) {
- alert("Did not find course!");
- } else {
- course.selectedIndex = 0;
- }
-
- // remove any selected recipe name
- var recipe = findNodeWithAttributeValue(newRow,'name','\\.recipeId$');
- if ( !recipe ) {
- alert("Did not find recipe!");
- } else {
- recipe.value = 0;
- }
- var recipeSpan = findNodeWithAttributeValue(newRow,'id','\\.name$');
- if ( !recipeSpan ) {
- alert("Did not find recipe name span!");
- } else {
- removeChildren(recipeSpan);
- recipeSpan.appendChild(document.createTextNode('('+msg_setRecipe+')'));
- }
-
-
-
- // find all 'name' attributes, and increment index values
- updateRecipeRowIndexValues(newRow,numRecipes);
-
- // insert into table
- addRow.parentNode.insertBefore(newRow,addRow);
-
- numRecipes++;
- }
- function updateRecipeRowIndexValues(row,index) {
- replaceAttribute(row,'name','recipe\\[\\d+\\]',
- 'recipe[' +index +']');
- replaceAttribute(row,'id','recipe\\[\\d+\\]',
- 'recipe[' +index +']');
- replaceAttribute(row,'href','\\d+',
- index);
- }
- function chooseRecipeForMeal(doc,rowNum,recipeId,recipeName) {
- var recipeNameSpan = doc.getElementById('meal.recipe['+rowNum+'].recipe.name');
- if ( !recipeNameSpan ) {
- alert("Could not get recipe name span!");
- return;
- }
-
- var recipeIdHidden = doc.forms[0].elements['meal.recipe['+rowNum+'].recipe.recipeId'];
- if ( !recipeIdHidden ) {
- alert("Could not get recipe id hidden element!");
- return;
- }
- // delete any current children, then insert name
- removeChildren(recipeNameSpan);
-
- // insert recipe name into span if name available
- if ( recipeName ) {
- recipeNameSpan.appendChild(doc.createTextNode(recipeName));
- }
-
- // set hidden select value to recipeId
- recipeIdHidden.value = recipeId;
- }
- function removeRecipe(recipeIndex) {
- // loop through all rows in recipe table, removing the
- // row in question and then re-naming any subsequent rows
- // so index values decrease
-
- if ( recipeIndex < 1 ) {
- alert(getMessage('msg_noDeleteFirstRecipe'));
- return;
- }
-
- // forward to proper row
- var rowIdx = 0;
- var recipeRow = document.getElementById('recipe_row');
- if ( !recipeRow ) {
- alert("Could not get recipe_row!");
- return;
- }
- while ( recipeRow != null && rowIdx < recipeIndex ) {
- recipeRow = recipeRow.nextSibling;
- if ( recipeRow.nodeName.toLowerCase() == 'tr' ) {
- rowIdx++;
- }
- }
-
- var currRow = recipeRow.nextSibling;
- for ( var currIndex = recipeIndex; currIndex < (numRecipes - 1) && currRow != null
- && currRow.nextSibling != null; currRow = currRow.nextSibling )
- {
- if ( currRow.nodeName.toLowerCase() != 'tr' ) continue;
- updateRecipeRowIndexValues(currRow,currIndex);
- currIndex++;
- }
-
- // now remove recipeRow from table
- if ( recipeRow.parentNode.removeChild(recipeRow) ) {
- numRecipes--;
- } else {
- alert("Unable to remove recipe node!");
- }
- }
|