[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [10294] Logistic: Added validation
From: |
Torstein |
Subject: |
[Fmsystem-commits] [10294] Logistic: Added validation |
Date: |
Mon, 22 Oct 2012 11:46:14 +0000 |
Revision: 10294
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10294
Author: vator
Date: 2012-10-22 11:46:13 +0000 (Mon, 22 Oct 2012)
Log Message:
-----------
Logistic: Added validation
Modified Paths:
--------------
trunk/logistic/inc/class.uiproject.inc.php
trunk/logistic/inc/class.uirequirement.inc.php
trunk/logistic/inc/model/class.project.inc.php
trunk/logistic/templates/base/project/project_item.xsl
Modified: trunk/logistic/inc/class.uiproject.inc.php
===================================================================
--- trunk/logistic/inc/class.uiproject.inc.php 2012-10-22 11:18:36 UTC (rev
10293)
+++ trunk/logistic/inc/class.uiproject.inc.php 2012-10-22 11:46:13 UTC (rev
10294)
@@ -45,7 +45,8 @@
'edit_project_type' => true,
'edit_project_type_name' => true,
'add' => true,
- 'edit' => true
+ 'edit' => true,
+ 'save' => true
);
public function __construct()
@@ -356,12 +357,6 @@
$project_array = $project->toArray();
- if ($this->flash_msgs)
- {
- $msgbox_data =
$GLOBALS['phpgw']->common->msgbox_data($this->flash_msgs);
- $msgbox_data =
$GLOBALS['phpgw']->common->msgbox($msgbox_data);
- }
-
$data = array
(
'value_id' => !empty($project) ?
$project->get_id() : 0,
@@ -399,7 +394,6 @@
$data = array
(
'value_id' => !empty($project) ?
$project->get_id() : 0,
- 'img_go_home' =>
'rental/templates/base/images/32x32/actions/go-home.png',
'project' => $project
);
@@ -486,7 +480,7 @@
$GLOBALS['phpgw']->redirect_link('/index.php',
array('menuaction' => 'logistic.uiproject.edit'));
}
- public function edit()
+ public function edit($project)
{
$project_id = phpgw::get_var('id');
if ($project_id && is_numeric($project_id))
@@ -495,47 +489,57 @@
}
else
{
- $project = new logistic_project();
+ if($project == null)
+ {
+ $project = new logistic_project();
+ }
}
- if (isset($_POST['save_project']))
+ $project_types = $this->so->get_project_types();
+ foreach ($project_types as &$p_type)
{
- $project->set_name(phpgw::get_var('name'));
-
$project->set_project_type_id(phpgw::get_var('project_type_id'));
-
$project->set_description(phpgw::get_var('description'));
+ if ($project->get_project_type_id() ==
$p_type['id'])
+ {
+ $p_type['selected'] = 1;
+ }
+ }
+
+ $data = array
+ (
+ 'project' => $project,
+ 'options' => $project_types,
+ 'editable' => true
+ );
- $project_id = $this->so->store($project);
- $GLOBALS['phpgw']->redirect_link('/index.php',
array('menuaction' => 'logistic.uiproject.view', 'id' => $project_id));
+ $this->use_yui_editor('description');
+ $GLOBALS['phpgw_info']['flags']['app_header'] =
lang('logistic') . '::' . lang('Project type');
+
self::render_template_xsl(array('project/project_item'), $data);
+ }
+
+ public function save()
+ {
+ $project_id = phpgw::get_var('id');
+
+ if ($project_id && is_numeric($project_id))
+ {
+ $project = $this->so->get_single($project_id);
}
- else if (isset($_POST['cancel_project']))
+ else
{
- $GLOBALS['phpgw']->redirect_link('/index.php',
array('menuaction' => 'logistic.uiproject.view', 'id' => $project_id));
+ $project = new logistic_project();
}
+
+ $project->populate();
+
+ if( $project->validate() )
+ {
+ $project_id = $this->so->store($project);
+ $GLOBALS['phpgw']->redirect_link('/index.php',
array('menuaction' => 'logistic.uiproject.view', 'id' => $project_id));
+ }
else
{
- $project_types = $this->so->get_project_types();
- foreach ($project_types as &$p_type)
- {
- if ($project->get_project_type_id() ==
$p_type['id'])
- {
- $p_type['selected'] = 1;
- }
- }
- $project_array = $project->toArray();
-
- $data = array
- (
- 'value_id' => !empty($project) ?
$project->get_id() : 0,
- 'project' => $project_array,
- 'options' => $project_types,
- 'editable' => true
- );
-
- $this->use_yui_editor('description');
- $GLOBALS['phpgw_info']['flags']['app_header'] =
lang('logistic') . '::' . lang('Project type');
-
self::render_template_xsl(array('project/project_item'), $data);
+ $this->edit( $project );
}
}
-
}
Modified: trunk/logistic/inc/class.uirequirement.inc.php
===================================================================
--- trunk/logistic/inc/class.uirequirement.inc.php 2012-10-22 11:18:36 UTC
(rev 10293)
+++ trunk/logistic/inc/class.uirequirement.inc.php 2012-10-22 11:46:13 UTC
(rev 10294)
@@ -422,6 +422,7 @@
$this->edit($requirement);
}
}
+
public function add_requirement_values()
{
$requirement_id = phpgw::get_var('requirement_id');
Modified: trunk/logistic/inc/model/class.project.inc.php
===================================================================
--- trunk/logistic/inc/model/class.project.inc.php 2012-10-22 11:18:36 UTC
(rev 10293)
+++ trunk/logistic/inc/model/class.project.inc.php 2012-10-22 11:46:13 UTC
(rev 10294)
@@ -27,102 +27,146 @@
* @version $Id $
*/
- include_class('logistic', 'model', '/inc/model/');
+ include_class('logistic', 'model', '/inc/model/');
- class logistic_project extends logistic_model
- {
- public static $so;
+ class logistic_project extends logistic_model
+ {
+ public static $so;
- protected $id;
- protected $name;
- protected $project_type_id;
- protected $project_type_label;
- protected $description;
+ protected $id;
+ protected $name;
+ protected $project_type_id;
+ protected $project_type_label;
+ protected $description;
+
+ protected $error_msg_array = array();
- /**
- * Constructor. Takes an optional ID. If a
contract is created from outside
- * the database the ID should be empty so the
database can add one according to its logic.
- *
- * @param int $id the id of this project
- */
- public function __construct(int $id = null)
- {
- $this->id = (int)$id;
- }
+ /**
+ * Constructor. Takes an optional ID. If a contract is created
from outside
+ * the database the ID should be empty so the database can add
one according to its logic.
+ *
+ * @param int $id the id of this project
+ */
+ public function __construct(int $id = null)
+ {
+ $this->id = (int)$id;
+ }
- public function set_id($id)
- {
- $this->id = $id;
- }
+ public function set_id($id)
+ {
+ $this->id = $id;
+ }
- public function get_id()
- {
- return $this->id;
- }
+ public function get_id()
+ {
+ return $this->id;
+ }
- public function set_name($name)
- {
- $this->name = $name;
- }
+ public function set_name($name)
+ {
+ $this->name = $name;
+ }
- public function get_name()
- {
- return $this->name;
- }
+ public function get_name()
+ {
+ return $this->name;
+ }
- public function
set_project_type_id($project_type_id)
- {
- $this->project_type_id =
$project_type_id;
- }
+ public function set_project_type_id($project_type_id)
+ {
+ $this->project_type_id = $project_type_id;
+ }
- public function get_project_type_id()
- {
- return $this->project_type_id;
- }
+ public function get_project_type_id()
+ {
+ return $this->project_type_id;
+ }
- public function
set_project_type_label($project_type_label)
- {
- $this->project_type_label =
$project_type_label;
- }
+ public function set_project_type_label($project_type_label)
+ {
+ $this->project_type_label = $project_type_label;
+ }
- public function get_project_type_label()
- {
- return $this->project_type_label;
- }
+ public function get_project_type_label()
+ {
+ return $this->project_type_label;
+ }
- public function set_description($description)
- {
- $this->description = $description;
- }
+ public function set_description($description)
+ {
+ $this->description = $description;
+ }
- public function get_description()
- {
- return $this->description;
- }
+ public function get_description()
+ {
+ return $this->description;
+ }
+
+ public function get_error_msg_array() { return
$this->error_msg_array; }
+
+ public function set_error_msg_array( $error_msg_array )
+ {
+ $this->error_msg_array = $error_msg_array;
+ }
- /**
- * Get a static reference to the storage object
associated with this model object
- *
- * @return the storage object
- */
- public static function get_so()
- {
- if (self::$so == null) {
- self::$so =
CreateObject('logistic.soproject');
- }
+ /**
+ * Get a static reference to the storage object associated with
this model object
+ *
+ * @return the storage object
+ */
+ public static function get_so()
+ {
+ if (self::$so == null) {
+ self::$so = CreateObject('logistic.soproject');
+ }
- return self::$so;
- }
+ return self::$so;
+ }
- public function serialize()
- {
- return array(
- 'id' => $this->get_id(),
- 'name' => $this->get_name(),
- 'project_type_id' =>
$this->get_project_type_id(),
- 'project_type_label' =>
$this->get_project_type_label(),
- 'description' =>
$this->get_description()
- );
- }
+ public function serialize()
+ {
+ return array(
+ 'id' => $this->get_id(),
+ 'name' => $this->get_name(),
+ 'project_type_id' =>
$this->get_project_type_id(),
+ 'project_type_label' =>
$this->get_project_type_label(),
+ 'description' => $this->get_description()
+ );
}
-?>
+
+ public function populate()
+ {
+ $this->set_id( phpgw::get_var('id') );
+ $this->set_name( phpgw::get_var('name') );
+ $this->set_project_type_id(
phpgw::get_var('project_type_id') );
+ $this->set_description( phpgw::get_var('description')
);
+ }
+
+ public function validate()
+ {
+ $status = true;
+
+ // Validate NAME
+ if( empty($this->name) )
+ {
+ $status = false;
+ $this->error_msg_array['name'] = "error_msg_1";
+ }
+
+ // Validate DESCRIPTION
+ if( empty($this->description) )
+ {
+ $status = false;
+ $this->error_msg_array['description'] = "error_msg_1";
+ }
+
+ // Validate PROJECT TYPE ID
+ if( empty($this->project_type_id) )
+ {
+ $status = false;
+ $this->error_msg_array['project_type_id'] =
"error_msg_1";
+ }
+
+ return $status;
+ }
+ }
Modified: trunk/logistic/templates/base/project/project_item.xsl
===================================================================
--- trunk/logistic/templates/base/project/project_item.xsl 2012-10-22
11:18:36 UTC (rev 10293)
+++ trunk/logistic/templates/base/project/project_item.xsl 2012-10-22
11:46:13 UTC (rev 10294)
@@ -12,7 +12,10 @@
<div class="content-wrp">
<div id="details">
- <form action="#" method="post">
+ <xsl:variable name="action_url">
+ <xsl:value-of
select="php:function('get_phpgw_link', '/index.php',
'menuaction:logistic.uiproject.save')" />
+ </xsl:variable>
+ <form action="{$action_url}" method="post">
<input type="hidden" name="id" value =
"{value_id}">
</input>
<dl class="proplist-col">
@@ -22,7 +25,12 @@
<dd>
<xsl:choose>
<xsl:when test="editable">
+ <xsl:if
test="project/error_msg_array/name != ''">
+ <xsl:variable
name="error_msg"><xsl:value-of select="project/error_msg_array/name"
/></xsl:variable>
+ <div
class='input_error_msg'><xsl:value-of select="php:function('lang', $error_msg)"
/></div>
+ </xsl:if>
<input type="text"
name="name" id="name" value="{project/name}" size="100"/>
+ <span class="help_text
line">Angi startdato for aktiviteten</span>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="project/name" />
@@ -35,9 +43,14 @@
<dd>
<xsl:choose>
<xsl:when test="editable">
+ <xsl:if
test="project/error_msg_array/project_type_id != ''">
+ <xsl:variable
name="error_msg"><xsl:value-of select="project/error_msg_array/project_type_id"
/></xsl:variable>
+ <div
class='input_error_msg'><xsl:value-of select="php:function('lang', $error_msg)"
/></div>
+ </xsl:if>
<select
id="project_type_id" name="project_type_id">
<xsl:apply-templates select="options"/>
</select>
+ <span class="help_text
line">Angi startdato for aktiviteten</span>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="project/project_type_label" />
@@ -50,7 +63,12 @@
<dd>
<xsl:choose>
<xsl:when test="editable">
+ <xsl:if
test="project/error_msg_array/description != ''">
+ <xsl:variable
name="error_msg"><xsl:value-of select="project/error_msg_array/description"
/></xsl:variable>
+ <div
class='input_error_msg'><xsl:value-of select="php:function('lang', $error_msg)"
/></div>
+ </xsl:if>
<textarea
id="description" name="description" rows="5" cols="60"><xsl:value-of
select="project/description" disable-output-escaping="yes"/></textarea>
+ <span class="help_text
line">Angi startdato for aktiviteten</span>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="project/description" disable-output-escaping="yes"/>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [10294] Logistic: Added validation,
Torstein <=