Permalink
Browse files

Rename 'form_body' into 'Content'

IMPORTANT - projects should no longer use
$form->add('H2',null,'form_body')

instead use

$form->add('H2')
  • Loading branch information...
1 parent c89aecd commit 7ec46af5261da0d01f172d39a7ec966a53f04bee @romaninsh romaninsh committed Apr 3, 2011
View
@@ -22,6 +22,7 @@
http://www.atk4.com/commercial/
*****************************************************ATK4**/
+// Field bundle
include_once'Form/Field.php';
/**
* This class implements generic form, which you can actually use without
@@ -31,7 +32,7 @@
* @copyright See file COPYING
* @version $Id$
*/
-class Form extends AbstractView {
+class Form_Basic extends AbstractView {
@jancha
jancha Apr 6, 2011 Agile Toolkit member

Cool. So, what this imply is that Form.php is gone? So, if we have Form_Custom which extends Form - what will happen?

@jancha
jancha via email Apr 6, 2011 Agile Toolkit member
@romaninsh
romaninsh Apr 6, 2011 Agile Toolkit member

This change is transparent. Form is still there, it inherits Form_Basic, so there are no impact on any functionality. I am doing those moves in two steps because if i rename the file and change it at the same time, Github treats it as a new file. This way history is preserved.

http://agiletoolkit.org/whatsnew - is a summary of all other changes.

NOTE: those changes are done to "development" branch, it's not affecting stable branch.

protected $form_template = null;
protected $form_tag = null;
public $errors=array();
@@ -87,15 +88,15 @@ protected function getChunks(){
if($this->template->is_set('hidden_form_line'))
$this->grabTemplateChunk('hidden_form_line');
$this->grabTemplateChunk('field_error'); // template for error code, must contain field_error_str
- //$this->grabTemplateChunk('form'); // template for whole form, must contain form_body, form_buttons, form_action,
+ //$this->grabTemplateChunk('form'); // template for whole form, must contain Content, form_buttons, form_action,
// and form_name
$this->grabTemplateChunk('field_mandatory'); // template for marking mandatory fields
// ok, other grabbing will be done by field themselves as you will add them to the form.
// They will try to look into this template, and if you don't have apropriate templates
// for them, they will use default ones.
$this->template_chunks['form']=$this->template;
- $this->template_chunks['form']->del('form_body');
+ $this->template_chunks['form']->del('Content');
$this->template_chunks['form']->del('form_buttons');
$this->template_chunks['form']->set('form_name',$this->name);
return $this;
@@ -129,15 +130,23 @@ function grabTemplateChunk($name){
* @param string $msg message to show
*/
function showAjaxError($field,$msg){
- //$this->ajax()->displayAlert(strip_tags($msg))->execute();
+ // Depreciated
+ return $this->displayFieldError();
+ }
+
+ function displayError($field=null,$msg=null){
+ if(!$field){
+ // Field is not defined
+ // TODO: add support for error in template
+ $this->js()->univ()->alert($msg?$msg:'Error in form')->execute();
+ }
if(!is_object($field))$field=$this->getElement($field);
$this->js()->atk4_form('fieldError',$field->short_name,$msg)->execute();
}
-
function addField($type,$name,$caption=null,$attr=null){
if($caption===null)$caption=ucwords(str_replace('_',' ',$name));
- $last_field=$this->add('Form_Field_'.$type,$name,'form_body','form_line')
+ $last_field=$this->add('Form_Field_'.$type,$name,null,'form_line')
->setCaption($caption);
$last_field->template->trySet('field_type',$type);
if (is_array($attr)){
@@ -169,7 +178,7 @@ function setFormat($format,$separator='-'){
*/
function addComment($comment){
if(!isset($this->template_chunks['form_comment']))throw new BaseException('This form\'s template ('.$this->template->loaded_template.') does not support comments');
- return $this->add('Text','c'.count($this->elements),'form_body')->set(
+ return $this->add('Text')->set(
$this->template_chunks['form_comment']->set('comment',$comment)->render()
);
}
@@ -178,7 +187,7 @@ function addSeparator($separator_text=''){
$c=clone $this->template_chunks['form_separator'];
if(!$separator_text)$c->tryDel('separator');else $c->trySet('separator_text',$separator_text);
- return $this->add('Text',null,'form_body')->set($c->render());
+ return $this->add('Text')->set($c->render());
}
// Operating with field values
@@ -373,7 +382,7 @@ function isSubmitted(){
return $result;
}
function setLayout($template){
- // Instead of building our own form_body we will take it from
+ // Instead of building our own Content we will take it from
// pre-defined template and insert fields into there
$this->template_chunks['custom_layout']=$this->add('SMLite')->loadTemplate($template);
$this->template_chunks['custom_layout']->trySet('_name',$this->name);
@@ -385,7 +394,7 @@ function setFormClass($class){
return $this;
}
function render(){
- // Assuming, that child fields already inserted their HTML code into 'form'/form_body using 'form_line'
+ // Assuming, that child fields already inserted their HTML code into 'form'/Content using 'form_line'
// Assuming, that child buttons already inserted their HTML code into 'form'/form_buttons
if($this->js_widget){
@@ -412,7 +421,7 @@ function render(){
}
}
}
- $this->template->set('form_body',$this->template_chunks['custom_layout']->render());
+ $this->template->set('Content',$this->template_chunks['custom_layout']->render());
}
$this->template_chunks['form']
->set('form_action',$this->api->getDestinationURL(null,array('submit'=>$this->name)));
View
@@ -71,15 +71,13 @@ function setCaption($_caption){
}
function displayFieldError($msg=null){
if(!isset($msg))$msg='Error in field "'.$this->caption.'"';
- if($this->api->isAjaxOutput()){
- $this->error_message=$msg;
- $this->showAjaxError($msg);
- }
+
+ $this->owner->js(true)
+ ->atk4_form('fieldError',$this->short_name,$msg)
+ ->execute();
+
$this->owner->errors[$this->short_name]=$msg;
}
- function showAjaxError($msg){
- $this->owner->showAjaxError($this,$msg);
- }
function setNoSave(){
// Field value will not be saved into defined source (such as database)
$this->no_save=true;
@@ -391,7 +389,7 @@ function getInput($attr=array()){
function render(){
$this->template = $this->owner->template_chunks['hidden_form_line'];
$this->template->set('hidden_field_input',$this->getInput());
- $this->owner->template_chunks['form']->append('form_body',$this->template->render());
+ $this->owner->template_chunks['form']->append('Content',$this->template->render());
}
}
@@ -3,7 +3,7 @@
<?$hint?>
<form class="<?$form_internal_class?>" id="<?$form_name?>" name="<?$form_name?>" action="<?$form_action?>" method="POST" <?$enctype?>>
<fieldset>
- <?form_body?>
+ <?Content?>
<?form_line?>
<dl class="atk-field atk-field-<?$field_type?> <?$field_container_class?>">
<dt><label for="<?$field_name?>" <?field_mandatory?>class="mandatory"<?/?>><?$field_caption?></label></dt>
@@ -25,7 +25,7 @@
- <?/form_body?>
+ <?/Content?>
<dd style="display:none" class="field-error-template atk-form-error">
<i class="ui-icon ui-icon-alert"></i><span class="field-error-text">Sample Error</span>
@@ -3,7 +3,7 @@
<form id="<?$_name?>" class="atk4" name="<?$form_name?>" action="<?$form_action?>" method="POST" <?$enctype?>>
<fieldset>
- <?form_body?>
+ <?Content?>
<?form_line?>
<dl>
<dt><label for="<?$field_name?>" <?field_mandatory?>class="mandatory"<?/?>><?$field_caption?></label></dt>
@@ -21,7 +21,7 @@
<fieldset>
<?separator?>Personal information<?/?><?/form_separator?>
<?form_comment?><?$comment?><?/?>
- <?/form_body?>
+ <?/Content?>
</fieldset>
<dl class="atk-form-buttons">
@@ -7,7 +7,7 @@
<!--
<?form_error?><dl><dd><span style="color:red; font-size: 200%"><?form_error_str?>Error on form!!<?/?></span></dd></dl><?/?>
-->
- <?form_body?>
+ <?Content?>
<?form_line?>
<!-- <?$field_caption?> -->
<label><?$field_caption?></label><?$before_field?><?field_input?><span class="form_field"><input type="text"
@@ -17,7 +17,7 @@
<?form_separator?>
<?separator?>Personal information<?/?><?/form_separator?>
- <?/form_body?>
+ <?/Content?>
<?form_buttons?>
<input type="button" value="Save" class="gbutton button_style1" />
<?/form_buttons?>
@@ -3,7 +3,7 @@
<?$hint?>
<form class="<?$form_internal_class?>" id="<?$form_name?>" name="<?$form_name?>" action="<?$form_action?>" method="POST" <?$enctype?>>
<fieldset class="atk-form-<?form_class?>basic<?/?> ">
- <?form_body?>
+ <?Content?>
<?form_line?>
<dl class="atk-field atk-field-<?$field_type?>">
<dt><label for="<?$field_name?>" <?field_mandatory?>class="mandatory"<?/?>><?$field_caption?></label></dt>
@@ -21,7 +21,7 @@
<fieldset class="atk-form-<?separator_text?>basic<?/?> ">
<?/form_separator?>
- <?/form_body?>
+ <?/Content?>
<dd style="display:none" class="field-error-template atk-form-error field-error-text">
<i class="ui-icon ui-icon-alert"></i>Sample Error
@@ -1,74 +0,0 @@
-<?form?>
- <form id="<?$form_name?>" name="<?$form_name?>" action="<?$form_action?>" onsubmit="<?form_onsubmit?>spinner_on('<?$form_name?>_loading')<?/?>" method="POST" <?$enctype?>>
- <table width="100%" border="0">
- <tr>
- <?section_open?>
- <!-- opening DIV: opening new cell and creating a table there -->
- <td valign="top" <?SeparatorStyle?>style="border-left: solid black 1px;"<?/SeparatorStyle?>>
- <table border="0">
- <?/?>
- <?form_body?>
- <?form_line?>
- <tr style="vertical-align: middle;">
- <td class="smalltext" align="right" nowrap style="padding-left: 20px;"><?field_caption?>Email:<?/?></td>
- <td><?field_input?><input type="text" name="loginemail" class="logintext" value=""><?/?>
- <?field_error?><br><font color="red">^ <?field_error_str?>Error<?/?></font><?/?></td>
- <td style="padding-right: 20px;"><font color="gray"><?field_comment?>&nbsp;<?/field_comment?></font></td>
- </tr>
- <?/form_line?>
- <?form_separator?>
- <tr valign="top"><td colspan="2" align="left" nowrap style="padding-left: 70px">
- <u><?$separator?></u></td></tr>
- <?/form_separator?>
- <?form_comment?>
- <tr><td colspan="3" valign="top" align="left" nowrap style="padding-left: 0px; padding-right: 8px; padding-bottom: 16px;"><font size="3"><?$comment?></font></td></tr>
- <?/form_comment?>
- <?hidden_form_line?>
- <?hidden_field_input?> <?/?>
- <?/hidden_form_line?>
- <tr>
- <td class="smalltext">Ticket Key:</td>
- <td><input type="password" name="loginpassword" class="loginpassword" value=""></td>
- </tr>
- <tr>
- <td class="smalltext">Remember Me:</td>
- <td><input type="checkbox" name="rememberme" value="1"></td>
- </tr>
- <?/form_body?>
- <?section_close?>
- <!-- closing DIV: closing table and cell -->
- </table>
- </td>
- <?/?>
- </tr>
- <tr>
- <td colspan="<?$section_count?>"><hr></td>
- </tr>
- <tr>
- <td colspan="<?$section_count?>">
- <table width="100%" cellspacing="0" cellpadding="0" border="0">
- <tr>
- <td class="left" width="100%">&nbsp;<img id="<?$form_name?>_loading" src="amodules3/img/not_loading.gif" border="0">
- <!-- chk_preload -->
- <div style="display:none;"><img src="amodules3/img/loading.gif" /></div>
- <!-- -------------->
- </td>
- <td align="center" style="text-align: center;"><b id="msg_<?$form_id?>"></b>
- </td>
- <td id="<?$form_name?>_buttons" name="<?$form_name?>_buttons" align="right" nowrap>
- <?form_buttons?>
- <input type="submit" name="Submit2" value="Login" class="yellowbutton">
- <?/form_buttons?>
- </td>
- <td>
- <?form_ebuttons?>
- <?/form_ebuttons?>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </form>
- <script><?$form_onload?></script>
-<?/form?>

0 comments on commit 7ec46af

Please sign in to comment.