diff --git a/module/entry/config/form.php b/module/entry/config/form.php new file mode 100644 index 0000000000..31d9730e07 --- /dev/null +++ b/module/entry/config/form.php @@ -0,0 +1,23 @@ +entry->form = new stdClass(); +$config->entry->form->create = array(); +$config->entry->form->edit = array(); + +$config->entry->form->create['name'] = array('type' => 'string', 'required' => true, 'filter' => 'trim'); +$config->entry->form->create['code'] = array('type' => 'string', 'required' => true, 'filter' => 'trim'); +$config->entry->form->create['account'] = array('type' => 'string', 'required' => true, 'filter' => 'trim', 'default' => ''); +$config->entry->form->create['ip'] = array('type' => 'string', 'required' => true, 'filter' => 'trim', 'default' => '*'); +$config->entry->form->create['key'] = array('type' => 'string', 'required' => true, 'filter' => 'trim', 'default' => ''); +$config->entry->form->create['allIP'] = array('type' => 'string', 'required' => true, 'filter' => 'trim', 'default' => 'off'); +$config->entry->form->create['freePasswd'] = array('type' => 'int', 'required' => true); +$config->entry->form->create['desc'] = array('type' => 'string', 'required' => false, 'default' => '', 'control' => 'editor'); + + +$config->entry->form->edit['name'] = array('type' => 'string', 'required' => true, 'filter' => 'trim'); +$config->entry->form->edit['code'] = array('type' => 'string', 'required' => true, 'filter' => 'trim'); +$config->entry->form->edit['account'] = array('type' => 'string', 'required' => true, 'filter' => 'trim', 'default' => ''); +$config->entry->form->edit['ip'] = array('type' => 'string', 'required' => true, 'filter' => 'trim', 'default' => '*'); +$config->entry->form->edit['key'] = array('type' => 'string', 'required' => true, 'filter' => 'trim', 'default' => ''); +$config->entry->form->edit['allIP'] = array('type' => 'string', 'required' => true, 'filter' => 'trim', 'default' => 'off'); +$config->entry->form->edit['freePasswd'] = array('type' => 'int', 'required' => true); +$config->entry->form->edit['desc'] = array('type' => 'string', 'required' => false, 'default' => '', 'control' => 'editor'); diff --git a/module/entry/control.php b/module/entry/control.php index f4805af3bb..75239667f4 100644 --- a/module/entry/control.php +++ b/module/entry/control.php @@ -43,7 +43,15 @@ class entry extends control { if($_POST) { - $id = $this->entry->create(); + $entry = form::data($this->config->entry->form->create) + ->setIF($this->post->allIP === 'on', 'ip', '*') + ->setIF($this->post->freePasswd == '1', 'account', '') + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->remove('allIP') + ->get(); + + $id = $this->entry->create($entry); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->loadModel('action')->create('entry', $id, 'created'); @@ -67,7 +75,15 @@ class entry extends control { if($_POST) { - $changes = $this->entry->update($id); + $entry = form::data($this->config->entry->form->create) + ->setIF($this->post->allIP === 'on', 'ip', '*') + ->setIF($this->post->freePasswd == '1', 'account', '') + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->remove('allIP') + ->get(); + + $changes = $this->entry->update($id, $entry); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); if($changes) diff --git a/module/entry/js/common.ui.js b/module/entry/js/common.ui.js index 5103d1d22b..57df18420e 100644 --- a/module/entry/js/common.ui.js +++ b/module/entry/js/common.ui.js @@ -27,9 +27,11 @@ function toggleAllIP(event) if($(event.target).prop('checked')) { $('#ip').attr('disabled', 'disabled'); + $('input[name=ip][type=hidden]').removeAttr('disabled'); } else { + $('input[name=ip][type=hidden]').attr('disabled', 'disabled'); $('#ip').removeAttr('disabled'); } } diff --git a/module/entry/model.php b/module/entry/model.php index 7c7fcff16b..fca7323584 100644 --- a/module/entry/model.php +++ b/module/entry/model.php @@ -81,23 +81,16 @@ class entryModel extends model } /** + * 创建一个应用。 * Create an entry. * + * @param object $entry * @access public - * @return bool | int + * @return bool|int */ - public function create() + public function create(object $entry): bool|int { - $entry = fixer::input('post') - ->setDefault('ip', '*') - ->setIF($this->post->allIP, 'ip', '*') - ->setIF($this->post->freePasswd == '1', 'account', '') - ->add('createdBy', $this->app->user->account) - ->add('createdDate', helper::now()) - ->remove('allIP') - ->get(); - - if($this->post->freePasswd == 1) $this->config->entry->create->requiredFields = 'name, code, key'; + if($entry->freePasswd == 1) $this->config->entry->create->requiredFields = 'name, code, key'; $this->dao->insert(TABLE_ENTRY)->data($entry) ->batchCheck($this->config->entry->create->requiredFields, 'notempty') @@ -111,25 +104,19 @@ class entryModel extends model } /** + * 更新一个应用。 * Update an entry. * - * @param int $entryID + * @param int $entryID + * @param object $entry * @access public - * @return bool | array + * @return bool|array */ - public function update($entryID) + public function update(int $entryID, object $entry): bool|array { $oldEntry = $this->getById($entryID); - $entry = fixer::input('post') - ->setDefault('ip', '*') - ->setIF($this->post->allIP, 'ip', '*') - ->add('editedBy', $this->app->user->account) - ->add('editedDate', helper::now()) - ->remove('allIP') - ->get(); - - if($this->post->freePasswd == 1) $this->config->entry->edit->requiredFields = 'name, code, key'; + if($entry->freePasswd == 1) $this->config->entry->edit->requiredFields = 'name, code, key'; $this->dao->update(TABLE_ENTRY)->data($entry) ->batchCheck($this->config->entry->edit->requiredFields, 'notempty') diff --git a/module/entry/ui/edit.html.php b/module/entry/ui/edit.html.php index e15ddfba3e..3383481fc8 100644 --- a/module/entry/ui/edit.html.php +++ b/module/entry/ui/edit.html.php @@ -150,7 +150,7 @@ formPanel ( set::name('desc'), set::rows('3'), - set::value($entry->desc), + html($entry->desc), ) ), );