summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorwei <>2007-01-24 05:52:22 +0000
committerwei <>2007-01-24 05:52:22 +0000
commite306989c6d03aac37e2557465b4812ea21970065 (patch)
tree7e2524a33cedf49831eb3c5ae15cd1bed3c3ab2c /framework
parentdec4042d10caa5a54b753fab950f16218fa62d8d (diff)
Fixed #517, #519, #521
Diffstat (limited to 'framework')
-rw-r--r--framework/Data/ActiveRecord/Exceptions/messages.txt3
-rw-r--r--framework/Data/ActiveRecord/TActiveRecord.php30
-rw-r--r--framework/Web/Javascripts/js/compressed/ajax.js3
-rw-r--r--framework/Web/Javascripts/js/compressed/prado.js10
-rw-r--r--framework/Web/Javascripts/js/compressed/validator.js8
-rw-r--r--framework/Web/Javascripts/js/debug/ajax.js7
-rw-r--r--framework/Web/Javascripts/js/debug/prado.js14
-rw-r--r--framework/Web/Javascripts/js/debug/validator.js18
-rw-r--r--framework/Web/Javascripts/prado/activecontrols3.js7
-rw-r--r--framework/Web/Javascripts/prado/controls.js14
-rw-r--r--framework/Web/Javascripts/prado/validation3.js18
-rw-r--r--framework/Web/UI/ActiveControls/TActivePageAdapter.php5
12 files changed, 99 insertions, 38 deletions
diff --git a/framework/Data/ActiveRecord/Exceptions/messages.txt b/framework/Data/ActiveRecord/Exceptions/messages.txt
index 774c0275..53d8f4e3 100644
--- a/framework/Data/ActiveRecord/Exceptions/messages.txt
+++ b/framework/Data/ActiveRecord/Exceptions/messages.txt
@@ -12,4 +12,5 @@ ar_mismatch_args_exception = ActiveRecord finder method '{0}' expects {1} pa
ar_invalid_tablename_property = ActiveRecord tablename property '{0}::${1}' must be static and not null.
ar_value_must_not_be_null = Property '{0}::${2}' must not be null as defined by column '{2}' in table '{1}'.
ar_missing_pk_values = Missing primary key values in forming IN(key1, key2, ...) for table '{0}'.
-ar_pk_value_count_mismatch = Composite key value count mismatch in forming IN( (key1, key2, ..), (key3, key4, ..)) for table '{0}'. \ No newline at end of file
+ar_pk_value_count_mismatch = Composite key value count mismatch in forming IN( (key1, key2, ..), (key3, key4, ..)) for table '{0}'.
+ar_must_copy_from_array_or_object = $data in {0}::copyFrom($data) must be an object or an array. \ No newline at end of file
diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php
index 9272e1b9..9bc74c0f 100644
--- a/framework/Data/ActiveRecord/TActiveRecord.php
+++ b/framework/Data/ActiveRecord/TActiveRecord.php
@@ -424,7 +424,9 @@ abstract class TActiveRecord extends TComponent
* Dynamic find method using parts of method name as search criteria.
* Method name starting with "findBy" only returns 1 record.
* Method name starting with "findAllBy" returns 0 or more records.
- * The condition is taken as part of the method name after "findBy" or "findAllBy".
+ * Method name starting with "deleteBy" deletes records by the trail criteria.
+ * The condition is taken as part of the method name after "findBy", "findAllBy"
+ * or "deleteBy".
*
* The following are equivalent:
* <code>
@@ -440,25 +442,47 @@ abstract class TActiveRecord extends TComponent
* $finder->findAllByAge($age);
* $finder->findAll('Age = ?', $age);
* </code>
+ * <code>
+ * $finder->deleteAll('Name = ?', $name);
+ * $finder->deleteByName($name);
+ * </code>
* @return mixed single record if method name starts with "findBy", 0 or more records
* if method name starts with "findAllBy"
*/
public function __call($method,$args)
{
+ $delete =false;
if($findOne = substr(strtolower($method),0,6)==='findby')
$condition = $method[6]==='_' ? substr($method,7) : substr($method,6);
else if(substr(strtolower($method),0,9)==='findallby')
$condition = $method[9]==='_' ? substr($method,10) : substr($method,9);
+ else if($delete = substr(strtolower($method),0,8)==='deleteby')
+ $condition = $method[8]==='_' ? substr($method,9) : substr($method,8);
else
return null;//throw new TActiveRecordException('ar_invalid_finder_method',$method);
+
+ $criteria = $this->createCriteriaFromString($method, $condition, $args);
+ if($delete)
+ return $this->deleteAll($criteria);
+ else
+ return $findOne ? $this->find($criteria) : $this->findAll($criteria);
+ }
+
+ /**
+ * @param string __call method name
+ * @param string criteria conditions
+ * @param array method arguments
+ * @return TActiveRecordCriteria criteria created from the method name and its arguments.
+ */
+ private function createCriteriaFromString($method, $condition, $args)
+ {
$fields = array();
foreach(preg_split('/and|_and_/i',$condition) as $field)
$fields[] = $field.' = ?';
$args=count($args) === 1 && is_array($args[0]) ? $args[0] : $args;
if(count($fields)>count($args))
throw new TActiveRecordException('ar_mismatch_args_exception',$method,count($fields),count($args));
- $criteria = new TActiveRecordCriteria(implode(' AND ',$fields),$args);
- return $findOne ? $this->find($criteria) : $this->findAll($criteria);
+ return new TActiveRecordCriteria(implode(' AND ',$fields),$args);
}
}
?> \ No newline at end of file
diff --git a/framework/Web/Javascripts/js/compressed/ajax.js b/framework/Web/Javascripts/js/compressed/ajax.js
index ffc57483..5bf062d9 100644
--- a/framework/Web/Javascripts/js/compressed/ajax.js
+++ b/framework/Web/Javascripts/js/compressed/ajax.js
@@ -257,7 +257,8 @@ this.timer=setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
{Prado.WebUI.TTimeTriggeredCallback.timers[timer.options.ID]=timer;},start:function(id)
{Prado.WebUI.TTimeTriggeredCallback.timers[id].startTimer();},stop:function(id)
{Prado.WebUI.TTimeTriggeredCallback.timers[id].stopTimer();}});Prado.WebUI.ActiveListControl=Base.extend({constructor:function(options)
-{this.element=$(options.ID);this.options=options;Event.observe(this.element,"change",this.doCallback.bind(this));},doCallback:function(event)
+{this.element=$(options.ID);if(this.element)
+{this.options=options;Event.observe(this.element,"change",this.doCallback.bind(this));}},doCallback:function(event)
{var request=new Prado.CallbackRequest(this.options.EventTarget,this.options);request.dispatch();Event.stop(event);}});Prado.WebUI.TActiveDropDownList=Prado.WebUI.ActiveListControl;Prado.WebUI.TActiveListBox=Prado.WebUI.ActiveListControl;Prado.WebUI.TEventTriggeredCallback=Base.extend({constructor:function(options)
{this.options=options;var element=$(options['ControlID']);if(element)
Event.observe(element,this.getEventName(element),this.doCallback.bind(this));},getEventName:function(element)
diff --git a/framework/Web/Javascripts/js/compressed/prado.js b/framework/Web/Javascripts/js/compressed/prado.js
index e1c566e0..74e19278 100644
--- a/framework/Web/Javascripts/js/compressed/prado.js
+++ b/framework/Web/Javascripts/js/compressed/prado.js
@@ -346,8 +346,9 @@ elements[i].checked=true;}},checkIndices:function(elements,indices)
{new Insertion.After(element,content);},before:function(element,content)
{new Insertion.Before(element,content);}}
Prado.WebUI=Class.create();Prado.WebUI.PostBackControl=Class.create();Prado.WebUI.PostBackControl.prototype={initialize:function(options)
-{this._elementOnClick=null,this.element=$(options.ID);if(this.onInit)
-this.onInit(options);},onInit:function(options)
+{this._elementOnClick=null,this.element=$(options.ID);if(this.element)
+{if(this.onInit)
+this.onInit(options);}},onInit:function(options)
{if(typeof(this.element.onclick)=="function")
{this._elementOnClick=this.element.onclick;this.element.onclick=null;}
Event.observe(this.element,"click",this.elementClicked.bindEvent(this,options));},elementClicked:function(event,options)
@@ -369,8 +370,9 @@ if(y_input)
{y_input.value=y;}
else
{y_input=INPUT({type:'hidden',name:id+'_y','id':id+'_y',value:y});this.element.parentNode.appendChild(y_input);}}});Prado.WebUI.TRadioButton=Class.extend(Prado.WebUI.PostBackControl);Prado.WebUI.TRadioButton.prototype.onRadioButtonInitialize=Prado.WebUI.TRadioButton.prototype.initialize;Object.extend(Prado.WebUI.TRadioButton.prototype,{initialize:function(options)
-{this.element=$(options['ID']);if(!this.element.checked)
-this.onRadioButtonInitialize(options);}});Prado.WebUI.TTextBox=Class.extend(Prado.WebUI.PostBackControl,{onInit:function(options)
+{this.element=$(options['ID']);if(this.element)
+{if(!this.element.checked)
+this.onRadioButtonInitialize(options);}}});Prado.WebUI.TTextBox=Class.extend(Prado.WebUI.PostBackControl,{onInit:function(options)
{this.options=options;if(options['TextMode']!='MultiLine')
Event.observe(this.element,"keydown",this.handleReturnKey.bind(this));if(this.options['AutoPostBack']==true)
Event.observe(this.element,"change",Prado.PostBack.bindEvent(this,options));},handleReturnKey:function(e)
diff --git a/framework/Web/Javascripts/js/compressed/validator.js b/framework/Web/Javascripts/js/compressed/validator.js
index 95081d50..a3b3f1cd 100644
--- a/framework/Web/Javascripts/js/compressed/validator.js
+++ b/framework/Web/Javascripts/js/compressed/validator.js
@@ -51,8 +51,9 @@ this.groups.push(validator.group);},addSummary:function(summary)
{var inGroup=group&&summary.group==group;var noGroup=!group&&!summary.group;if(inGroup||noGroup)
summary.updateSummary(validators,refresh);else
summary.hideSummary(true);});}};Prado.WebUI.TValidationSummary=Class.create();Prado.WebUI.TValidationSummary.prototype={initialize:function(options)
-{this.options=options;this.group=options.ValidationGroup;this.messages=$(options.ID);this.visible=this.messages.style.visibility!="hidden"
-this.visible=this.visible&&this.messages.style.display!="none";Prado.Validation.addSummary(options.FormID,this);},updateSummary:function(validators,update)
+{this.options=options;this.group=options.ValidationGroup;this.messages=$(options.ID);if(this.messages)
+{this.visible=this.messages.style.visibility!="hidden"
+this.visible=this.visible&&this.messages.style.display!="none";Prado.Validation.addSummary(options.FormID,this);}},updateSummary:function(validators,update)
{if(validators.length<=0)
{if(update||this.options.Refresh!=false)
{return this.hideSummary(validators);}
@@ -86,7 +87,8 @@ this.messages.show();this.visible=true;},formats:function(type)
{switch(this.options.DisplayMode)
{case"List":output+=messages[i]+"\n";break;case"BulletList":default:output+=" - "+messages[i]+"\n";break;case"SingleParagraph":output+=messages[i]+" ";break;}}
return output;}};Prado.WebUI.TBaseValidator=Class.create();Prado.WebUI.TBaseValidator.prototype={initialize:function(options)
-{this.enabled=true;this.visible=false;this.isValid=true;this._isObserving={};this.group=null;this.requestDispatched=false;this.options=options;this.control=$(options.ControlToValidate);this.message=$(options.ID);this.group=options.ValidationGroup;this.manager=Prado.Validation.addValidator(options.FormID,this);},getErrorMessage:function()
+{this.enabled=true;this.visible=false;this.isValid=true;this._isObserving={};this.group=null;this.requestDispatched=false;this.options=options;this.control=$(options.ControlToValidate);this.message=$(options.ID);if(this.control&&this.message)
+{this.group=options.ValidationGroup;this.manager=Prado.Validation.addValidator(options.FormID,this);}},getErrorMessage:function()
{return this.options.ErrorMessage;},updateControl:function(focus)
{this.refreshControlAndMessage();if(this.options.FocusOnError&&!this.isValid)
Prado.Element.focus(this.options.FocusElementID);this.visible=true;},refreshControlAndMessage:function()
diff --git a/framework/Web/Javascripts/js/debug/ajax.js b/framework/Web/Javascripts/js/debug/ajax.js
index 9b1046ba..def73994 100644
--- a/framework/Web/Javascripts/js/debug/ajax.js
+++ b/framework/Web/Javascripts/js/debug/ajax.js
@@ -2308,8 +2308,11 @@ Prado.WebUI.ActiveListControl = Base.extend(
constructor : function(options)
{
this.element = $(options.ID);
- this.options = options;
- Event.observe(this.element, "change", this.doCallback.bind(this));
+ if(this.element)
+ {
+ this.options = options;
+ Event.observe(this.element, "change", this.doCallback.bind(this));
+ }
},
doCallback : function(event)
diff --git a/framework/Web/Javascripts/js/debug/prado.js b/framework/Web/Javascripts/js/debug/prado.js
index a1a224b9..08c7e428 100644
--- a/framework/Web/Javascripts/js/debug/prado.js
+++ b/framework/Web/Javascripts/js/debug/prado.js
@@ -3264,8 +3264,11 @@ Prado.WebUI.PostBackControl.prototype =
this._elementOnClick = null, //capture the element's onclick function
this.element = $(options.ID);
- if(this.onInit)
- this.onInit(options);
+ if(this.element)
+ {
+ if(this.onInit)
+ this.onInit(options);
+ }
},
onInit : function(options)
@@ -3382,8 +3385,11 @@ Object.extend(Prado.WebUI.TRadioButton.prototype,
initialize : function(options)
{
this.element = $(options['ID']);
- if(!this.element.checked)
- this.onRadioButtonInitialize(options);
+ if(this.element)
+ {
+ if(!this.element.checked)
+ this.onRadioButtonInitialize(options);
+ }
}
});
diff --git a/framework/Web/Javascripts/js/debug/validator.js b/framework/Web/Javascripts/js/debug/validator.js
index f3a37d0f..39ef9d63 100644
--- a/framework/Web/Javascripts/js/debug/validator.js
+++ b/framework/Web/Javascripts/js/debug/validator.js
@@ -376,9 +376,12 @@ Prado.WebUI.TValidationSummary.prototype =
this.options = options;
this.group = options.ValidationGroup;
this.messages = $(options.ID);
- this.visible = this.messages.style.visibility != "hidden"
- this.visible = this.visible && this.messages.style.display != "none";
- Prado.Validation.addSummary(options.FormID, this);
+ if(this.messages)
+ {
+ this.visible = this.messages.style.visibility != "hidden"
+ this.visible = this.visible && this.messages.style.display != "none";
+ Prado.Validation.addSummary(options.FormID, this);
+ }
},
/**
@@ -589,13 +592,16 @@ Prado.WebUI.TBaseValidator.prototype =
this._isObserving = {};
this.group = null;
this.requestDispatched = false;
-
+
this.options = options;
this.control = $(options.ControlToValidate);
this.message = $(options.ID);
- this.group = options.ValidationGroup;
+ if(this.control && this.message)
+ {
+ this.group = options.ValidationGroup;
- this.manager = Prado.Validation.addValidator(options.FormID, this);
+ this.manager = Prado.Validation.addValidator(options.FormID, this);
+ }
},
/**
diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js
index ecdc94cb..bb61d8ea 100644
--- a/framework/Web/Javascripts/prado/activecontrols3.js
+++ b/framework/Web/Javascripts/prado/activecontrols3.js
@@ -200,8 +200,11 @@ Prado.WebUI.ActiveListControl = Base.extend(
constructor : function(options)
{
this.element = $(options.ID);
- this.options = options;
- Event.observe(this.element, "change", this.doCallback.bind(this));
+ if(this.element)
+ {
+ this.options = options;
+ Event.observe(this.element, "change", this.doCallback.bind(this));
+ }
},
doCallback : function(event)
diff --git a/framework/Web/Javascripts/prado/controls.js b/framework/Web/Javascripts/prado/controls.js
index 390b1a25..2127732d 100644
--- a/framework/Web/Javascripts/prado/controls.js
+++ b/framework/Web/Javascripts/prado/controls.js
@@ -9,8 +9,11 @@ Prado.WebUI.PostBackControl.prototype =
this._elementOnClick = null, //capture the element's onclick function
this.element = $(options.ID);
- if(this.onInit)
- this.onInit(options);
+ if(this.element)
+ {
+ if(this.onInit)
+ this.onInit(options);
+ }
},
onInit : function(options)
@@ -127,8 +130,11 @@ Object.extend(Prado.WebUI.TRadioButton.prototype,
initialize : function(options)
{
this.element = $(options['ID']);
- if(!this.element.checked)
- this.onRadioButtonInitialize(options);
+ if(this.element)
+ {
+ if(!this.element.checked)
+ this.onRadioButtonInitialize(options);
+ }
}
});
diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js
index b1734452..4158369f 100644
--- a/framework/Web/Javascripts/prado/validation3.js
+++ b/framework/Web/Javascripts/prado/validation3.js
@@ -376,9 +376,12 @@ Prado.WebUI.TValidationSummary.prototype =
this.options = options;
this.group = options.ValidationGroup;
this.messages = $(options.ID);
- this.visible = this.messages.style.visibility != "hidden"
- this.visible = this.visible && this.messages.style.display != "none";
- Prado.Validation.addSummary(options.FormID, this);
+ if(this.messages)
+ {
+ this.visible = this.messages.style.visibility != "hidden"
+ this.visible = this.visible && this.messages.style.display != "none";
+ Prado.Validation.addSummary(options.FormID, this);
+ }
},
/**
@@ -589,13 +592,16 @@ Prado.WebUI.TBaseValidator.prototype =
this._isObserving = {};
this.group = null;
this.requestDispatched = false;
-
+
this.options = options;
this.control = $(options.ControlToValidate);
this.message = $(options.ID);
- this.group = options.ValidationGroup;
+ if(this.control && this.message)
+ {
+ this.group = options.ValidationGroup;
- this.manager = Prado.Validation.addValidator(options.FormID, this);
+ this.manager = Prado.Validation.addValidator(options.FormID, this);
+ }
},
/**
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
index 8ea196f9..af3cdd4d 100644
--- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
@@ -15,6 +15,7 @@
* Load callback response adapter class.
*/
Prado::using('System.Web.UI.ActiveControls.TCallbackResponseAdapter');
+Prado::using('System.Web.UI.ActiveControls.TCallbackClientScript');
/**
* TActivePageAdapter class.
@@ -155,7 +156,7 @@ class TActivePageAdapter extends TControlAdapter
if(!is_null($responseData))
{
$data = TJavascript::jsonEncode($responseData);
-
+
$this->appendContentPart($response, self::CALLBACK_DATA_HEADER, $data);
//$response->appendHeader(self::CALLBACK_DATA_HEADER.': '.$data);
}
@@ -192,7 +193,7 @@ class TActivePageAdapter extends TControlAdapter
/**
* Appends data or javascript code to the body content surrounded with delimiters
- */
+ */
private function appendContentPart($response, $delimiter, $data)
{
$content = $response->createHtmlWriter();