Index: openacs-4/packages/xowiki/www/resources/repeat.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/repeat.js,v diff -u -N -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/xowiki/www/resources/repeat.js 7 Apr 2015 09:53:39 -0000 1.1.2.1 +++ openacs-4/packages/xowiki/www/resources/repeat.js 13 Apr 2015 20:41:06 -0000 1.1.2.2 @@ -16,10 +16,10 @@ if (j == (items.length)-1) { // this is the final item: hide add item button $(e.parentNode).children(".repeat-add-link").hide(); - } else { - // Make an existing but invisible item visible. - items[j].style.display = 'block'; - } + } + // Make an existing but invisible item visible. + items[j].style.display = 'block'; + // IPAD HACK START // for ipad we have to set the contenteditiable to true for the ckeditor inline if it is false var ck_editors = $(items[j]).find('.xowiki-ckeditor.cke_editable.cke_editable_inline.cke_contents_ltr'); @@ -57,11 +57,11 @@ var divs = new Array(); var current = -1; for (var j = 0; j < items.length; j++) { - if (items[j].nodeName != 'DIV') { continue; } - if (items[j].style.display != 'none') { visible ++; } - if (items[j] == item) {current = nr;}; - divs[nr] = items[j]; - nr ++; + if (items[j].nodeName != 'DIV') { continue; } + if (items[j].style.display != 'none') { visible ++; } + if (items[j] == item) {current = nr;}; + divs[nr] = items[j]; + nr ++; } return {'visible' : visible, 'nr' : nr, 'current': current, 'divs' : divs}; } @@ -74,39 +74,40 @@ */ xowiki.repeat.renameItem = function(top, e, from, to) { if (e == undefined) {return;} - //console.log('renameItem: work on ' + e); + //console.log('renameItem: work on ' + e.nodeName + ' ' + from + ' ' + to); //console.info(e); var items = e.children; if (items.length == 0 || e.nodeName == 'SELECT') { - var name = e.name; - if (typeof name != "undefined" && name != "") { - //console.log('renameItem: compare ' + name + ' from ' + from); - var compareLength = from.length; - if (name.substring(0,compareLength) == from) { - if (compareLength != name.length) { - to += name.substring(compareLength, name.length); - } - e.name = to; - e.disabled = false; - // we have also to remove the disabled attribute for options of a select field - if (e.nodeName == 'SELECT') { - $(e).find('option:disabled').each(function() { - $(this).attr('disabled', false); + var name = e.name; + if (typeof name != "undefined" && name != "") { + //console.log('renameItem: compare ' + name + ' from ' + from); + var compareLength = from.length; + if (name.substring(0,compareLength) == from) { + //console.log('renameItem: RENAME ' + name + ' from ' + from); + if (compareLength != name.length) { + to += name.substring(compareLength, name.length); + } + e.name = to; + e.disabled = false; + // we have also to remove the disabled attribute for options of a select field + if (e.nodeName == 'SELECT') { + $(e).find('option:disabled').each(function() { + $(this).attr('disabled', false); }); - } - - console.log('renameItem: renamed ' + name + ' base ' + from + ' to ' + to); - this.renameItem(top, top, - '__old_value_' + from, - '__old_value_' + to); - } - } + } + + //console.log('renameItem: renamed ' + name + ' base ' + from + ' to ' + to); + //this.renameItem(top, top, + // '__old_value_' + from, + // '__old_value_' + to); + } + } } else if (e.nodeName == 'DIV' || e.nodeName == 'FIELDSET') { - for (var j = 0; j < items.length; j++) { - this.renameItem(top, items[j], from, to); - } + for (var j = 0; j < items.length; j++) { + this.renameItem(top, items[j], from, to); + } } else { - console.log('rename ignores ' + e); + console.log('rename ignores ' + e); } } @@ -143,22 +144,30 @@ console.log('delete ' + current); if (current == last) { - //console.log('delete the last item'); + //console.log('delete the last item'); } else { for (var j = current; j < last; j++) { var k = j + 1; - // before moving we are storing the input values --> so that the values are being moved + //console.log('work on ' + j + ': ' + divs[j].innerHTML); + + // before moving, we are storing the input values --> so that the values are being moved // normal input fields $(divs[k]).find(':input[type=text]').each(function() { $(this).attr('value',$(this).val()); }); // radio and checkbox input fields - $(divs[k]).find(':input[type=radio|checkbox]:checked').each(function() { - $(this).attr('checked',$(this).attr('checked')); + // THIS DOES NOT SEEM TO WORK + $(divs[k]).find(':input[type=radio]').each(function() { + //console.info($(this)); + $(this).prop('checked', $(this).checked); }); + // checkbox input fields + $(divs[k]).find(':input[type=checkbox]:checked').each(function() { + $(this).attr('checked',$(this).attr('checked')); + }); // selected options of select fields $(divs[k]).find(':selected').each(function() { $(this).attr('selected','on'); @@ -172,7 +181,6 @@ var oldid = item.parentNode.id + '.' + k; var newid = item.parentNode.id + '.' + j; - // before we can move the items we have to remove the ckeditor instance if available // otherwise it will shown twice after moving (because we are reloading it) // we have to reload because the ckeditor will not work after moving @@ -188,22 +196,24 @@ // console.log('searchString: '+searchString); if (CKEDITOR.instances[l].name.search(searchString) == 0) { // console.log('data to copy: '+CKEDITOR.instances[l].getData()); - - CKEDITOR.instances[l].updateElement(); // should update the textarea but it doesn't -> so we have to do that manually + // should update the textarea but it doesn't -> so we have to do that manually + CKEDITOR.instances[l].updateElement(); document.getElementById(CKEDITOR.instances[l].name).innerHTML=CKEDITOR.instances[l].getData(); CKEDITOR.instances[l].destroy(true); } } } + //console.log(j + ' becomes ' + k + ': ' + divs[k].innerHTML); divs[j].innerHTML = divs[k].innerHTML; - // due to the fact that the ckeditor are using the ids for reloading we have to recycle them (and for the other cases it doesn't hurt) - this.renameIds(divs[j],oldid,newid); - + // due to the fact that the ckeditor are using the ids for reloading + // we have to recycle them (and for the other cases it doesn't hurt) + this.renameIds(divs[j], oldid, newid); + //console.log("RENAME INNER"); this.renameItem(divs[j], divs[j], - data['name'] + '.' + (k), data['name'] + '.' + (j)); + data['name'] + '.' + (k), data['name'] + '.' + (j)); } }; // We add an empty item at the end to force back-reporting of @@ -224,12 +234,14 @@ // .xowiki-ckeditor --> normaler ckeditor // .xowiki-ckeditor.ckeip --> inplace editor // .xowiki-ckeditor.cke_editable.cke_editable_inline.cke_contents_ltr --> inline editing - var ckclasses = [".xowiki-ckeditor",".xowiki-ckeditor.ckeip",".xowiki-ckeditor.cke_editable.cke_editable_inline.cke_contents_ltr"]; + var ckclasses = [".xowiki-ckeditor", + ".xowiki-ckeditor.ckeip", + ".xowiki-ckeditor.cke_editable.cke_editable_inline.cke_contents_ltr"]; for (var i = 0; i < ckclasses.length; i++) { var ck_editors = $(item.parentNode).find(ckclasses[i]); for (var j = 0; j < ck_editors.length; j++) { var idofeditor = ck_editors[j].id; - console.log('reloading ckeditor for id: '+idofeditor); + console.log('reloading ckeditor for id: ' + idofeditor); var functionname = 'load_' + idofeditor; try { window[functionname](); @@ -239,11 +251,10 @@ } } - + //console.log("RENAME LAST"); this.renameItem(divs[last], divs[last], - data['name'] + '.0', data['name'] + '.' + (last)); + data['name'] + '.0', data['name'] + '.' + (last)); - divs[last].style.display = display; // force refresh of tree @@ -288,3 +299,9 @@ }); } +/* + * Local variables: + * mode: Javascript + * indent-tabs-mode: nil + * End: + */