Exemplo n.º 1
0
 public function __construct($dict = array())
 {
     if (!isset($dict['default'])) {
         $dict['default'] = '';
     }
     parent::__construct($dict);
 }
Exemplo n.º 2
0
 public function __construct(Model $model)
 {
     parent::__construct();
     $fields = $model->getFields();
     foreach ($fields as $name => $field) {
         if ($field['key'] == 'primary') {
             continue;
         }
         if ($field['reference'] == '') {
             $method = "get{$field['type']}field";
             $element = $this->{$method}($field);
         } else {
             $element = new ModelField($field["reference"], $field["referenceValue"]);
         }
         $element->setRequired($field['required']);
         $this->add($element);
     }
     $this->addAttribute('style', 'width:50%');
 }
Exemplo n.º 3
0
 public function __construct($dict = array())
 {
     $dict['default'] = '0000-00-00 00:00:00';
     $dict['extra'] = 'on update CURRENT_TIMESTAMP';
     parent::__construct($dict);
 }
Exemplo n.º 4
0
 /**
  * 基础表单
  */
 public static function baseForm()
 {
     if (!($data['model_id'] = self::isP('model_id'))) {
         return self::error($GLOBALS['_LANG']['MODEL']['LOST_MODEL_ID']);
     }
     if (!(self::$model = \Model\Model::findModel($data['model_id']))) {
         return self::error($GLOBALS['_LANG']['MODEL']['NOT_EXIST_MODEL']);
     }
     if (self::p('method') == 'PUT') {
         if (!($data['noset']['field_id'] = self::isP('field_id'))) {
             return self::error($GLOBALS['_LANG']['MODEL']['LOST_FIELD_ID']);
         }
         if (!self::findField($data['noset']['field_id'])) {
             return self::error($GLOBALS['_LANG']['MODEL']['NOT_EXIST_FIELD']);
         }
     } else {
         if (!($data['field_type'] = self::isP('field_type'))) {
             return self::error($GLOBALS['_LANG']['MODEL']['SELECT_FIELD_TYPE']);
         }
         if (!($data['field_name'] = self::isP('field_name'))) {
             return self::error($GLOBALS['_LANG']['MODEL']['ENTER_FIELD_NAME']);
         }
     }
     if (!($data['display_name'] = self::isP('display_name'))) {
         return self::error($GLOBALS['_LANG']['MODEL']['ENTER_DISPLAY_NAME']);
     }
     if (!($data['field_option'] = self::splitOption())) {
         self::error($GLOBALS['_LANG']['MODEL']['SPLIT_OPTION_ERROR']);
     }
     if (!($data['field_required'] = self::isP('field_required')) && !is_numeric($data['field_required'])) {
         return self::error($GLOBALS['_LANG']['MODEL']['SELECT_REQUIRED']);
     }
     if (!($data['field_status'] = self::isP('field_status')) && !is_numeric($data['field_status'])) {
         return self::error($GLOBALS['_LANG']['MODEL']['SELECT_FIELD_STATUS']);
     }
     $data['field_default'] = self::p('field_default');
     $data['field_listsort'] = self::p('field_listsort');
     return self::success($data);
 }
Exemplo n.º 5
0
 protected function addReferencedFilter($label, $name, $model, $value, $searchField = true)
 {
     if ($searchField === true || is_array($searchField)) {
         if (is_array($searchField)) {
             $enum_list = new ModelSearchField($model, $value);
             foreach ($searchField as $field) {
                 $enum_list->addSearchField($field);
             }
             $enum_list->boldFirst = true;
         } else {
             $enum_list = new ModelSearchField($model, $value);
             $enum_list->boldFirst = false;
         }
     } else {
         $enum_list = new ModelField($model, $value);
     }
     $enum_list->setName("{$name}_value");
     $this->filters->add(Element::create("Label", $label), $this->numFilters, 0)->add(Element::create("SelectionList", "", "{$name}_option")->addOption("Is any of", "IS_ANY_OF")->addOption("Is none of", "IS_NONE_OF")->setValue("IS_ANY_OF"), $this->numFilters, 1)->add(Element::create("MultiFields")->setTemplate($enum_list), $this->numFilters, 2);
     $this->numFilters++;
 }
