/* Copyright 2008 Kevin Morey (email : kevin@kmorey.net) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ var STR_REACTIVATE_TAGLINE = "Re-activate Tagline"; var STR_REMOVE_TAGLINE = "Remove Tagline"; var ID_ACTIVE = 'active_taglines'; var ID_REMOVED = 'removed_taglines'; window.addEvent('domready', function() { var myAccordion = new Accordion('h3.toggler', 'div.element', { opacity: false, alwaysHide: true }); }); function advtag_target_changed (select) { if (select.value == "[custom]") { select.value = "_TEST"; } } function advtag_addTagline() { var textElem = $('add_text'); var linkElem = $('add_link'); var targetElem = $('add_target'); advtag_newTagline(textElem.value, linkElem.value, targetElem.value); textElem.value = ""; linkElem.value = ""; targetElem.value = ""; } function advtag_newTagline(text, link, target) { //TODO: create a class for the tagline elements var newElem = new Element('tr'); var moveUpCell = new Element('td'); var moveUpBtn = new Element('input', { 'type' : 'button', 'class' : 'button btn-move-up', 'title' : 'Move Up', 'value' : '', 'events' : { 'click' : function(){ advtag_moveUp(this); } } }); moveUpBtn.inject(moveUpCell); var moveDownCell = new Element('td'); var moveDownBtn = new Element('input', { 'type' : 'button', 'class' : 'button btn-move-down', 'title' : 'Move Down', 'value' : '', 'events' : { 'click' : function() { advtag_moveDown(this); } } }); moveDownBtn.inject(moveDownCell); var removeCell = new Element('td'); var removeBtn = new Element('input', { 'type' : 'button', 'class' : 'button btn-remove', 'title' : STR_REMOVE_TAGLINE, 'value' : '', 'events' : { 'click' : function(){ advtag_removeTag(this); } } }); removeBtn.inject(removeCell); var textCell = new Element('td'); var textBox = new Element('input', { 'class' : 'advtag-text-empty', 'name' : 'tag[]', 'type' : 'text', 'size' : '50', 'value' : text }); textBox.inject(textCell); var linkCell = new Element('td'); var linkBox = new Element('input', { 'class' : 'advtag-link-empty', 'name' : 'link[]', 'type' : 'text', 'size' : '50', 'value' : link }); linkBox.inject(linkCell); var targetCell = new Element('td'); var targetBox = new Element('input', { 'class' : 'advtag-target-empty', 'name' : 'target[]', 'type' : 'text', 'size' : '15', 'value' : target }); targetBox.inject(targetCell); moveUpCell.inject(newElem); moveDownCell.inject(newElem); textCell.inject(newElem); linkCell.inject(newElem); targetCell.inject(newElem); removeCell.inject(newElem); newElem.inject($(ID_ACTIVE)); advtag_updateButtons($(ID_ACTIVE)); advtag_updateHeaders($(ID_ACTIVE)); } function advtag_removeTag(sender) { var elem = $(sender).getParent('tr'); if (elem == null) { return; } var parent = elem.getParent(); var active = $(ID_ACTIVE); var removed = $(ID_REMOVED); if (parent == active) { elem.inject(removed); } else { elem.inject(active); } advtag_updateButtons(parent); //be sure to update both sets advtag_updateHeaders(active); advtag_updateHeaders(removed); } function advtag_updateHeaders(tbody) { var thead = tbody.getPrevious("thead"); if (thead == null) { return; } if (tbody.getChildren().length > 0) { thead.setStyle('display', ''); } else { thead.setStyle('display', 'none'); } } function advtag_updateButtons(tbody) { tbody.getChildren('tr').each(advtag_updateRowButtons); } function advtag_updateRowButtons(elem, index, array) { //TODO: find a better way to get the buttons var children = elem.getChildren(); var moveUpBtn = children[0].getChildren()[0]; var moveDownBtn = children[1].getChildren()[0]; var removeBtn = children[2].getChildren()[0]; if (elem.getPrevious('tr') == null) { moveUpBtn.disabled = true; } else { moveUpBtn.disabled = false; } if (elem.getNext('tr') == null) { moveDownBtn.disabled = true; } else { moveDownBtn.disabled = false; } if (elem.getParent('tbody') == $(ID_ACTIVE)) { removeBtn.title = STR_REMOVE_TAGLINE; } else { removeBtn.title = STR_REACTIVATE_TAGLINE; } } function advtag_moveUp(sender) { var elem = $(sender).getParent('tr'); if (elem == null) { return; } var prev = elem.getPrevious('tr'); if (prev == null) { return; } elem.inject(prev, 'before'); advtag_updateButtons(elem.getParent('tbody')); } function advtag_moveDown(sender) { var elem = $(sender).getParent('tr'); if (elem == null) { return; } var next = elem.getNext('tr'); if (next == null) { return; } elem.inject(next, 'after'); advtag_updateButtons(elem.getParent('tbody')); } function advtag_purgeRemoved() { $(ID_REMOVED).getChildren('tr').each(advtag_purgeItem); advtag_updateHeaders($(ID_REMOVED)); } function advtag_purgeItem(item, index, array) { item.dispose(); }