[limb-svn] r6415 - in 3.x/trunk/limb/calendar: shared/js src src/template/tags
svn at limb-project.com
svn at limb-project.com
Mon Oct 15 13:53:24 MSD 2007
Author: svk
Date: 2007-10-15 13:53:24 +0400 (Mon, 15 Oct 2007)
New Revision: 6415
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6415
Modified:
3.x/trunk/limb/calendar/shared/js/datewidget.js
3.x/trunk/limb/calendar/src/lmbDateWidget.class.php
3.x/trunk/limb/calendar/src/template/tags/date_select.tag.php
Log:
- tabs replaced with spaces
Modified: 3.x/trunk/limb/calendar/shared/js/datewidget.js
===================================================================
--- 3.x/trunk/limb/calendar/shared/js/datewidget.js 2007-10-14 09:12:00 UTC (rev 6414)
+++ 3.x/trunk/limb/calendar/shared/js/datewidget.js 2007-10-15 09:53:24 UTC (rev 6415)
@@ -1,225 +1,222 @@
var DATE_WIDGETS = new Object();
function DateWidget_Init(name, show_default, min_year, max_year)
{
- DATE_WIDGETS[name] = new DateWidget(name, show_default, min_year, max_year);
- DATE_WIDGETS[name].init();
+ DATE_WIDGETS[name] = new DateWidget(name, show_default, min_year, max_year);
+ DATE_WIDGETS[name].init();
}
function DateWidget_Action(name, action)
{
- var widget = DATE_WIDGETS[name];
- switch (action)
- {
- case "handle_change":
- DATE_WIDGETS[name].handle_change(DateWidget_Action.arguments[2]);
- break;
- default:
- alert('Unknown action');
- break;
- }
+ var widget = DATE_WIDGETS[name];
+ switch (action)
+ {
+ case "handle_change":
+ DATE_WIDGETS[name].handle_change(DateWidget_Action.arguments[2]);
+ break;
+ default:
+ alert('Unknown action');
+ break;
+ }
}
function DateWidget(name, show_default, min_year, max_year)
{
- if (!document.getElementById(name))
- {
- alert('Component field missed');
- return;
- }
- this.show_default = show_default;
- this.field_id = name;
- this.control = document.getElementById(name);
- this.day_select = document.getElementById(name+"_day");
- this.month_select = document.getElementById(name+"_month");
- this.year_select = document.getElementById(name+"_year");
- this.value = document.getElementById(name).value;
- this.year = this.value ? this.value.substr(0,4) : 0;
- this.month = this.value ? parseInt(this.value.substr(5,2), 10) : 0;
- this.day = this.value ? this.value.substr(8, 2) : 0;
- this.min_year = min_year;
- this.max_year = max_year;
+ if (!document.getElementById(name))
+ {
+ alert('Component field missed');
+ return;
+ }
+ this.show_default = show_default;
+ this.field_id = name;
+ this.control = document.getElementById(name);
+ this.day_select = document.getElementById(name+"_day");
+ this.month_select = document.getElementById(name+"_month");
+ this.year_select = document.getElementById(name+"_year");
+ this.value = document.getElementById(name).value;
+ this.year = this.value ? this.value.substr(0,4) : 0;
+ this.month = this.value ? parseInt(this.value.substr(5,2), 10) : 0;
+ this.day = this.value ? this.value.substr(8, 2) : 0;
+ this.min_year = min_year;
+ this.max_year = max_year;
}
DateWidget.prototype.init = function()
{
- this.remove_options(this.year_select);
- this.remove_options(this.month_select);
- this.remove_options(this.day_select);
- this.setup_options(this.year_select, this.year_options(), this.year);
- this.setup_options(this.month_select, this.month_options(), this.month);
- this.setup_options(this.day_select, this.day_options(this.year, this.month), this.day);
- //var obj = this;
- //this.setValue();
- //setTimeout(function(){obj.setValue();}, 3);
+ this.remove_options(this.year_select);
+ this.remove_options(this.month_select);
+ this.remove_options(this.day_select);
+ this.setup_options(this.year_select, this.year_options(), this.year);
+ this.setup_options(this.month_select, this.month_options(), this.month);
+ this.setup_options(this.day_select, this.day_options(this.year, this.month), this.day);
}
DateWidget.prototype.setValue = function()
{
- this.control.value = parseInt(this.year) + "-" + this.zerofill((parseInt(this.month)), 2) + "-" + this.zerofill(parseInt(this.day), 2);
- if (this.month_select.value === '-1' && this.day_select.value === '-1' && this.year_select.value === '-1')
- {
- this.control.value = "";
- }
- this.value = this.control.value;
- if (!this.show_default && !this.value)
- {
- this.setDefaultValue();
- }
+ this.control.value = parseInt(this.year) + "-" + this.zerofill((parseInt(this.month)), 2) + "-" + this.zerofill(parseInt(this.day), 2);
+ if (this.month_select.value === '-1' && this.day_select.value === '-1' && this.year_select.value === '-1')
+ {
+ this.control.value = "";
+ }
+ this.value = this.control.value;
+ if (!this.show_default && !this.value)
+ {
+ this.setDefaultValue();
+ }
}
DateWidget.prototype.setDefaultValue = function()
{
- this.day = this.day_select.value;
- this.month = this.month_select.value;
- this.year = this.year_select.value;
+ this.day = this.day_select.value;
+ this.month = this.month_select.value;
+ this.year = this.year_select.value;
}
DateWidget.prototype.handle_change = function(field)
{
- switch (field)
- {
- case "month":
- this.month = this.month_select.value;
- this.init();
- break;
- case "day":
- this.day = this.day_select.value;
- this.init();
- break;
- case "year":
- this.year = this.year_select.value;
- this.init();
- break;
- }
+ switch (field)
+ {
+ case "month":
+ this.month = this.month_select.value;
+ this.init();
+ break;
+ case "day":
+ this.day = this.day_select.value;
+ this.init();
+ break;
+ case "year":
+ this.year = this.year_select.value;
+ this.init();
+ break;
+ }
}
DateWidget.prototype.year_options = function()
{
- var opts = new Array();
- if (this.show_default)
- {
- if (Calendar._DEFOPT)
- {
- opts[opts.length] = {value: -1, text:Calendar._DEFOPT['year']};
- }
- else
- {
- opts[opts.length] = {value: -1, text: '---'};
- }
- }
- for (var i=this.max_year; i>=this.min_year; i--)
- {
- opts[opts.length] = {value: i, text:i};
- }
- return opts;
+ var opts = new Array();
+ if (this.show_default)
+ {
+ if (Calendar._DEFOPT)
+ {
+ opts[opts.length] = {value: -1, text:Calendar._DEFOPT['year']};
+ }
+ else
+ {
+ opts[opts.length] = {value: -1, text: '---'};
+ }
+ }
+ for (var i=this.max_year; i>=this.min_year; i--)
+ {
+ opts[opts.length] = {value: i, text:i};
+ }
+ return opts;
}
DateWidget.prototype.month_options = function()
{
- var opts = new Array();
- if (this.show_default)
- {
- if (Calendar._DEFOPT)
- {
- opts[opts.length] = {value: -1, text:Calendar._DEFOPT['month']};
- }
- else
- {
- opts[opts.length] = {value: -1, text: '---'};
- }
- }
- for (var i=0; i<Calendar._MN.length; i++)
- {
- opts[opts.length] = {value: i+1, text: Calendar._MN[i]};
- }
- return opts;
+ var opts = new Array();
+ if (this.show_default)
+ {
+ if (Calendar._DEFOPT)
+ {
+ opts[opts.length] = {value: -1, text:Calendar._DEFOPT['month']};
+ }
+ else
+ {
+ opts[opts.length] = {value: -1, text: '---'};
+ }
+ }
+ for (var i=0; i<Calendar._MN.length; i++)
+ {
+ opts[opts.length] = {value: i+1, text: Calendar._MN[i]};
+ }
+ return opts;
}
DateWidget.prototype.day_options = function(y, m)
{
- m = parseInt(m);
- var maxday;
- var opts = new Array();
- if (this.show_default)
- {
- if (Calendar._DEFOPT)
- {
- opts[opts.length] = {value: -1, text:Calendar._DEFOPT['day']};
- }
- else
- {
- opts[opts.length] = {value: -1, text: '---'};
- }
- }
- switch (m)
- {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- maxday = 31;
- break;
- case 4:
- case 6:
- case 9:
- case 11:
- maxday = 30;
- break;
- case 2:
- maxday = y%4 == 0 ? 29 : 28;
- break;
- default:
- maxday = 31;
- break;
- }
-
- for (var i=1; i<=maxday; i++)
- {
- opts[opts.length] = {value: i, text: i};
- }
- return opts;
+ m = parseInt(m);
+ var maxday;
+ var opts = new Array();
+ if (this.show_default)
+ {
+ if (Calendar._DEFOPT)
+ {
+ opts[opts.length] = {value: -1, text:Calendar._DEFOPT['day']};
+ }
+ else
+ {
+ opts[opts.length] = {value: -1, text: '---'};
+ }
+ }
+ switch (m)
+ {
+ case 1:
+ case 3:
+ case 5:
+ case 7:
+ case 8:
+ case 10:
+ case 12:
+ maxday = 31;
+ break;
+ case 4:
+ case 6:
+ case 9:
+ case 11:
+ maxday = 30;
+ break;
+ case 2:
+ maxday = y%4 == 0 ? 29 : 28;
+ break;
+ default:
+ maxday = 31;
+ break;
+ }
+
+ for (var i=1; i<=maxday; i++)
+ {
+ opts[opts.length] = {value: i, text: i};
+ }
+ return opts;
}
DateWidget.prototype.setup_options = function(elem, opts, v)
{
- if (!elem) return;
- var ind = 0;
- for (var i=0; i<opts.length; i++)
- {
- var opt = document.createElement("option");
- opt.value = opts[i].value;
- opt.text = opts[i].text;
- if (opts[i].value == v)
- {
- ind = i;
- }
- elem.options.add(opt);
- }
- var obj = this;
- setTimeout(function(){elem.selectedIndex=ind;obj.setValue();}, 1);
+ if (!elem) return;
+ var ind = 0;
+ for (var i=0; i<opts.length; i++)
+ {
+ var opt = document.createElement("option");
+ opt.value = opts[i].value;
+ opt.text = opts[i].text;
+ if (opts[i].value == v)
+ {
+ ind = i;
+ }
+ elem.options.add(opt);
+ }
+ var obj = this;
+ setTimeout(function(){elem.selectedIndex=ind;obj.setValue();}, 1);
}
DateWidget.prototype.remove_options = function(elem)
{
- if (!elem) return;
- while (elem.options.length)
- {
- elem.remove(0);
- }
+ if (!elem) return;
+ while (elem.options.length)
+ {
+ elem.remove(0);
+ }
}
DateWidget.prototype.zerofill = function(s, n)
{
- s = s + "";
- var l = s.length;
- var out = "";
- for (var i=0; i<n-l; i++)
- {
- out = "0"+out;
- }
- out = out + s + "";
- return out;
+ s = s + "";
+ var l = s.length;
+ var out = "";
+ for (var i=0; i<n-l; i++)
+ {
+ out = "0"+out;
+ }
+ out = out + s + "";
+ return out;
}
\ No newline at end of file
Modified: 3.x/trunk/limb/calendar/src/lmbDateWidget.class.php
===================================================================
--- 3.x/trunk/limb/calendar/src/lmbDateWidget.class.php 2007-10-14 09:12:00 UTC (rev 6414)
+++ 3.x/trunk/limb/calendar/src/lmbDateWidget.class.php 2007-10-15 09:53:24 UTC (rev 6415)
@@ -8,12 +8,12 @@
*/
/**
- * This class allows you to enter the date by three select fields.
+ * This class allows you to enter the date by three select fields.
* @package calendar
* @version $Id$
*/
class lmbDateWidget {
-
+
protected $newline = "\n";
protected $dw_lang_file;
@@ -27,22 +27,22 @@
protected $min_year;
protected $max_year;
- function __construct($lang = 'en',
- $year_class = "",
- $month_class = "",
- $day_class = "",
- $show_default = false,
- $lib_path = '/shared/calendar/js/')
+ function __construct($lang = 'en',
+ $year_class = "",
+ $month_class = "",
+ $day_class = "",
+ $show_default = false,
+ $lib_path = '/shared/calendar/js/')
{
- $this -> show_default = $show_default;
- $this -> calendar_lib_path = $lib_path;
- $this -> dw_lang_file = 'lang/calendar-' . $lang . '.js';
- $this -> dw_year_class = $year_class;
- $this -> dw_month_class = $month_class;
- $this -> dw_day_class = $day_class;
- $this -> dw_lib_path = preg_replace('/\/+$/', '/', $this->calendar_lib_path).'datewidget.js';
- $this -> min_year = 1950;
- $this -> max_year = 2000;
+ $this->show_default = $show_default;
+ $this->calendar_lib_path = $lib_path;
+ $this->dw_lang_file = 'lang/calendar-' . $lang . '.js';
+ $this->dw_year_class = $year_class;
+ $this->dw_month_class = $month_class;
+ $this->dw_day_class = $day_class;
+ $this->dw_lib_path = preg_replace('/\/+$/', '/', $this->calendar_lib_path).'datewidget.js';
+ $this->min_year = 1950;
+ $this->max_year = 2000;
}
function loadFiles()
@@ -53,13 +53,13 @@
if(!$rendered)
{
- $code = '<script type="text/javascript" src="' .
+ $code = '<script type="text/javascript" src="' .
$this->calendar_lib_path . $this->calendar_file .
'"></script>' . $this->newline;
$code .= '<script type="text/javascript" src="' .
$this->calendar_lib_path . $this->dw_lang_file .
'"></script>' . $this->newline;
- $code .= '<script type="text/javascript" src="' .
+ $code .= '<script type="text/javascript" src="' .
$this->dw_lib_path . '"></script>' . $this->newline;
}
@@ -70,28 +70,28 @@
function makeFields($field_name)
{
- $out = '<select name="'.$field_name.'_day" id="'.$field_name.'_day" class="'.$this->dw_day_class.'" onchange="DateWidget_Action(\''.$field_name.'\', \'handle_change\', \'day\');"></select>'.$this->newline;
- $out .= '<select name="'.$field_name.'_month" id="'.$field_name.'_month" class="'.$this->dw_month_class.'" onchange="DateWidget_Action(\''.$field_name.'\', \'handle_change\', \'month\');"></select>'.$this->newline;
- $out .= '<select name="'.$field_name.'_year" id="'.$field_name.'_year" class="'.$this->dw_year_class.'" onchange="DateWidget_Action(\''.$field_name.'\', \'handle_change\', \'year\');"></select>'.$this->newline;
- $out .= '<script type="text/javascript">DateWidget_Init("'.$field_name.'", '.($this->show_default ? 'true' : 'false').', '.$this->min_year.', '.$this->max_year.');</script>'.$this->newline;
+ $out = '<select name="' . $field_name . '_day" id="' . $field_name . '_day" class="' . $this->dw_day_class . '" onchange="DateWidget_Action(\'' . $field_name . '\', \'handle_change\', \'day\');"></select>' . $this->newline;
+ $out .= '<select name="' . $field_name . '_month" id="' . $field_name . '_month" class="' . $this->dw_month_class . '" onchange="DateWidget_Action(\'' . $field_name . '\', \'handle_change\', \'month\');"></select>' . $this->newline;
+ $out .= '<select name="' . $field_name . '_year" id="' . $field_name . '_year" class="' . $this->dw_year_class . '" onchange="DateWidget_Action(\'' . $field_name . '\', \'handle_change\', \'year\');"></select>' . $this->newline;
+ $out .= '<script type="text/javascript">DateWidget_Init("' . $field_name . '", ' . ($this->show_default ? 'true' : 'false') . ', ' . $this->min_year . ', ' . $this->max_year . ');</script>' . $this->newline;
return $out;
}
-
+
function setMinYear($year)
{
- if ($year > 0)
- {
- $this -> min_year = $year;
- }
+ if ($year > 0)
+ {
+ $this->min_year = $year;
+ }
}
-
+
function setMaxYear($year)
{
- if ($year > 0)
- {
- $this -> max_year = $year;
- }
+ if ($year > 0)
+ {
+ $this->max_year = $year;
+ }
}
-
+
}
\ No newline at end of file
Modified: 3.x/trunk/limb/calendar/src/template/tags/date_select.tag.php
===================================================================
--- 3.x/trunk/limb/calendar/src/template/tags/date_select.tag.php 2007-10-14 09:12:00 UTC (rev 6414)
+++ 3.x/trunk/limb/calendar/src/template/tags/date_select.tag.php 2007-10-15 09:53:24 UTC (rev 6415)
@@ -12,10 +12,11 @@
/**
* @tag date_select
* @forbid_end_tag
+ * @req_attributes id
* @package calendar
- * @req_attributes id
- */
-class DateSelectTag extends WactInputTag
+ * @version $Id: $
+*/
+class lmbDateSelectTag extends WactInputTag
{
function getRenderedTag()
{
@@ -43,14 +44,14 @@
$max_year = $this->getAttribute('max_year');
$widget = new lmbDateWidget($lang, $year_class, $month_class, $day_class, $show_default);
- if ($min_year)
- {
- $widget -> setMinYear(intval($min_year));
- }
- if ($max_year)
- {
- $widget -> setMaxYear(intval($max_year));
- }
+ if ($min_year)
+ {
+ $widget -> setMinYear(intval($min_year));
+ }
+ if ($max_year)
+ {
+ $widget -> setMaxYear(intval($max_year));
+ }
$code->writeHTML($widget->loadFiles() .
More information about the limb-svn
mailing list