[Linpha-cvs] SF.net SVN: linpha: [4799] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <fan...@us...> - 2007-11-18 22:20:11
|
Revision: 4799 http://linpha.svn.sourceforge.net/linpha/?rev=4799&view=rev Author: fangehrn Date: 2007-11-18 14:20:05 -0800 (Sun, 18 Nov 2007) Log Message: ----------- 2007-11-18 flo * installer - some UI improvements - added sys_public_installation to sql.data.php and update it only in step10_postsettings.php like the other settings * integrity.php fixed bug and readded bypass for install check with install/ignore_delete_install_msg.txt * created global class for inline popups - updated scriptaculous (1.8.0) and prototype (1.6.0) * maps plugin - fixed some annoying IE bugs (edit marker not working, ajax data not working) - using inline popup for help window Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/docs/dev/TODO.txt trunk/linpha2/docs/dev/external_libraries.txt trunk/linpha2/install/ignore_delete_install_msg.txt trunk/linpha2/install/step10_postsettings.php trunk/linpha2/install/step11_finish.php trunk/linpha2/install/step3_dbtype.php trunk/linpha2/lib/include/integrity.php trunk/linpha2/lib/include/sql.data.php trunk/linpha2/lib/js/LinGlobal.js trunk/linpha2/lib/js/builder.js trunk/linpha2/lib/js/controls.js trunk/linpha2/lib/js/dragdrop.js trunk/linpha2/lib/js/effects.js trunk/linpha2/lib/js/prototype.js trunk/linpha2/lib/js/scriptaculous.js trunk/linpha2/lib/js/slider.js trunk/linpha2/lib/js/unittest.js trunk/linpha2/lib/plugins/maps/LinMaps.js trunk/linpha2/lib/plugins/maps/class.googlemaps.js trunk/linpha2/lib/plugins/maps/module.maps.php trunk/linpha2/templates/default/maps.html.php trunk/linpha2/templates/default/themes/default/css/global.css Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/ChangeLog 2007-11-18 22:20:05 UTC (rev 4799) @@ -1,3 +1,16 @@ +2007-11-18 flo + * installer + - some UI improvements + - added sys_public_installation to sql.data.php and update it + only in step10_postsettings.php like the other settings + * integrity.php fixed bug and readded bypass for install check with + install/ignore_delete_install_msg.txt + * created global class for inline popups + - updated scriptaculous (1.8.0) and prototype (1.6.0) + * maps plugin + - fixed some annoying IE bugs (edit marker not working, ajax data not working) + - using inline popup for help window + 2007-11-10 bzrudi * bump exiftool to latest 7.00 stable release * fixed a couple of issues in installer and maintenance_import.php Modified: trunk/linpha2/docs/dev/TODO.txt =================================================================== --- trunk/linpha2/docs/dev/TODO.txt 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/docs/dev/TODO.txt 2007-11-18 22:20:05 UTC (rev 4799) @@ -24,7 +24,7 @@ - should enable browsers cache for the thumbnails and maybe also for the images -- fix error handler +- fix (adodb) error handler ## Big Todos Modified: trunk/linpha2/docs/dev/external_libraries.txt =================================================================== --- trunk/linpha2/docs/dev/external_libraries.txt 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/docs/dev/external_libraries.txt 2007-11-18 22:20:05 UTC (rev 4799) @@ -1,8 +1,8 @@ - csshover.htc V1.42.060206 -- scriptaculous 1.6.4 (contains prototype) -- prototype 1.5.0_rc1 +- scriptaculous 1.8.0 (contains prototype) +- prototype 1.6.0 - adodb Modified: trunk/linpha2/install/ignore_delete_install_msg.txt =================================================================== --- trunk/linpha2/install/ignore_delete_install_msg.txt 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/install/ignore_delete_install_msg.txt 2007-11-18 22:20:05 UTC (rev 4799) @@ -0,0 +1,2 @@ +If this file exists, the check for existing ./install directory is ignored. +This file must be remove in official releases. \ No newline at end of file Modified: trunk/linpha2/install/step10_postsettings.php =================================================================== --- trunk/linpha2/install/step10_postsettings.php 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/install/step10_postsettings.php 2007-11-18 22:20:05 UTC (rev 4799) @@ -85,10 +85,10 @@ ?> <div align="center"> <div class="box4"> - <input type='radio' name='sys_public_installation' value='1' checked=checked> - <?php echo i18n_install("<b>Internet</b>"); ?> - <input type='radio' name='sys_public_installation' value='0' > - <?php echo i18n_install("<b>Intranet</b>"); ?> + <input type='radio' id='linInputTypeInternet' name='sys_public_installation' value='1' checked=checked><label for="linInputTypeInternet"> + <?php echo i18n_install("<b>Internet</b>"); ?></label> + <input type='radio' id='linInputTypeIntranet' name='sys_public_installation' value='0' ><label for="linInputTypeIntranet"> + <?php echo i18n_install("<b>Intranet</b>"); ?></label> </div> </div> @@ -105,13 +105,13 @@ ?> <div align="center"> <div class="box2"> - <input type='radio' name='quality' value='1'>High Quality<br /> - <img src='./graphics/hqdemo.jpg' width="120" height="90" border="0""> + <input type='radio' id='linInputQualityHigh' name='quality' value='1'><label for="linInputQualityHigh">High Quality<br /> + <img src='./graphics/hqdemo.jpg' width="120" height="90" border="0""></label> </div> <div class="box2" style="float: none; "> - <input type='radio' name='quality' value='0' checked>Low Quality<br /> - <img src='./graphics/lqdemo.jpg' width="120" height="90" border="0""> + <input type='radio' id='linInputQualityLow' name='quality' value='0' checked><label for="linInputQualityLow">Low Quality<br /> + <img src='./graphics/lqdemo.jpg' width="120" height="90" border="0""></label> </div> </div> <?php @@ -126,21 +126,21 @@ <div align="center"> <div class="box3"> - <input type='radio' name='sys_style_tn_size' value='90'> + <input type='radio' id='linInputTNSize90' name='sys_style_tn_size' value='90'><label for="linInputTNSize90"> 90 pixel<br /> - <img src='./graphics/thumb90px.jpg' /> + <img src='./graphics/thumb90px.jpg' /></label> </div> <div class="box3"> - <input type='radio' name='sys_style_tn_size' value='120' checked="checked"> + <input type='radio' id='linInputTNSize120' name='sys_style_tn_size' value='120' checked="checked"><label for="linInputTNSize120"> 120 pixel<br /> - <img src='./graphics/thumb120px.jpg' /> + <img src='./graphics/thumb120px.jpg' /></label> </div> <div class="box3"> - <input type='radio' name='sys_style_tn_size' value='150'> + <input type='radio' id='linInputTNSize150' name='sys_style_tn_size' value='150'><label for="linInputTNSize150"> 150 pixel<br /> - <img src='./graphics/thumb150px.jpg'> + <img src='./graphics/thumb150px.jpg'></label> </div> </div> <br /> @@ -154,18 +154,18 @@ ?> <div align="center"> <div class="box4"> - <input type='radio' name='sys_import_use_exiftool' value='1'> + <input type='radio' id='linInputExifToolYes' name='sys_import_use_exiftool' value='1'><label for="linInputExifToolYes"> <?php echo i18n_install("Yes"); ?> - <input type='radio' name='sys_import_use_exiftool' value='0' checked=checked> + <input type='radio' id='linInputExifToolNo' name='sys_import_use_exiftool' value='0' checked=checked><label for="linInputExifToolNo"> <?php echo i18n_install("No"); ?> <?php echo i18n_install("Enable Exiftool"); ?> </div> <div class="box4"> - <input type='radio' name='sys_import_use_emb_thumb' value='1'> + <input type='radio' id='linInputEmbTNYes' name='sys_import_use_emb_thumb' value='1'><label for="linInputEmbTNYes"> <?php echo i18n_install("Yes"); ?> - <input type='radio' name='sys_import_use_emb_thumb' value='0' checked=checked> + <input type='radio' id='linInputEmbTNNo' name='sys_import_use_emb_thumb' value='0' checked=checked><label for="linInputEmbTNNo"> <?php echo i18n_install("No"); ?> <?php echo i18n_install("Extract Embedded Thumbnails"); ?> Modified: trunk/linpha2/install/step11_finish.php =================================================================== --- trunk/linpha2/install/step11_finish.php 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/install/step11_finish.php 2007-11-18 22:20:05 UTC (rev 4799) @@ -86,10 +86,9 @@ echo "<br />".i18n_install("Saving Install Type (Internet/Intranet) To Database...").' '; if( isset( $_POST['sys_public_installation'] ) ) { - $result = $linpha->db->Execute("INSERT INTO ".LIN_PREFIX."config " . - "(option_value, option_name) VALUES (" . - "'".LinSql::linAddslashes($_POST['sys_public_installation'])."', " . - "'".LinSql::linAddslashes('sys_public_installation')."')"); + $result = $linpha->db->Execute("UPDATE ".LIN_PREFIX."config " . + "SET option_value = '".LinSql::linAddslashes($_POST['sys_public_installation'])."' " . + "WHERE option_name = 'sys_public_installation'"); if(!$result) { echo failed_msg(); @@ -102,7 +101,7 @@ else { echo failed_msg(); - echo "<br />".i18n_install("Error - No Value Specified!"); + echo "<br />".i18n_install("Error: No Value Specified!"); $error_nr = 1; } @@ -115,20 +114,25 @@ $result = $linpha->db->Execute("UPDATE ".LIN_PREFIX."config " . "SET option_value = '".LinSql::linAddslashes($_POST['sys_style_tn_size'])."' " . "WHERE option_name = 'sys_style_thumb_size_max'"); - if(!$result) - { + if(!$result) { echo failed_msg(); + $error_nr = 1; } else { - $result = $linpha->db->Execute("UPDATE ".LIN_PREFIX."config " . + $result = $linpha->db->Execute("UPDATE ".LIN_PREFIX."config " . "SET option_value = '".LinSql::linAddslashes($_POST['sys_style_tn_size'])."' " . "WHERE option_name = 'sys_style_thumb_size_display'"); - echo success_msg(); + if(!$result) { + echo failed_msg(); + $error_nr = 1; + } else { + echo success_msg(); + } } } else { echo failed_msg(); - echo "<br />".i18n_install("Error - No Value Specified!"); + echo "<br />".i18n_install("Error: No Value Specified!"); $error_nr = 1; } Modified: trunk/linpha2/install/step3_dbtype.php =================================================================== --- trunk/linpha2/install/step3_dbtype.php 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/install/step3_dbtype.php 2007-11-18 22:20:05 UTC (rev 4799) @@ -125,11 +125,13 @@ <br /><br /> <h1><?php echo i18n_install("Select Installation Mode"); ?></h1><hr> -<input type='radio' name='install_mode' value='automatic' checked="checked"> -<?php echo i18n_install("Automatic mode"); ?> +<input type='radio' id='linInputModeAutomatic' name='install_mode' value='automatic' checked="checked"><?php +/* no linebreak between <input> and <label> tag */ ?><label for="linInputModeAutomatic"> +<?php echo i18n_install("Automatic mode"); ?></label> <br /> -<input type='radio' name='install_mode' value='manual'> -<?php echo i18n_install("Manual Mode (Experts Only)"); ?> +<input type='radio' id='linInputModeManual' name='install_mode' value='manual'><?php +/* no linebreak between <input> and <label> tag */ ?><label for="linInputModeManual"> +<?php echo i18n_install("Manual Mode (Experts Only)"); ?></label> <?php include_once(LINPHA_DIR.'/install/footer.php'); Modified: trunk/linpha2/lib/include/integrity.php =================================================================== --- trunk/linpha2/lib/include/integrity.php 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/lib/include/integrity.php 2007-11-18 22:20:05 UTC (rev 4799) @@ -29,46 +29,34 @@ /** * check folders */ - $folders = array("install", "album", "tmp", "cache"); - $install_type_public = $GLOBALS['linpha']->sql->config->value['sys_public_installation']; + /** + * Install directory check only on public installation + */ + $dir = LinSql::getPath('install'); + if( !file_exists($dir.'/ignore_delete_install_msg.txt') && file_exists($dir) && + $GLOBALS['linpha']->sql->config->value['sys_public_installation'] == true) + { + throw new Exception(i18n("For security reasons, the LinPHA ./install directory needs to be removed!")); + } - foreach($folders AS $directory) + $folders = array("album", "tmp", "cache"); + foreach($folders as $directory) { - $dir = LinSql::getPath($directory); - - /** - * Install directory check only on public installation - */ - if( $directory == "install" && file_exists($dir) && $install_type_public == true) - { - throw new Exception(i18n("For security reasons, the LinPHA $dir " . - "directory needs to be removed!")); - break; - } - else - { - break; - } + $dir = LinSql::getPath($directory); if( ! file_exists($dir) ) { - throw new Exception(i18n("Directory ".$dir." doesn't exist - " . - "Please make sure to create directory manually.")); - break; + throw new Exception( getErrorMsg(1,$dir)); } - if( ! is_writable($dir) && $directory != "album") + if( ! is_readable($dir) ) { - throw new Exception(i18n("Directory ".$dir." is not writable - " . - "Please change write permissions manually.")); - break; + throw new Exception( getErrorMsg(2,$dir)); } - - if( ! is_readable($dir) ) + + if( ! is_writable($dir) && $directory != "album") { - throw new Exception(i18n("Directory ".$dir." is not readable - " . - "Please change read permissions manually")); - break; + throw new Exception( getErrorMsg(3,$dir)); } } } @@ -77,5 +65,26 @@ die("Error: ".$error -> getMessage()); } +function getErrorMsg($type,$dir) { + switch($type) + { + case 1: + // Do not break strings inside i18n() function. + // Language translation would not work anymore! + return sprintf(i18n("Directory %s doesn't exist - Please make sure to create directory manually."),$dir); + break; + case 2: + // Do not break strings inside i18n() function. + // Language translation would not work anymore! + return sprintf(i18n("Directory %s is not readable - Please change read permissions manually"),$dir); + break; + case 3: + // Do not break strings inside i18n() function. + // Language translation would not work anymore! + return sprintf(i18n("Directory %s is not writable - Please change write permissions manually."),$dir); + break; + } +} + /* vi: set ts=4 sw=4 sts=4 */ -?> +?> \ No newline at end of file Modified: trunk/linpha2/lib/include/sql.data.php =================================================================== --- trunk/linpha2/lib/include/sql.data.php 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/lib/include/sql.data.php 2007-11-18 22:20:05 UTC (rev 4799) @@ -27,6 +27,7 @@ */ $options = array( 'sys_db_version' => '3', + 'sys_public_installation' => '1', 'sys_im_bracket_support' => $_SESSION['sys_im_bracket_support'], 'sys_im_imagemagick_path' => $_SESSION['sys_im_convert_path'], Modified: trunk/linpha2/lib/js/LinGlobal.js =================================================================== --- trunk/linpha2/lib/js/LinGlobal.js 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/lib/js/LinGlobal.js 2007-11-18 22:20:05 UTC (rev 4799) @@ -21,6 +21,8 @@ this.linPageYOffset = 0; this.tabs = new Array(); + + this.nofPopups = 0; }, /** @@ -231,7 +233,42 @@ //this.tabs[ className ][ tabNr ] = ''; //this.tabs.className.tabNr = ''; $(elemAId).style.color = ''; + }, + + /** + * popup functions + */ + createPopup: function( elemId ) { + this.divPopupWindow = Builder.node('div', {id: 'linPopup'+this.nofPopups, className: 'linPopupWindow'} ); + + var divClose = Builder.node('div', {className: 'linPopupClose'}); + var divCloseButton = Builder.node('input', {type: 'button', value: 'X', + onclick: 'myLinGlobal.closePopup(\'linPopup'+this.nofPopups+'\')', className: 'linPopupCloseButton'}); + divClose.appendChild(divCloseButton); + + var divTitleBar = Builder.node('div', {className: 'linPopupTitleBar'} ); + divTitleBar.appendChild(divClose); + + + var divText = $(elemId).cloneNode(true); + divText.className = 'linPopupText'; + Element.show(divText); + + this.divPopupWindow.appendChild(divTitleBar); + this.divPopupWindow.appendChild(divText); + + document.body.appendChild(this.divPopupWindow); + + new Draggable(this.divPopupWindow, {handle: 'linPopupTitleBar'}); + + this.nofPopups++; + }, + closePopup: function(elemId) { + document.body.removeChild($(elemId)); } + + + // no comma at last function. firefox works, but IE not! } /** Modified: trunk/linpha2/lib/js/builder.js =================================================================== --- trunk/linpha2/lib/js/builder.js 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/lib/js/builder.js 2007-11-18 22:20:05 UTC (rev 4799) @@ -1,8 +1,9 @@ -// script.aculo.us builder.js v1.6.4, Wed Sep 06 11:30:58 CEST 2006 +// script.aculo.us builder.js v1.8.0, Tue Nov 06 15:01:40 +0300 2007 -// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) +// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) // -// See scriptaculous.js for full license. +// script.aculo.us is freely distributable under the terms of an MIT-style license. +// For details, see the script.aculo.us web site: http://script.aculo.us/ var Builder = { NODEMAP: { @@ -35,7 +36,7 @@ var element = parentElement.firstChild || null; // see if browser added wrapping tags - if(element && (element.tagName != elementName)) + if(element && (element.tagName.toUpperCase() != elementName)) element = element.getElementsByTagName(elementName)[0]; // fallback to createElement approach @@ -47,7 +48,8 @@ // attributes (or text) if(arguments[1]) if(this._isStringOrNumber(arguments[1]) || - (arguments[1] instanceof Array)) { + (arguments[1] instanceof Array) || + arguments[1].tagName) { this._children(element, arguments[1]); } else { var attrs = this._attributes(arguments[1]); @@ -63,9 +65,9 @@ for(attr in arguments[1]) element[attr == 'class' ? 'className' : attr] = arguments[1][attr]; } - if(element.tagName != elementName) + if(element.tagName.toUpperCase() != elementName) element = parentElement.getElementsByTagName(elementName)[0]; - } + } } // text, or array of children @@ -77,14 +79,24 @@ _text: function(text) { return document.createTextNode(text); }, + + ATTR_MAP: { + 'className': 'class', + 'htmlFor': 'for' + }, + _attributes: function(attributes) { var attrs = []; for(attribute in attributes) - attrs.push((attribute=='className' ? 'class' : attribute) + - '="' + attributes[attribute].toString().escapeHTML() + '"'); + attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) + + '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'"') + '"'); return attrs.join(" "); }, _children: function(element, children) { + if(children.tagName) { + element.appendChild(children); + return; + } if(typeof children=='object') { // array can hold nodes and text children.flatten().each( function(e) { if(typeof e=='object') @@ -94,12 +106,17 @@ element.appendChild(Builder._text(e)); }); } else - if(Builder._isStringOrNumber(children)) - element.appendChild(Builder._text(children)); + if(Builder._isStringOrNumber(children)) + element.appendChild(Builder._text(children)); }, _isStringOrNumber: function(param) { return(typeof param=='string' || typeof param=='number'); }, + build: function(html) { + var element = this.node('div'); + $(element).update(html.strip()); + return element.down(); + }, dump: function(scope) { if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope @@ -116,4 +133,4 @@ } }); } -} \ No newline at end of file +} Modified: trunk/linpha2/lib/js/controls.js =================================================================== --- trunk/linpha2/lib/js/controls.js 2007-11-11 09:48:23 UTC (rev 4798) +++ trunk/linpha2/lib/js/controls.js 2007-11-18 22:20:05 UTC (rev 4799) @@ -1,14 +1,15 @@ -// script.aculo.us controls.js v1.6.4, Wed Sep 06 11:30:58 CEST 2006 +// script.aculo.us controls.js v1.8.0, Tue Nov 06 15:01:40 +0300 2007 -// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) -// (c) 2005 Ivan Krstic (http://blogs.law.harvard.edu/ivan) -// (c) 2005 Jon Tirsen (http://www.tirsen.com) +// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) +// (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan) +// (c) 2005-2007 Jon Tirsen (http://www.tirsen.com) // Contributors: // Richard Livsey // Rahul Bhargava // Rob Wills // -// See scriptaculous.js for full license. +// script.aculo.us is freely distributable under the terms of an MIT-style license. +// For details, see the script.aculo.us web site: http://script.aculo.us/ // Autocompleter.Base handles all the autocompletion functionality // that's independent of the data source for autocompletion. This @@ -38,22 +39,23 @@ if(typeof Effect == 'undefined') throw("controls.js requires including script.aculo.us' effects.js library"); -var Autocompleter = {} -Autocompleter.Base = function() {}; -Autocompleter.Base.prototype = { +var Autocompleter = { } +Autocompleter.Base = Class.create({ baseInitialize: function(element, update, options) { - this.element = $(element); + element = $(element) + this.element = element; this.update = $(update); this.hasFocus = false; this.changed = false; this.active = false; this.index = 0; this.entryCount = 0; + this.oldElementValue = this.element.value; if(this.setOptions) this.setOptions(options); else - this.options = options || {}; + this.options = options || { }; this.options.paramName = this.options.paramName || this.element.name; this.options.tokens = this.options.tokens || []; @@ -75,6 +77,9 @@ if(typeof(this.options.tokens) == 'string') this.options.tokens = new Array(this.options.tokens); + // Force carriage returns as token delimiters anyway + if (!this.options.tokens.include('\n')) + this.options.tokens.push('\n'); this.observer = null; @@ -82,15 +87,14 @@ Element.hide(this.update); - Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this)); - Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this)); + Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this)); + Event.observe(this.element, 'keypress', this.onKeyPress.bindAsEventListener(this)); }, show: function() { if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update); if(!this.iefix && - (navigator.appVersion.indexOf('MSIE')>0) && - (navigator.userAgent.indexOf('Opera')<0) && + (Prototype.Browser.IE) && (Element.getStyle(this.update, 'position')=='absolute')) { new Insertion.After(this.update, '<iframe id="' + this.update.id + '_iefix" '+ @@ -140,17 +144,17 @@ case Event.KEY_UP: this.markPrevious(); this.render(); - if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event); + if(Prototype.Browser.WebKit) Event.stop(event); return; case Event.KEY_DOWN: this.markNext(); this.render(); - if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event); + if(Prototype.Browser.WebKit) Event.stop(event); return; } else if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN || - (navigator.appVersion.indexOf('AppleWebKit') > 0 && event.keyCode == 0)) return; + (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return; this.changed = true; this.hasFocus = true; @@ -196,7 +200,6 @@ this.index==i ? Element.addClassName(this.getEntry(i),"selected") : Element.removeClassName(this.getEntry(i),"selected"); - if(this.hasFocus) { this.show(); this.active = true; @@ -239,21 +242,22 @@ } var value = ''; if (this.options.select) { - var nodes = document.getElementsByClassName(this.options.select, selectedElement) || []; + var nodes = $(selectedElement).select('.' + this.options.select) || []; if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select); } else value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal'); - var lastTokenPos = this.findLastToken(); - if (lastTokenPos != -1) { - var newValue = this.element.value.substr(0, lastTokenPos + 1); - var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/); + var bounds = this.getTokenBounds(); + if (bounds[0] != -1) { + var newValue = this.element.value.substr(0, bounds[0]); + var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/); if (whitespace) newValue += whitespace[0]; - this.element.value = newValue + value; + this.element.value = newValue + value + this.element.value.substr(bounds[1]); } else { this.element.value = value; } + this.oldElementValue = this.element.value; this.element.focus(); if (this.options.afterUpdateElement) @@ -264,11 +268,11 @@ if(!this.changed && this.hasFocus) { this.update.innerHTML = choices; Element.cleanWhitespace(this.update); - Element.cleanWhitespace(this.update.firstChild); + Element.cleanWhitespace(this.update.down()); - if(this.update.firstChild && this.update.firstChild.childNodes) { + if(this.update.firstChild && this.update.down().childNodes) { this.entryCount = - this.update.firstChild.childNodes.length; + this.update.down().childNodes.length; for (var i = 0; i < this.entryCount; i++) { var entry = this.getEntry(i); entry.autocompleteIndex = i; @@ -297,39 +301,48 @@ onObserverEvent: function() { this.changed = false; + this.tokenBounds = null; if(this.getToken().length>=this.options.minChars) { - this.startIndicator(); this.getUpdatedChoices(); } else { this.active = false; this.hide(); } + this.oldElementValue = this.element.value; }, getToken: function() { - var tokenPos = this.findLastToken(); - if (tokenPos != -1) - var ret = this.element.value.substr(tokenPos + 1).replace(/^\s+/,'').replace(/\s+$/,''); - else - var ret = this.element.value; - - return /\n/.test(ret) ? '' : ret; + var bounds = this.getTokenBounds(); + return this.element.value.substring(bounds[0], bounds[1]).strip(); }, - findLastToken: function() { - var lastTokenPos = -1; - - for (var i=0; i<this.options.tokens.length; i++) { - var thisTokenPos = this.element.value.lastIndexOf(this.options.tokens[i]); - if (thisTokenPos > lastTokenPos) - lastTokenPos = thisTokenPos; + getTokenBounds: function() { + if (null != this.tokenBounds) return this.tokenBounds; + var value = this.element.value; + if (value.strip().empty()) return [-1, 0]; + var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue); + var offset = (diff == this.oldElementValue.length ? 1 : 0); + var prevTokenPos = -1, nextTokenPos = value.length; + var tp; + for (var index = 0, l = this.options.tokens.length; index < l; ++index) { + tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1); + if (tp > prevTokenPos) prevTokenPos = tp; + tp = value.indexOf(this.options.tokens[index], diff + offset); + if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp; } - return lastTokenPos; + return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]); } -} +}); -Ajax.Autocompleter = Class.create(); -Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), { +Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) { + var boundary = Math.min(newS.length, oldS.length); + for (var index = 0; index < boundary; ++index) + if (newS[index] != oldS[index]) + return index; + return boundary; +}; + +Ajax.Autocompleter = Class.create(Autocompleter.Base, { initialize: function(element, update, url, options) { this.baseInitialize(element, update, options); this.options.asynchronous = true; @@ -339,7 +352,9 @@ }, getUpdatedChoices: function() { - entry = encodeURIComponent(this.options.paramName) + '=' + + this.startIndicator(); + + var entry = encodeURIComponent(this.options.paramName) + '=' + encodeURIComponent(this.getToken()); this.options.parameters = this.options.callback ? @@ -347,14 +362,13 @@ if(this.options.defaultParams) this.options.parameters += '&' + this.options.defaultParams; - + new Ajax.Request(this.url, this.options); }, onComplete: function(request) { this.updateChoices(request.responseText); } - }); // The local array autocompleter. Used when you'd prefer to @@ -392,8 +406,7 @@ // In that case, the other options above will not apply unless // you support them. -Autocompleter.Local = Class.create(); -Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), { +Autocompleter.Local = Class.create(Autocompleter.Base, { initialize: function(element, update, array, options) { this.baseInitialize(element, update, options); this.options.array = array; @@ -449,13 +462,12 @@ ret = ret.concat(partial.slice(0, instance.options.choices - ret.length)) return "<ul>" + ret.join('') + "</ul>"; } - }, options || {}); + }, options || { }); } }); -// AJAX in-place editor -// -// see documentation on http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor +// AJAX in-place editor and collection editor +// Full rewrite by Christophe Porteneuve <td...@td...> (April 2007). // Use this if you notice weird scrolling problems on some browsers, // the DOM might be a bit confused when this gets called so do this @@ -466,352 +478,472 @@ }, 1); } -Ajax.InPlaceEditor = Class.create(); -Ajax.InPlaceEditor.defaultHighlightColor = "#FFFF99"; -Ajax.InPlaceEditor.prototype = { +Ajax.InPlaceEditor = Class.create({ initialize: function(element, url, options) { this.url = url; - this.element = $(element); - - this.options = Object.extend({ - okButton: true, - okText: "ok", - cancelLink: true, - cancelText: "cancel", - savingText: "Saving...", - clickToEditText: "Click to edit", - okText: "ok", - rows: 1, - onComplete: function(transport, element) { - new Effect.Highlight(element, {startcolor: this.options.highlightcolor}); - }, - onFailure: function(transport) { - alert("Error communicating with the server: " + transport.responseText.stripTags()); - }, - callback: function(form) { - return Form.serialize(form); - }, - handleLineBreaks: true, - loadingText: 'Loading...', - savingClassName: 'inplaceeditor-saving', - loadingClassName: 'inplaceeditor-loading', - formClassName: 'inplaceeditor-form', - highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor, - highlightendcolor: "#FFFFFF", - externalControl: null, - submitOnBlur: false, - ajaxOptions: {}, - evalScripts: false - }, options || {}); - - if(!this.options.formId && this.element.id) { - this.options.formId = this.element.id + "-inplaceeditor"; - if ($(this.options.formId)) { - // there's already a form with that name, don't specify an id - this.options.formId = null; - } + this.element = element = $(element); + this.prepareOptions(); + this._controls = { }; + arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!! + Object.extend(this.options, options || { }); + if (!this.options.formId && this.element.id) { + this.options.formId = this.element.id + '-inplaceeditor'; + if ($(this.options.formId)) + this.options.formId = ''; } - - if (this.options.externalControl) { + if (this.options.externalControl) this.options.externalControl = $(this.options.externalControl); - } - - this.originalBackground = Element.getStyle(this.element, 'background-color'); - if (!this.originalBackground) { - this.originalBackground = "transparent"; - } - + if (!this.options.externalControl) + this.options.externalControlOnly = false; + this._originalBackground = this.element.getStyle('background-color') || 'transparent'; this.element.title = this.options.clickToEditText; - - this.onclickListener = this.enterEditMode.bindAsEventListener(this); - this.mouseoverListener = this.enterHover.bindAsEventListener(this); - this.mouseoutListener = this.leaveHover.bindAsEventListener(this); - Event.observe(this.element, 'click', this.onclickListener); - Event.observe(this.element, 'mouseover', this.mouseoverListener); - Event.observe(this.element, 'mouseout', this.mouseoutListener); - if (this.options.externalControl) { - Event.observe(this.options.externalControl, 'click', this.onclickListener); - Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener); - Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener); - } + this._boundCancelHandler = this.handleFormCancellation.bind(this); + this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this); + this._boundFailureHandler = this.handleAJAXFailure.bind(this); + this._boundSubmitHandler = this.handleFormSubmission.bind(this); + this._boundWrapperHandler = this.wrapUp.bind(this); + this.registerListeners(); }, - enterEditMode: function(evt) { - if (this.saving) return; - if (this.editing) return; - this.editing = true; - this.onEnterEditMode(); - if (this.options.externalControl) { - Element.hide(this.options.externalControl); - } - Element.hide(this.element); - this.createForm(); - this.element.parentNode.insertBefore(this.form, this.element); - if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField); - // stop the event to avoid a page refresh in Safari - if (evt) { - Event.stop(evt); - } - return false; + checkForEscapeOrReturn: function(e) { + if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) return; + if (Event.KEY_ESC == e.keyCode) + this.handleFormCancellation(e); + else if (Event.KEY_RETURN == e.keyCode) + this.handleFormSubmission(e); }, - createForm: function() { - this.form = document.createElement("form"); - this.form.id = this.options.formId; - Element.addClassName(this.form, this.options.formClassName) - this.form.onsubmit = this.onSubmit.bind(this); - - this.createEditField(); - - if (this.options.textarea) { - var br = document.createElement("br"); - this.form.appendChild(br); + createControl: function(mode, handler, extraClasses) { + var control = this.options[mode + 'Control']; + var text = this.options[mode + 'Text']; + if ('button' == control) { + var btn = document.createElement('input'); + btn.type = 'submit'; + btn.value = text; + btn.className = 'editor_' + mode + '_button'; + if ('cancel' == mode) + btn.onclick = this._boundCancelHandler; + this._form.appendChild(btn); + this._controls[mode] = btn; + } else if ('link' == control) { + var link = document.createElement('a'); + link.href = '#'; + link.appendChild(document.createTextNode(text)); + link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler; + link.className = 'editor_' + mode + '_link'; + if (extraClasses) + link.className += ' ' + extraClasses; + this._form.appendChild(link); + this._controls[mode] = link; } - - if (this.options.okButton) { - okButton = document.createElement("input"); - okButton.type = "submit"; - okButton.value = this.options.okText; - okButton.className = 'editor_ok_button'; - this.form.appendChild(okButton); - } - - if (this.options.cancelLink) { - cancelLink = document.createElement("a"); - cancelLink.href = "#"; - cancelLink.appendChild(document.createTextNode(this.options.cancelText)); - cancelLink.onclick = this.onclickCancel.bind(this); - cancelLink.className = 'editor_cancel'; - this.form.appendChild(cancelLink); - } }, - hasHTMLLineBreaks: function(string) { - if (!this.options.handleLineBreaks) return false; - return string.match(/<br/i) || string.match(/<p>/i); - }, - convertHTMLLineBreaks: function(string) { - return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, ""); - }, createEditField: function() { - var text; - if(this.options.loadTextURL) { - text = this.options.loadingText; - } else { - text = this.getText(); - } - - var obj = this; - - if (this.options.rows == 1 && !this.hasHTMLLineBreaks(text)) { - this.options.textarea = false; - var textField = document.createElement("input"); - textField.obj = this; - textField.type = "text"; - textField.name = "value"; - textField.value = text; - textField.style.backgroundColor = this.options.highlightcolor; - textField.className = 'editor_field'; + var text = (this.options.loadTextURL ? this.options.loadingText : this.getText()); + var fld; + if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) { + fld = document.createElement('input'); + fld.type = 'text'; var size = this.options.size || this.options.cols || 0; - if (size != 0) textField.size = size; - if (this.options.submitOnBlur) - textField.onblur = this.onSubmit.bind(this); - this.editField = textField; + if (0 < size) fld.size = size; } else { - this.options.textarea = true; - var textArea = document.createElement("textarea"); - textArea.obj = this; - textArea.name = "value"; - textArea.value = this.convertHTMLLineBreaks(text); - textArea.rows = this.options.rows; - textArea.cols = this.options.cols || 40; - textArea.className = 'editor_field'; - if (this.options.submitOnBlur) - textArea.onblur = this.onSubmit.bind(this); - this.editField = textArea; + fld = document.createElement('textarea'); + fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows); + fld.cols = this.options.cols || 40; } - - if(this.options.loadTextURL) { + fld.name = this.options.paramName; + fld.value = text; // No HTML breaks conversion anymore + fld.className = 'editor_field'; + if (this.options.submitOnBlur) + fld.onblur = this._boundSubmitHandler; + this._controls.editor = fld; + if (this.options.loadTextURL) this.loadExternalText(); - } - this.form.appendChild(this.editField); + this._form.appendChild(this._controls.editor); }, - getText: function() { - return this.element.innerHTML; + createForm: function() { + var ipe = this; + function addText(mode, condition) { + var text = ipe.options['text' + mode + 'Controls']; + if (!text || condition === false) return; + ipe._form.appendChild(document.createTextNode(text)); + }; + this._form = $(document.createElement('form')); + this._form.id = this.options.formId; + this._form.addClassName(this.options.formClassName); + this._form.onsubmit = this._boundSubmitHandler; + this.createEditField(); + if ('textarea' == this._controls.editor.tagName.toLowerCase()) + this._form.appendChild(document.createElement('br')); + if (this.options.onFormCustomization) + this.options.onFormCustomization(this, this._form); + addText('Before', this.options.okControl || this.options.cancelControl); + this.createControl('ok', this._boundSubmitHandler); + addText('Between', this.options.okControl && this.options.cancelControl); + this.createControl('cancel', this._boundCancelHandler, 'editor_cancel'); + addText('After', this.options.okControl || this.options.cancelControl); }, - loadExternalText: function() { - Element.addClassName(this.form, this.options.loadingClassName); - this.editField.disabled = true; - new Ajax.Request( - this.options.loadTextURL, - Object.extend({ - asynchronous: true, - onComplete: this.onLoadedExternalText.bind(this) - }, this.options.ajaxOptions) - ); + destroy: function() { + if (this._oldInnerHTML) + this.element.innerHTML = this._oldInnerHTML; + this.leaveEditMode(); + this.unregisterListeners(); }, - onLoadedExternalText: function(transport) { - Element.removeClassName(this.form, this.options.loadingClassName); - this.editField.disabled = false; - this.editField.value = transport.responseText.stripTags(); - Field.scrollFreeActivate(this.editField); + enterEditMode: function(e) { + if (this._saving || this._editing) return; + this._editing = true; + this.triggerCallback('onEnterEditMode'); + if (this.options.externalControl) + this.options.externalControl.hide(); + this.element.hide(); + this.createForm(); + this.element.parentNode.insertBefore(this._form, this.element); + if (!this.options.loadTextURL) + this.postProcessEditField(); + if (e) Event.stop(e); }, - onclickCancel: function() { - this.onComplete(); - this.leaveEditMode(); - return false; + enterHover: function(e) { + if (this.options.hoverClassName) + this.element.addClassName(this.options.hoverClassName); + if (this._saving) return; + this.triggerCallback('onEnterHover'); }, - onFailure: function(transport) { - this.options.onFailure(transport); - if (this.oldInnerHTML) { - this.element.innerHTML = this.oldInnerHTML; - this.oldInnerHTML = null; + getText: function() { + return this.element.innerHTML; + }, + handleAJAXFailure: function(transport) { + this.triggerCallback('onFailure', transport); + if (this._oldInnerHTML) { + this.element.innerHTML = this._oldInnerHTML; + this._oldInnerHTML = null; } - return false; }, - onSubmit: function() { - // onLoading resets these so we need to save them away for the Ajax call - var form = this.form; - var value = this.editField.value; - - // do this first, sometimes the ajax call returns before we get a chance to switch on Saving... - // which means this will actually switch on Saving... *after* we've left edit mode causing Saving... - // to be displayed indefinitely - this.onLoading(); - - if (this.options.evalScripts) { - new Ajax.Request( - this.url, Object.extend({ - parameters: this.options.callback(form, value), - onComplete: this.onComplete.bind(this), - onFailure: this.onFailure.bind(this), - asynchronous:true, - evalScripts:true - }, this.options.ajaxOptions)); - } else { - new Ajax.Updater( - { success: this.element, - // don't update on failure (this could be an option) - failure: null }, - this.url, Object.extend({ - parameters: this.options.callback(form, value), - onComplete: this.onComplete.bind(this), - onFailure: this.onFailure.bind(this) - }, this.options.ajaxOptions)); + handleFormCancellation: function(e) { + this.wrapUp(); + if (e) Event.stop(e); + }, + handleFormSubmission: function(e) { + var form = this._form; + var value = $F(this._controls.editor); + this.prepareSubmission(); + var params = this.options.callback(form, value) || ''; + if (Object.isString(params)) + params = params.toQueryParams(); + params.editorId = this.element.id; + if (this.options.htmlResponse) { + var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions); + Object.extend(options, { + parameters: params, + onComplete: this._boundWrapperHandler, + onFailure: this._boundFailureHandler + }); + new Ajax.Updater({ success: this.element }, this.url, options); + } else { + var options = Object.extend({ method: 'get' }, this.options.ajaxOptions); + Object.extend(options, { + parameters: params, + onComplete: this._boundWrapperHandler, + onFailure: this._boundFailureHandler + }); + new Ajax.Request(this.url, options); } - // stop the event to avoid a page refresh in Safari - if (arguments.length > 1) { - Event.stop(arguments[0]); - } - return false; + if (e) Event.stop(e); }, - onLoading: function() { - this.saving = true; + leaveEditMode: function() { + this.element.removeClassName(this.options.savingClassName); this.removeForm(); this.leaveHover(); + this.element.style.backgroundColor = this._originalBackground; + this.element.show(); + if (this.options.externalControl) + this.options.externalControl.show(); + this._saving = false; + this._editing = false; + this._oldInnerHTML = null; + this.triggerCallback('onLeaveEditMode'); + }, + leaveHover: function(e) { + if (this.options.hoverClassName) + this.element.removeClassName(this.options.hoverClassName); + if (this._saving) return; + this.triggerCallback('onLeaveHover'); + }, + loadExternalText: function() { + this._form.addClassName(this.options.loadingClassName); + this._controls.editor.disabled = true; + var options = Object.extend({ method: 'get' }, this.options.ajaxOptions); + Object.extend(options, { + parameters: 'editorId=' + encodeURIComponent(this.element.id), + onComplete: Prototype.emptyFunction, + onSuccess: function(transport) { + this._form.removeClassName(this.options.loadingClassName); + var text = transport.responseText; + if (this.options.stripLoadedTextTags) + text = text.stripTags(); + this._controls.editor.value = text; + this._controls.editor.disabled = false; + this.postProcessEditField(); + }.bind(this), + onFailure: this._boundFailureHandler + }); + new Ajax.Request(this.options.loadTextURL, options); + }, + postProcessEditField: function() { + var fpc = this.options.fieldPostCreation; + if (fpc) + $(this._controls.editor)['focus' == fpc ? 'focus' : 'activate'](); + }, + prepareOptions: function() { + this.options = Object.clone(Ajax.InPlaceEditor.DefaultOptions); + Object.extend(this.options, Ajax.InPlaceEditor.DefaultCallbacks); + [this._extraDefaultOptions].flatten().compact().each(function(defs) { + Object.extend(this.options, defs); + }.bind(this)); + }, + prepareSubmission: function() { + this._saving = true; + this.removeForm(); + this.leaveHover(); this.showSaving(); }, + registerListeners: function() { + this._listeners = { }; + var listener; + $H(Ajax.InPlaceEditor.Listeners).each(function(pair) { + listener = this[pair.value].bind(this); + this._listeners[pair.key] = listener; + if (!this.options.externalControlOnly) + this.element.observe(pair.key, listener); + if (this.options.externalControl) + this.options.externalControl.observe(pair.key, listener); + }.bind(this)); + }, + removeForm: function() { + if (!this._form) return; + this._form.remove(); + this._form = null; + this._controls = { }; + }, showSaving: function() { - this.oldInnerHTML = this.element.innerHTML; + this._oldInnerHTML = this.element.innerHTML; this.element.innerHTML = this.options.savingText; - Element.addClassName(this.element, this.options.savingClassName); - this.element.style.backgroundColor = this.originalBackground; - Element.show(this.element); + this.element.addClassName(this.options.savingClassName); + this.element.style.backgroundColor = this._originalBackground; + this.element.show(); }, - removeForm: function() { - if(this.form) { - if (this.form.parentNode) Element.remove(this.form); - this.form = null; + triggerCallback: function(cbName, arg) { + if ('function' == typeof this.options[cbName]) { + this.options[cbName](this, arg); } }, - enterHover: function() { - if (this.saving) return; - this.element.style.backgroundColor = this.options.highlightcolor; - if (this.effect) { - this.effect.cancel(); - } - Element.addClassName(this.element, this.options.hoverClassName) + unregisterListeners: function() { + $H(this._listeners).each(function(pair) { + if (!this.options.externalControlOnly) + this.element.stopObserving(pair.key, pair.value); + if (this.options.externalControl) + this.options.externalControl.stopObserving(pair.key, pair.value); + }.bind(this)); }, - leaveHover: function() { - if (this.options.backgroundColor) { - this.element.style.backgroundColor = this.oldBackground; - } - Element.removeClassName(this.element, this.options.hoverClassName) - if (this.saving) return; - this.effect = new Effect.Highlight(this.element, { - startcolor: this.options.highlightcolor, - endcolor: this.options.highlightendcolor, - restorecolor: this.originalBackground + wrapUp: function(transport) { + this.leaveEditMode(); + // Can't use triggerCallback due to backward compatibility: requires + // binding + direct element + this._boundComplete(transport, this.element); + } +}); + +Object.extend(Ajax.InPlaceEditor.prototype, { + dispose: Ajax.InPlaceEditor.prototype.destroy +}); + +Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, { + initialize: function($super, element, url, options) { + this._extraDefaultOptions = Ajax.InPlaceCollectionEditor.DefaultOptions; + $super(element, url, options); + }, + + createEditField: function() { + var list = document.createElement('select'); + list.name = this.options.paramName; + list.size = 1; + this._controls.editor = list; + this._collection = this.options.collection || []; + if (this.options.loadCollectionURL) + this.loadCollection(); + else + this.checkForExternalText(); + this._form.appendChild(this._controls.editor); + }, + + loadCollection: function() { + this._form.addClassName(this.options.loadingClassName); + this.showLoadingText(this.options.loadingCollectionText); + var options = Object.extend({ method: 'get' }, this.options.ajaxOptions); + Object.extend(options, { + parameters: 'editorId=' + encodeURIComponent(this.element.id), + onComplete: Prototype.emptyFunction, + onSuccess: function(transport) { + var js = transport.responseText.strip(); + if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check + throw 'Server returned an invalid collection representation.'; + this._collection = eval(js); + this.checkForExternalText(); + }.bind(this), + onFailure: this.onFailure }); + new Ajax.Request(this.options.loadCollectionURL, options); }, - leaveEditMode: function() { - Element.removeClassName(this.element, this.options.savingClassName); - this.removeForm(); - this.leaveHover(); - this.element.style.backgroundColor = this.originalBackground; - Element.show(this.element); - if (this.options.externalControl) { - Element.show(this.options.externalControl); + + showLoadingText: function(text) { + this._controls.editor.disabled = true; + var tempOption = this._controls.editor.firstChild; + if (!tempOption) { + tempOption = document.createElement('option'); + tempOption.value = ''; + this._controls.editor.appendChild(tempOption); + tempOption.selected = true; } - this.editing = false; - this.saving = false; - this.oldInnerHTML = null; - this.onLeaveEditMode(); + tempOption.update((text || '').stripScripts().stripTags()); }, - onComplete: function(transport) { - this.leaveEditMode(); - this.options.onComplete.bind(this)(transport, this.element); + + checkForExternalText: function() { + this._text = this.getText(); + if (this.options.loadTextURL) + this.loadExternalText(); + else + this.buildOptionList(); }, - onEnterEditMode: function() {}, - onLeaveEditMode: function() {}, - dispose: function() { - if (this.oldInnerHTML) { - this.element.innerHTML = this.oldInnerHTML; - } - this.leaveEditMode(); - Event.stopObserving(this.element, 'click', this.onclickListener); - Event.stopObserving(this.element, 'mouseover', this.mouseoverListener); - Event.stopObserving(this.element, 'mouseout', this.mouseoutListener); - if (this.options.externalControl) { - Event.stopObserving(this.options.externalControl, 'click', this.onclickListener); - Event.stopObserving(this.options.externalControl, 'mouseover', this.mouseoverListener); - Event.stopObserving(this.options.externalControl, 'mouseout', this.mouseoutListener); - } + + loadExternalText: function() { + this.showLoadingText(this.options.loadingText); + var options = Object.extend({ method: 'get' }, this.options.ajaxOptions); + Object.extend(options, { + parameters: 'editorId=' + encodeURIComponent(this.element.id), + onComplete: Prototype.emptyFunction, + onSuccess: function(transport) { + this._text = transport.responseText.strip(); + this.buildOptionList(); + }.bind(this), + onFailure: this.onFailure + }); + new Ajax.Request(this.options.loadTextURL, options); + }, + + buildOptionList: function() { + this._form.removeClassName(this.options.loadingClassName); + this._collection = this._collection.map(function(entry) { + return 2 === entry.length ? entry : [entry, entry].flatten(); + }); + var marker = ('value' in this.options) ? this.options.value : this._text; + var textFound = this._collection.any(function(entry) { + return entry[0] == marker; + }.bind(this)); + this._controls.editor.update(''); + var option; + this._collection.each(function(entry, index) { + option = document.createElement('option'); + option.value = entry[0]; + option.selected = textFound ? entry[0] == marker : 0 == index; + option.appendChild(document.createTextNode(entry[1])); + this._controls.editor.appendChild(option); + }.bind(this)); + this._controls.editor.disabled = false; + Field.scrollFreeActivate(this._controls.editor); } +}); + +//**** DEPRECATION LAYER FOR InPlace[Collection]Editor! **** +//**** This only exists for a while, in order to let **** +//**** users adapt to the new API. Read up on the new **** +//**** API and convert your code to it ASAP! **** + +Ajax.InPlaceEditor.prototype.initialize.dealWithDeprecatedOptions = function(options) { + if (!options) return; + function fallback(name, expr) { + if (name in options || expr === undefined) return; + options[name] = expr; + }; + fallback('cancelControl', (options.cancelLink ? 'link' : (options.cancelButton ? 'button' : + options.cancelLink == options.cancelButton == false ? false : undefined))); + fallback('okControl', (options.okLink ? 'link' : (options.okButton ? 'button' : + options.okLink == options.okButton == false ? false : undefined))); + fallback('highlightColor', options.highlightcolor); + fallback('highlightEndColor', options.highlightendcolor); }; -Ajax.InPlaceCollectionEditor = Class.create(); -Object.extend(Ajax.InPlaceCollectionEditor.prototype, Ajax.InPlaceEditor.prototype); -Object.extend(Ajax.InPlaceCollectionEditor.prototype, { - createEditField: function() { - if (!this.cached_selectTag) { - var selectTag = document.createElement("select"); - var collection = this.options.collection || []; - var optionTag; - collection.each(function(e,i) { - optionTag = document.createElement("option"); - optionTag.value = (e instanceof Array) ? e[0] : e; - if((typeof this.options.value == 'undefined') && - ((e instanceof Array) ? this.element.innerHTML == e[1] : e == optionTag.value)) optionTag.selected = true; - if(this.options.value==optionTag.value) optionTag.selected = true; - optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e)); - selectTag.appendChild(optionTag); - }.bind(this)); - this.cached_selectTag = selectTag; +Object.extend(Ajax.InPlaceEditor, { + DefaultOptions: { + ajaxOptions: { }, + autoRows: 3, // Use when multi-line w/ rows == 1 + cancelControl: 'link', // 'link'|'button'|false + cancelText: 'cancel', + clickToEditText: 'Click to edit', + externalControl: null, // id|elt + externalControlOnly: false, + fieldPostCreation: 'activate', // 'activate'|'focus'|false + formClassName: 'inplaceeditor-form', + formId: null, // id|elt + highlightColor: '#ffff99', + highlightEndColor: '#ffffff', + hoverClassName: '', + htmlResponse: true, + loadingClassName: 'inplaceeditor-loading', + loadingText: 'Loading...', + okControl: 'button', // 'link'|'button'|false + okText: 'ok', + paramName: 'value', + rows: 1, // If 1 and multi-line, uses autoRows + savingClassName: 'inplaceeditor-saving', + savingText: 'Saving...', + size: 0, + stripLoadedTextTags: false, + submitOnBlur: false, + textAfterControls: '', + textBeforeControls: '', + textBetweenControls: '' + }, + DefaultCallbacks: { + callback: function(form) { + return Form.serialize(form); + }, + onComplete: function(transport, element) { + // For backward compatibility, this one is bound to the IPE, and passes + // the element directly. It was too often customized, so we don't break it. + new Effect.Highlight(element, { + startcolor: this.options.highlightColor, keepBackgroundImage: true }); + }, + onEnterEditMode: null, + onEnterHover: function(ipe) { + ipe.element.style.backgroundColor = ipe.options.highlightColor; + if (ipe._effect) + ipe._effect.cancel(); + }, + onFailure: function(transport, ipe) { + alert('Error communication with the server: ' + transport.responseText.stripTags()); + }, + onFormCustomization: null, // Takes the IPE and its generated form, after editor, before controls. + onLeaveEditMode: null, + onLeaveHover: function(ipe) { + ipe._effect = new Effect.Highlight(ipe.element, { + startcolor: ipe.options.highlightColor, endcolor: ipe.options.highlightEndColor, + restorecolor: ipe._originalBackground, keepBackgroundImage: true + }); } - - this.editField = this.cached_selectTag; - if(this.options.loadTextURL) this.loadExternalText(); - this.form.appendChild(this.editField); - this.options.callback = function(form, value) { - return "value=" + encodeURIComponent(value); - } + }, + Listeners: { + click: 'enterEditMode', + keydown: 'checkForEscapeOrReturn', + mouseover: 'enterHover',... [truncated message content] |