$s .= '/';
$s .= strtolower( $folder );
}
- require_once($s.'.php');
+ require_once($s.'.php');
}
final class IPF{
IPF::$settings['app_base'] = '/index.php';
}
+ if (!isset(IPF::$settings['append_slash'])){
+ IPF::$settings['append_slash'] = true;
+ }
+
if (!isset(IPF::$settings['media_url'])){
IPF::$settings['media_url'] = '/media/';
}
array_pop($elts);
$file = strtolower(implode(DIRECTORY_SEPARATOR, $elts)).'.php';
@include $file;
-
if (!function_exists($function))
throw new IPF_Exception('Impossible to load the function: '.$function.' in '.$file);
}
.change-list ul.toplinks li { float: left; width: 9em; padding:3px 6px; font-weight: bold; list-style-type:none; }
.change-list ul.toplinks .date-back a { color:#999; }
.change-list ul.toplinks .date-back a:hover { color:#036; }
+
+/* INLINE TABULAR */
+fieldset.inlineTabular {margin-top:5px; padding-top:5px;}
+fieldset.inlineTabular legend{font-size:11pt; color:#888;}
+fieldset.inlineTabular table{width:auto;}
+fieldset.inlineTabular table th{font-weight:bold; color:#666; padding:2px 5px; font-size:11px; background:url(../img/hbg.gif) top left repeat-x; border:1px solid #ABB0BE;}
+fieldset.inlineTabular table td{border:1px solid #DDD;}
input[type=submit]:active, input[type=button]:active { background-image:url(../img/nav-bg.gif); background-position:bottom; }
input[type=submit].default, .submit-row input.default { border:2px solid #888; background: url(../img/hbg.gif) center repeat-x; font-weight:bold; color:#888; }
input[type=submit].default:active { background-image:url(../img/default-bg-reverse.gif); background-position:top; }
+
+a.button { background:white url(../img/nav-bg.gif) bottom repeat-x; padding:2px; color:black; }
+
.submit-row { padding:5px 7px; text-align:right; background:url(../img/topbg.gif) top left repeat-x; border:1px solid #ABB0BE; margin:5px 0; }
.submit-row input { margin:0 0 0 5px; }
.submit-row .float-left { padding-top:.1em; }
class IPF_Admin_Model{
static $models = array();
+
public static function register($classModel, $classAdmin){
IPF_Admin_Model::$models[$classModel] = new $classAdmin($classModel);
}
}
public static function getModelAdmin($classModel){
- if (array_key_exists($classModel, IPF_Admin_Model::$models))
- return IPF_Admin_Model::$models[$classModel];
+ if (array_key_exists($classModel, IPF_Admin_Model::$models)){
+ $ma = IPF_Admin_Model::$models[$classModel];
+ $ma->setUp();
+ return $ma;
+ }
return null;
}
var $modelName = null;
-
+ var $model = null;
+ var $inlineInstances = array();
+
public function __construct($modelName){
$this->modelName = $modelName;
}
+ public function setUp(){
+ $this->model = new $this->modelName;
+ }
+
+ protected function setInlines(&$instance=null){
+ $il = $this->inlines();
+ if (is_array($il)){
+ foreach($il as $inlineName=>$inlineClassName){
+ $this->inlineInstances[] = new $inlineClassName(&$this->model,&$instance);
+ }
+ }
+ }
+
protected function _setupEditForm(&$form){
$this->_setupForm(&$form);
+ $this->setInlines($this->instance);
}
protected function _setupAddForm(&$form){
$this->_setupForm(&$form);
+ $this->setInlines();
}
protected function _setupForm(&$form){
}
- public function fields(){
- return null;
+ public function fields(){return null;}
+
+ public function inlines(){return null;}
+
+ public function isValidInlines(){
+ if ($this->inlineInstances==null)
+ return true;
+ foreach($this->inlineInstances as &$il){
+ if ($il->isValid()===false)
+ return false;
+ }
+ return true;
}
public function ListItemsHeader(){
// Views Function
public function AddItem($request, $lapp, $lmodel){
- $model = new $this->modelName();
if ($request->method == 'POST'){
- $form = IPF_Shortcuts::GetFormForModel($model,$request->POST+$request->FILES,array('user_fields'=>$this->fields()));
+ $form = IPF_Shortcuts::GetFormForModel($this->model,$request->POST+$request->FILES,array('user_fields'=>$this->fields()));
$this->_setupAddForm(&$form);
if ($form->isValid()) {
$item = $form->save();
}
}
else{
- $form = IPF_Shortcuts::GetFormForModel($model,null,array('user_fields'=>$this->fields()));
+ $form = IPF_Shortcuts::GetFormForModel($this->model,null,array('user_fields'=>$this->fields()));
$this->_setupAddForm(&$form);
-
}
$context = array(
'page_title'=>'Add '.$this->modelName,
if ($request->method == 'POST'){
$form = IPF_Shortcuts::GetFormForModel($o,$request->POST+$request->FILES,array('user_fields'=>$this->fields()));
$this->_setupEditForm(&$form);
- if ($form->isValid()) {
+ if ( ($form->isValid()) && ($this->isValidInlines()) ) {
$item = $form->save();
AdminLog::logAction($request, $item, AdminLog::CHANGE);
$url = IPF_HTTP_URL_urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
else{
$form = IPF_Shortcuts::GetFormForModel($o,$o->getData(),array('user_fields'=>$this->fields()));
$this->_setupEditForm(&$form);
- $dd = $o->getData();
}
+
$context = array(
'page_title'=>'Edit '.$this->modelName,
'classname'=>$this->modelName,
'object'=>$o,
'form'=>$form,
+ 'inlineInstances'=>$this->inlineInstances,
'lapp'=>$lapp,
'lmodel'=>$lmodel,
);
'page_title'=>'Delete '.$this->modelName,
'classname'=>$this->modelName,
'object'=>$o,
- 'form'=>$form,
'lapp'=>$lapp,
'lmodel'=>$lmodel,
'affected'=>array(),
--- /dev/null
+<?php
+
+abstract class IPF_Admin_ModelInline{
+
+ var $model = null;
+ var $parentModel = null;
+ var $formset = null;
+ var $parentInstance = null;
+
+ function __construct(&$parentModel,$parentInstance=null){
+ $this->parentModel = $parentModel;
+ $this->parentInstance = $parentInstance;
+
+ $modelName = $this->getModelName();
+ $this->model = new $modelName();
+
+ $this->createFormSet();
+ }
+
+ abstract function getModelName();
+
+ function getAddNum(){ return 2; }
+
+ function getLegend(){
+ return get_class($this->model);
+ }
+
+ function isValid(){
+ foreach($this->formset as &$form){
+ if ($form->isValid()==false){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function getFkName(){
+ foreach($this->model->getTable()->getRelations() as $rel){
+ if ($rel->getClass()==get_class($this->parentModel))
+ return $rel->getAlias();
+ }
+ throw new IPF_Exception('Cannot get fkName for '.$this->getModelName());
+ }
+
+ function getFkLocal(){
+ foreach($this->model->getTable()->getRelations() as $rel){
+ if ($rel->getClass()==get_class($this->parentModel))
+ return $rel->getLocal();
+ }
+ throw new IPF_Exception('Cannot get fkLocal for '.$this->getModelName());
+ }
+
+ function createFormSet(){
+ $this->formset = array();
+ for($i=0; $i<$this->getAddNum(); $i++ ){
+ $form = IPF_Shortcuts::GetFormForModel($this->model, null, array('exclude'=>array($this->getFkName(),$this->getFkLocal())));
+ $form->prefix = "add-$i";
+ if ($i==0)
+ $form->isFirst = true;
+ else
+ $form->isFirst = false;
+ //print_r($form->fields);
+ $this->formset[] = $form;
+ }
+ }
+}
\ No newline at end of file
<div id="ipfcontent">
<h1>{$page_title}</h1>
- <form method="post" {if $form.hasFileField() }enctype="multipart/form-data"{/if}>
+ <form method="post" {if $form.hasFileField()}enctype="multipart/form-data"{/if}>
<fieldset>
<table>
{$form.render_table}
</table>
</fieldset>
+ {foreach $inlineInstances as $inline}
+ <fieldset class="inlineTabular">
+ <legend>{$inline->getLegend()}</legend>
+ <table>
+ {foreach $inline.formset as $formset}
+ {if $formset.isFirst}
+ <tr>
+ {foreach $formset.fields as $fieldname=>$field}
+ <th>{$formset.field($fieldname).labelTag()|safe}</th>
+ {/foreach}
+ </tr>
+ {/if}
+ <tr>
+ {foreach $formset.fields as $fieldname=>$field}
+ <td>{$formset.field($fieldname)|safe}</td>
+ {/foreach}
+ </tr>
+ {/foreach}
+ </table>
+ </fieldset>
+ {/foreach}
<div class="submit-row">
<p class="float-left"><a href="{url 'IPF_Admin_Views_DeleteItem', array($lapp, $lmodel, $object.id)}" class="deletelink">Delete</a></p>
{extends 'admin/base-simple.html'}
{block body}
-
<div style="text-align:center; margin-top:100px;">
<div style="margin-left:auto;margin-right:auto; width:300px; text-align:left;">
<h1>{$page_title}</h1>
}
public function AddItem($request, $lapp, $lmodel){
- $model = new $this->modelName();
if ($request->method == 'POST'){
$form = new IPF_Auth_Forms_UserCreation($request->POST);
if ($form->isValid()) {
$form->cleaned_data['is_staff'],
$form->cleaned_data['is_superuser']
);
+ AdminLog::logAction($request, $user, AdminLog::ADDITION);
$url = IPF_HTTP_URL_urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
return new IPF_HTTP_Response_Redirect($url);
}
public function field($key)
{
return new IPF_Form_BoundField($this, $this->fields[$key], $key);
-
}
public function current()
$db_columns = $this->model->getTable()->getColumns();
$db_relations = $this->model->getTable()->getRelations();
-
if ($user_fields===null){
+
+ if (isset($extra['exclude']))
+ $exclude = $extra['exclude'];
+ else
+ $exclude = array();
+
foreach($db_columns as $name=>$col){
+ if (array_search($name,$exclude)!==false)
+ continue;
$this->addDBField($name,$col);
}
foreach($db_relations as $name => $relation){
+ if (array_search($name,$exclude)!==false)
+ continue;
$this->addDBRelation($name,$relation);
}
}
//echo $name;
//print_r($defaults);
-
-
if (null !== ($form_field=$db_field->formField($defaults))) {
$this->fields[$name] = $form_field;
$this->uri = $_SERVER['REQUEST_URI'];
$this->remote_addr = $_SERVER['REMOTE_ADDR'];
$this->http_host = $_SERVER['HTTP_HOST'];
+ if (isset($_SERVER['PATH_INFO']))
+ $this->path_info = $_SERVER['PATH_INFO'];
+ else
+ $this->path_info = '/';
+
$this->SERVER =& $_SERVER;
}
+
+ function isSecure(){
+ return false; // # FIXME
+ }
+
+ function addUrlrotocol($uri){
+ if ($this->isSecure())
+ $proto = 'https';
+ else
+ $proto = 'http';
+ return $proto.'://'.$uri;
+ }
}
$className = $e[0];
if ($modelLoading == IPF_ORM::MODEL_LOADING_CONSERVATIVE) {
self::loadModel($className, $file->getPathName());
-
$loadedModels[$className] = $className;
} else {
//$declaredBefore = get_declared_classes();
require_once($file->getPathName());
$loadedModels[$className] = $className; // !!!
-
/*
//$declaredAfter = get_declared_classes();
//$foundClasses = array_slice($declaredAfter, count($declaredBefore) - 1);