Exemplo n.º 6
0
 /**
  * Returns the form that this controller uses to manipulate the data stored
  * in its model. As stated earlier the form is either automatically generated
  * or it is loaded from an existing file which is located in the same
  * directory as the model and bears the model's name.
  *
  * @return Form
  */
 protected function getForm()
 {
     // Load a local form if it exists.
     if ($this->redirected) {
         $formName = $this->redirectedPackageName . Application::camelize($this->mainRedirectedPackage) . "Form";
         $formPath = $this->redirectPath . "/" . str_replace(".", "/", $this->mainRedirectedPackage) . "/" . $formName . ".php";
     } else {
         $formName = Application::camelize($this->model->package) . "Form";
         $formPath = $this->localPath . "/" . $formName . ".php";
     }
     if (is_file($formPath)) {
         include_once $formPath;
         $form = new $formName();
     } else {
         if (is_file($this->localPath . "/" . $this->name . "Form.php")) {
             include_once $this->localPath . "/" . $this->name . "Form.php";
             $formclass = $this->name . "Form";
             $form = new $formclass();
             $form->setModel($this->model);
         } else {
             // Generate a form automatically
             $fieldNames = array();
             $fields = $this->model->getFields();
             $form = new Form();
             $form->setModel($this->model);
             $names = array_keys($fields);
             for ($i = 0; $i < count($fields); $i++) {
                 $field = $fields[$names[$i]];
                 if ($field['key'] == 'primary') {
                     continue;
                 }
                 if ($fieldNames[$i]["renderer"] == "") {
                     if ($field["reference"] == "") {
                         switch ($field["type"]) {
                             case "boolean":
                                 $element = new Checkbox($field["label"], $field["name"], $field["description"], 1);
                                 break;
                             case "enum":
                                 $element = new SelectionList($field["label"], $field["name"]);
                                 foreach ($field["options"] as $value => $option) {
                                     $element->addOption($option, $value . "");
                                 }
                                 break;
                             case "date":
                             case "datetime":
                                 $element = new DateField($field["label"], $field["name"]);
                                 break;
                             case "integer":
                             case "double":
                                 $element = new TextField($field["label"], $field["name"], $field["description"]);
                                 $element->setAsNumeric();
                                 break;
                             case "textarea":
                                 $element = new TextArea($field["label"], $field["name"], $field["description"]);
                                 break;
                             default:
                                 $element = new TextField($field["label"], $field["name"], $field["description"]);
                                 break;
                         }
                     } else {
                         $element = new ModelField($field["reference"], $field["referenceValue"]);
                     }
                     foreach ($field["validators"] as $validator) {
                         switch ($validator["type"]) {
                             case "required":
                                 $element->setRequired(true);
                                 break;
                             case "unique":
                                 $element->setUnique(true);
                                 break;
                             case "regexp":
                                 $element->setRegexp((string) $validator["parameter"]);
                                 break;
                         }
                     }
                 } else {
                     $renderer = (string) $fieldNames[$i]["renderer"];
                     $element = new $renderer();
                 }
                 $form->add($element);
             }
             $form->addAttribute("style", "width:50%");
             $form->useAjax(true, false);
         }
     }
     return $form;
 }
Exemplo n.º 7
0
 private function createDefaultForm()
 {
     // Generate a form automatically
     $fieldNames = array();
     $fields = $this->model->getFields();
     $form = new Form();
     $names = array_keys($fields);
     for ($i = 0; $i < count($fields); $i++) {
         $field = $fields[$names[$i]];
         if ($field['key'] == 'primary') {
             continue;
         }
         if ($fieldNames[$i]["renderer"] == "") {
             if ($field["reference"] == "") {
                 switch ($field["type"]) {
                     case "boolean":
                         $element = new Checkbox($field["label"], $field["name"], $field["description"], 1);
                         break;
                     case "enum":
                         $element = new SelectionList($field["label"], $field["name"]);
                         foreach ($field["options"] as $value => $option) {
                             $element->addOption($option, $value . "");
                         }
                         break;
                     case "date":
                     case "datetime":
                         $element = new DateField($field["label"], $field["name"]);
                         break;
                     case "integer":
                     case "double":
                         $element = new TextField($field["label"], $field["name"], $field["description"]);
                         $element->setAsNumeric();
                         break;
                     case "textarea":
                         $element = new TextArea($field["label"], $field["name"], $field["description"]);
                         break;
                     default:
                         $element = new TextField($field["label"], $field["name"], $field["description"]);
                         break;
                 }
             } else {
                 $element = new ModelField($field["reference"], $field["referenceValue"]);
             }
             foreach ($field["validators"] as $validator) {
                 switch ($validator["type"]) {
                     case "required":
                         $element->setRequired(true);
                         break;
                     case "unique":
                         $element->setUnique(true);
                         break;
                     case "regexp":
                         $element->setRegexp((string) $validator["parameter"]);
                         break;
                 }
             }
         } else {
             $renderer = (string) $fieldNames[$i]["renderer"];
             $element = new $renderer();
         }
         $form->add($element);
     }
     $form->addAttribute("style", "width:50%");
     $form->useAjax(true, false);
     return $form;
 }
Exemplo n.º 8
0
 /**
  * 基础表单
  */
 public static function baseForm()
 {
     $data['model_id'] = self::isP('model_id', '丢失模型ID');
     if (!(self::$model = \Model\ModelManage::findModel($data['model_id']))) {
         self::error('不存在的模型');
     }
     if (self::p('method') == 'PUT') {
         $data['noset']['field_id'] = self::isP('field_id', '丢失字段ID');
         if (!self::findField($data['noset']['field_id'])) {
             self::error('不存在的模型');
         }
     } else {
         $data['field_type'] = self::isP('field_type', '请选择字段类型');
         $data['field_name'] = self::isP('field_name', '请填写字段名称');
     }
     $data['display_name'] = self::isP('display_name', '请填写字段显示名称');
     $data['field_option'] = self::splitOption();
     if ($data['field_option'] === false) {
         self::error('拆分字段选项出错');
     }
     if (!($data['field_required'] = self::p('field_required')) && !is_numeric($_POST['field_required'])) {
         return self::error('请选择是否为必填');
     }
     if (!($data['field_status'] = self::p('field_status')) && !is_numeric($_POST['field_status'])) {
         return self::error('请选择启用状态');
     }
     $data['field_default'] = self::p('field_default');
     $data['field_listsort'] = self::p('field_listsort');
     $data['field_explain'] = self::p('field_explain');
     $data['field_list'] = self::p('field_list');
     return $data;
 }
Exemplo n.º 9
0
 /**
  * 基础表单
  */
 public static function baseForm()
 {
     if (!(self::$model = \Model\ModelManage::findModel(self::isP('model_id', '丢失模型ID')))) {
         self::error('不存在的模型');
     }
     $option = self::splitOption(self::p('option'));
     if ($option === false) {
         self::error('拆分字段选项出错');
     }
     $_POST['option'] = (string) $option;
 }