/** * @ignore */ public static function edit($uAction, $uSlug) { Auth::checkRedirect('editor'); $tModule = AutoModels::get(Panel::$module); $tViewbag = array('module' => $tModule, 'fields' => array()); if (Request::$method === 'post') { //! todo: validations Validation::addRule('name')->isRequired()->errorMessage('Name shouldn\'t be blank.'); // Validation::addRule('slug')->isRequired()->errorMessage('Slug shouldn\'t be blank.'); if (Validation::validate($_POST)) { $tSlug = Request::post('slug', ""); if (strlen(rtrim($tSlug)) === 0) { $tSlug = Request::post('name', ""); } $tInput = array('type' => Request::post('type'), 'name' => Request::post('name'), 'slug' => String::slug(String::removeAccent($tSlug))); $tAutoModel = new AutoModel('categories'); $tAutoModel->update($uSlug, $tInput); Session::set('notification', array('info', 'ok-sign', 'Record modified.')); Http::redirect('panel/categories'); return; } Session::set('notification', array('error', 'remove-sign', Validation::getErrorMessages(true))); foreach ($tModule['fieldList'] as $tField) { $tIsView = array_key_exists('view', $tField['methods']); $tIsEdit = array_key_exists('edit', $tField['methods']); if ($tIsView || $tIsEdit) { if ($tField['type'] === 'enum') { $tTypes = array(); foreach ($tField['valueList'] as $tValue) { $tTypes[$tValue['name']] = $tValue['title']; } $tAttributes = array('name' => $tField['name'], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('select', $tAttributes, Html::selectOptions($tTypes, Request::post($tField['name'], null))) . '</p>'; } else { $tAttributes = array('type' => 'text', 'name' => $tField['name'], 'value' => Request::post($tField['name'], ""), 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('input', $tAttributes) . '</p>'; } } $tViewbag['fields'][] = array('data' => $tField, 'html' => $tTag); } Views::viewFile('{core}views/panel/models/form.php', $tViewbag); return; } $tAutoModel = new AutoModel('categories'); $tCategory = $tAutoModel->getBySlug($tModule['name'], $uSlug); foreach ($tModule['fieldList'] as $tField) { $tIsView = array_key_exists('view', $tField['methods']); $tIsEdit = array_key_exists('edit', $tField['methods']); if ($tIsView || $tIsEdit) { if ($tField['type'] === 'enum') { $tTypes = array(); foreach ($tField['valueList'] as $tValue) { $tTypes[$tValue['name']] = $tValue['title']; } $tAttributes = array('name' => $tField['name'], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('select', $tAttributes, Html::selectOptions($tTypes, $tCategory[$tField['name']])) . '</p>'; } else { $tAttributes = array('type' => 'text', 'name' => $tField['name'], 'value' => $tCategory[$tField['name']], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('input', $tAttributes) . '</p>'; } } $tViewbag['fields'][] = array('data' => $tField, 'html' => $tTag); } Views::viewFile('{core}views/panel/models/form.php', $tViewbag); }
/** * @ignore */ public function __construct($uModelName, $uDatasource = null) { parent::__construct($uDatasource); $this->entityName = $uModelName; $this->modelDefinition = AutoModels::get($uModelName); }