[pLog-svn] r5741 - in plog/trunk: class/template/smarty/plugins js/location templates/admin
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Fri Jul 27 17:50:24 EDT 2007
Author: oscar
Date: 2007-07-27 17:50:24 -0400 (Fri, 27 Jul 2007)
New Revision: 5741
Modified:
plog/trunk/class/template/smarty/plugins/function.location_chooser.php
plog/trunk/js/location/location.js
plog/trunk/templates/admin/blogsettings.template
plog/trunk/templates/admin/editpost.template
plog/trunk/templates/admin/editposts.template
plog/trunk/templates/admin/newpost.template
plog/trunk/templates/admin/newresource.template
plog/trunk/templates/admin/resources.template
Log:
Improved location_chooser smarty function so that the same chooser can be used for filtering (like in the "edit posts" screen) and for selection screens (i.e. "new post", "edit post")
Modified: plog/trunk/class/template/smarty/plugins/function.location_chooser.php
===================================================================
--- plog/trunk/class/template/smarty/plugins/function.location_chooser.php 2007-07-27 20:01:03 UTC (rev 5740)
+++ plog/trunk/class/template/smarty/plugins/function.location_chooser.php 2007-07-27 21:50:24 UTC (rev 5741)
@@ -4,6 +4,14 @@
*
* Generates all code necessary to call the location chooser and gather
* its location data.
+ *
+ * Supported parameters:
+ *
+ * @param locations Array with the list of locations. If not provided, they will be dynamically loaded
+ * @param default Default location to be selected
+ * @param showDisplayLink Adds a small icon on the right of the list that will display the currently selected one
+ * @param showAllOption Adds an option labelled "All" to the drop-down filter
+ * @param showAddNewLink Adds a small icon on the right of the list that will allow to add new locations
*/
function smarty_function_location_chooser($params, &$smarty)
{
@@ -24,23 +32,56 @@
$locs = $locations->getBlogLocations( $blogId );
}
+
+ // find the locale
+ if( isset( $smarty->_tpl_vars["locale"] )) {
+ $locale = $smarty->_tpl_vars["locale"];
+ }
+ elseif( isset( $smarty->_tpl_vars["blog"] )) {
+ $blog = $smarty->_tpl_vars["locale"];
+ $locale = $blog->getLocale();
+ }
+ else {
+ lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" );
+ $locale =& Locales::getLocale();
+ }
// default location id, if any
- isset( $params["default"] ) ? $default = $params["default"] : $default = null;
+ if( isset( $params["default"] )) {
+ if( $params["default"] instanceof Location )
+ $default = $params["default"]->getId();
+ else
+ $default = $params["default"];
+ }
+ else
+ $default = null;
- // message for the "add new" string
- isset( $params["addNewString"] ) ? $addNewString = $params["addNewString"] : $addNewString = "Add New";
-
// whether to use the location display icon next to the drop-down list
isset( $params["showDisplayLink"]) ? $showDisplayLink = true : $showDisplayLink = false;
- $code = "<select name=\"locationId\" id=\"locationId\" onChange=\"Lifetype.UI.Location.Selector.onChangeHandler(this);\">";
+ // whether to include an option labelled as "All" with an id of '-1', only meaningful for filtering
+ isset( $params["showAllOption"] ) ? $showAllOption = $params["showAllOption"] : $showAllOption = false;
+
+ // whether to include a link with a plus sign to add new locations
+ isset( $params["showAddNewLink"] ) ? $showAddNewLink = $params["showAddNewLink"] : $showAddNewLink = false;
+
+ $code = "<select name=\"locationId\" id=\"locationId\" onChange=\"Lifetype.UI.Location.Selector.onChangeHandler(this);\">";
+
+ if( $showAllOption ) {
+ $code .= "<option value=\"-1\"";
+ if( $default == -1 )
+ $code .= "selected=\"selected\"";
+ $code .= ">".$locale->tr("all")."</option>";
+ }
+
$code .= "<option value=\"0\"";
- $code .= ">None</option>";
+ if( $default == 0 )
+ $code .= "selected=\"selected\"";
+ $code .= ">".$locale->tr("none")."</option>";
foreach( $locs as $loc ) {
$code .= "<option value=\"".$loc->getId()."\"";
if( $default ) {
- if( $loc->getId() == $default->getId())
+ if( $loc->getId() == $default )
$code .= " selected=\"selected\"";
}
$code .= ">".$loc->getDescription();
@@ -52,12 +93,15 @@
if( count( $locs ) == 0 )
$code .= "<option value=\"-1\">-- Select --</option>";
- $code .= "<option value=\"-1\">$addNewString</option>";
- $code .= " </select>";
+ $code .= " </select>";
if( $showDisplayLink ) {
- $code .= " <a href=\"#\" onClick=\"return(Lifetype.UI.Location.Selector.displaySelected(this))\"><img src=\"imgs/admin/icon_globe-16.png\" alt=\"Location Display\" style=\"border:0px\" /></a>";
+ $code .= " <a href=\"#\" onClick=\"return(Lifetype.UI.Location.Selector.displaySelected(this))\"><img src=\"imgs/admin/icon_globe-16.png\" alt=\"Display\" style=\"border:0px\" /></a>";
}
+
+ if( $showAddNewLink ) {
+ $code .= " <a href=\"#\" onClick=\"return(Lifetype.UI.Location.Selector.addNew(this))\"><img src=\"imgs/admin/icon_add-16.gif\" alt=\"New\" style=\"border:0px\" /></a>";
+ }
$code .= "<input type=\"hidden\" name=\"locationDesc\" id=\"locationDesc\" value=\"\" />
<input type=\"hidden\" name=\"locationLat\" id=\"locationLat\" value=\"\" />
Modified: plog/trunk/js/location/location.js
===================================================================
--- plog/trunk/js/location/location.js 2007-07-27 20:01:03 UTC (rev 5740)
+++ plog/trunk/js/location/location.js 2007-07-27 21:50:24 UTC (rev 5741)
@@ -77,16 +77,24 @@
Lifetype.UI.Location.Selector.onChangeHandler = function( s )
{
- if( s.options[s.selectedIndex].value == -1) {
+ if( s.options[s.selectedIndex].value == -2 ) {
this.o = new Lifetype.UI.ContentOverlay( YAHOO.util.Dom.generateId(), '?op=locationChooser' );
this.o.show();
}
}
+Lifetype.UI.Location.Selector.addNew = function( a )
+{
+ this.o = new Lifetype.UI.ContentOverlay( YAHOO.util.Dom.generateId(), '?op=locationChooser' );
+ this.o.show();
+
+ return( false );
+}
+
Lifetype.UI.Location.Selector.displaySelected = function( a )
{
list = Lifetype.Dom.$('locationId');
- if( list.options[list.selectedIndex].value == 0 )
+ if( list.options[list.selectedIndex].value <= 0 )
return false;
locId = list.options[list.selectedIndex].value;
@@ -216,35 +224,6 @@
}
/**
- * utility method to display a location based on the id from a drop-down list
- * that contains a list of location ids. This is used in editposts.template.
- *
- * @param elem
- * @param ignoreValues
- */
-Lifetype.UI.Location.displaySelectedLocationFromId = function( elem, ignoreValues )
-{
- var list = document.getElementById( elem );
- if( !list )
- return false;
-
- // is it one of the elements of the 'ignoreValues' array?
- for( i = 0; i < ignoreValues.length; i++ ) {
- if( list.options[list.selectedIndex].value == ignoreValues[i] )
- return false;
- }
-
- var locId = list.options[list.selectedIndex].value;
- var text = list.options[list.selectedIndex].text;
- var url = '?op=adminLocationDisplay&locId=' + locId;
-
- window.open(url,'LocationViewer','scrollbars=no,resizable=no,toolbar=no,height=500,width=590');
-
- return false;
-}
-
-
-/**
* Marker is being dragged
*/
GMarker.prototype.markerDragged = function()
@@ -332,8 +311,6 @@
locationList.options[i].text = locDesc;
}
}
-
- Lifetype.UI.Location.Selector.hide();
}
/**
@@ -381,10 +358,11 @@
addNewValue = locationList.options[locationList.selectedIndex].value;
// add the new option
- opt = document.createElement ( 'option' );
+ /*opt = document.createElement ( 'option' );
opt.text = locDesc;
opt.value = locId;
- locationList.options[locationList.options.length - 1] = opt;
+ locationList.options[locationList.options.length - 1] = opt;*/
+ Lifetype.Forms.List.appendToList( 'locationId', locId, locDesc );
// and select the last but one option (the new one that was added)
locationList.selectedIndex = locationList.options.length - 1;
Modified: plog/trunk/templates/admin/blogsettings.template
===================================================================
--- plog/trunk/templates/admin/blogsettings.template 2007-07-27 20:01:03 UTC (rev 5740)
+++ plog/trunk/templates/admin/blogsettings.template 2007-07-27 21:50:24 UTC (rev 5741)
@@ -62,7 +62,7 @@
<label for="locId">{$locale->tr("location")}</label>
<span class="required"*</span>
<div class="formHelp">{$locale->tr("blog_location_help")}</div>
- {location_chooser blogId=$blog->getId() addNewString=$locale->tr("add_new") default=$blog->getLocation() showDisplayLink=1}
+ {location_chooser blogId=$blog->getId() default=$blog->getLocation() showDisplayLink=1 showAddNewLink=1}
</div>
{/if}
Modified: plog/trunk/templates/admin/editpost.template
===================================================================
--- plog/trunk/templates/admin/editpost.template 2007-07-27 20:01:03 UTC (rev 5740)
+++ plog/trunk/templates/admin/editpost.template 2007-07-27 21:50:24 UTC (rev 5741)
@@ -102,7 +102,7 @@
<label for="locId">{$locale->tr("location")}</label>
<span class="required"*</span>
<div class="formHelp">{$locale->tr("article_location_help")}</div>
- {location_chooser blogId=$blog->getId() addNewString=$locale->tr("add_new") showDisplayLink=1 default=$location}
+ {location_chooser blogId=$blog->getId() showAddNewLink=1 showDisplayLink=1 default=$location}
</div>
{/if}
Modified: plog/trunk/templates/admin/editposts.template
===================================================================
--- plog/trunk/templates/admin/editposts.template 2007-07-27 20:01:03 UTC (rev 5740)
+++ plog/trunk/templates/admin/editposts.template 2007-07-27 21:50:24 UTC (rev 5741)
@@ -69,16 +69,7 @@
<div class="list_nav_option">
<label for="location">{$locale->tr("location")}</label>
<br />
- <select name="showLocation" id="locationId">
- <option value="-1" {if $currentlocation == -1} selected="selected" {/if}>{$locale->tr("all")}</option>
- <option value="0" {if $currentlocation == 0} selected="selected" {/if}>{$locale->tr("none")}</option>
- {foreach from=$locations item=location}
- <option value="{$location->getId()}" {if $currentlocation==$location->getId()}selected="selected"{/if}>{$location->getDescription()}</option>
- {/foreach}
- </select>
- <a href="javascript:void(0)" onClick="Lifetype.UI.Location.displaySelectedLocationFromId('locationId', [ 0, -1 ] );">
- <img src="imgs/admin/icon_globe-16.png" alt="View" style="border:0px" />
- </a>
+ {location_chooser blogId=$blog->getId() showAddNew=0 showDisplayLink=1 showAllOption=1 default=$currentlocation}
</div>
{/if}
Modified: plog/trunk/templates/admin/newpost.template
===================================================================
--- plog/trunk/templates/admin/newpost.template 2007-07-27 20:01:03 UTC (rev 5740)
+++ plog/trunk/templates/admin/newpost.template 2007-07-27 21:50:24 UTC (rev 5741)
@@ -113,7 +113,7 @@
<label for="locId">{$locale->tr("location")}</label>
<span class="required"*</span>
<div class="formHelp">{$locale->tr("article_location_help")}</div>
- {location_chooser blogId=$blog->getId() addNewString=$locale->tr("add_new") showDisplayLink=1}
+ {location_chooser blogId=$blog->getId() showAddNewLink=1 showDisplayLink=1}
</div>
{/if}
Modified: plog/trunk/templates/admin/newresource.template
===================================================================
--- plog/trunk/templates/admin/newresource.template 2007-07-27 20:01:03 UTC (rev 5740)
+++ plog/trunk/templates/admin/newresource.template 2007-07-27 21:50:24 UTC (rev 5741)
@@ -39,7 +39,7 @@
<label for="locId">{$locale->tr("location")}</label>
<span class="required"*</span>
<div class="formHelp">{$locale->tr("location_help")}</div>
- {location_chooser locations=$locations addNewString=$locale->tr("add_new") showDisplayLink=1}
+ {location_chooser locations=$locations showAddNewLink=1 showDisplayLink=1}
</div>
{/if}
Modified: plog/trunk/templates/admin/resources.template
===================================================================
--- plog/trunk/templates/admin/resources.template 2007-07-27 20:01:03 UTC (rev 5740)
+++ plog/trunk/templates/admin/resources.template 2007-07-27 21:50:24 UTC (rev 5741)
@@ -26,16 +26,7 @@
<div class="list_nav_option">
<label for="location">{$locale->tr("location")}</label>
<br />
- <select name="showLocation" id="locationId">
- <option value="-1" {if $currentlocation == -1} selected="selected" {/if}>{$locale->tr("all")}</option>
- <option value="0" {if $currentlocation == 0} selected="selected" {/if}>{$locale->tr("none")}</option>
- {foreach from=$locations item=location}
- <option value="{$location->getId()}" {if $currentlocation==$location->getId()}selected="selected"{/if}>{$location->getDescription()}</option>
- {/foreach}
- </select>
- <a href="javascript:void(0)" onClick="Lifetype.UI.Location.displaySelectedLocationFromId('locationId', [ 0, -1 ] );">
- <img src="imgs/admin/icon_globe-16.png" alt="View" style="border:0px" />
- </a>
+ {location_chooser blogId=$blog->getId() showAddNew=0 showDisplayLink=1 showAllOption=1 default=$currentlocation}
</div>
{/if}
More information about the pLog-svn
mailing list