/** * Shortcut for ajax */ function ajax($data = NULL) { $ajax = new Ajax(); if ($data) { $ajax->append($data); $ajax->send(); } return $ajax; }
/** * Edit action */ public function edit_action($id = NULL) { $post = new Post(); $post->id = $id; $post->cache(FALSE); if (!$post->find()) { return event('404'); } $form = new Form('Post/forms/post'); $form->object($post); $form->elements->title->options->label = t('Редактирование публикации'); event('post.edit', $post, $form); if ($result = $form->result()) { $post->object()->extend($result); if ($result->delete && access('Post.delete', $post)) { if ($post->delete()) { flash_success(t('Пост удалён!')); redirect(); } } if ($result->preview) { $post->created_date = time(); $post->aid = $this->user->id; $post->preview = TRUE; $post->show(); } else { if (Ajax::is() && $this->input->get('autosave')) { $post->update(); $ajax = new Ajax(); $ajax->message(t('Пост сохранён!', 'Post')); $ajax->send(); } if ($result->draft) { $post->published = 0; } elseif ($result->publish) { $post->published = 1; } if ($post->save()) { if ($post->published) { $link = l($post->getLink()); flash_success(t('Пост опубликован!'), NULL, 'growl'); } else { $link = l($post->getLink()); flash_success(t('Сохранено в черновиках!'), NULL, 'growl'); } redirect($post->getLink()); } } } $form->show(); }