1
0
Fork 0
mirror of https://github.com/Oreolek/kangana.git synced 2024-06-16 15:01:09 +03:00

Fast course creation UI

This commit is contained in:
Alexander Yakovlev 2014-02-19 14:15:40 +07:00
parent 09fc6bb843
commit d9abab48ff
7 changed files with 139 additions and 4 deletions

View file

@ -31,6 +31,55 @@ class Controller_Course extends Controller_Layout {
$this->_edit($this->template->model);
}
/**
* One-page course creation
**/
public function action_simple()
{
$this->template = new View_Course_Simple;
$this->template->controls = array();
$this->template->title = __('New course');
if ($this->request->method() === HTTP_Request::POST) {
$course = ORM::factory('Course');
$letter = ORM::factory('Letter');
$course->values($this->request->post(), array('title', 'description'));
$letter->subject = $this->request->post('letter_subject');
$letter->text = $this->request->post('letter_body');
$course->price = 0;
$course->period = 1;
$letter->order = 1;
$validation_course = $course->validate_create($this->request->post());
$validation_letter = $letter->validate_create(array(
'subject' => $this->request->post('letter_subject'),
'text' => $this->request->post('letter_body')
));
try
{
if ($validation_course->check() AND $validation_letter->check())
{
$course->create();
$letter->course_id = $course->id;
$letter->create();
}
else
{
$this->template->errors = array_merge(
$validation_course->errors('default'),
$validation_letter->errors('default')
);
}
}
catch (ORM_Validation_Exception $e)
{
$this->template->errors = $e->errors('default');
}
if (empty($this->template->errors))
{
$this->redirect($this->_edit_redirect($course));
}
}
}
public function action_edit()
{
$this->template = new View_Edit;

View file

@ -116,6 +116,28 @@ class Form extends Kohana_Form {
$template->value = $model->$name;
return self::render_inline_control($template);
}
public static function textarea_inline($model, $name)
{
$template = new View_Form_Textarea;
$template->_view = 'form/inline/textarea';
$template->name = $name;
$template->label = __($model->get_label($name));
$template->value = $model->$name;
return self::render_inline_control($template);
}
/**
* New textarea.
* Does not support $double_encode = FALSE.
**/
public static function textarea($name, $value = NULL, array $attributes = NULL, $double_encode = TRUE)
{
$template = new View_Form_Textarea;
$template->name = $name;
$template->label = __(Arr::get($attributes, 'label'));
$template->value = $value;
return self::render_control($template);
}
/**
* A textarea with a HTML visual editor

View file

@ -0,0 +1,28 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Simple course and first letter creation view controller
**/
class View_Course_Simple extends View_Edit {
public function controls_course()
{
return array(
'heading' => __('New course'),
'controls' => array(
Form::textinput('title', '', array('label' => 'Title')),
Form::textarea('description', '', array('label' => 'Description'))
)
);
}
public function controls_letter()
{
return array(
'heading' => __('First letter'),
'controls' => array(
Form::textinput('letter_subject', '', array('label' => 'Subject')),
Form::textarea('letter_body', '', array('label' => 'Message body'))
)
);
}
}

View file

@ -1,4 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Edit view controller
@ -26,9 +26,12 @@ class View_Edit extends View_Layout {
public function get_controls()
{
$output = '';
foreach ($this->controls as $key => $value)
if ($this->model instanceof ORM)
{
$output .= Form::orm_input($this->model, $key, $value);
foreach ($this->controls as $key => $value)
{
$output .= Form::orm_input($this->model, $key, $value);
}
}
foreach ($this->custom_controls as $key => $value)
{

View file

@ -77,6 +77,7 @@ class View_Layout {
else
{
$navigation = array_merge($navigation, array(
__('New course') => 'course/simple',
__('Courses') => 'course/index',
__('Subscriptions') => 'subscription/index',
__('Clients') => 'client/index',

View file

@ -61,5 +61,8 @@ return array(
'Welcome message' => 'Приветственное сообщение',
'Sent' => 'Отправлено',
'Send instant to all subscribers' => 'Отослать мгновенное всем подписчикам',
'The instant has been sent.' => 'Мгновенное было выслано.'
'The instant has been sent.' => 'Мгновенное было выслано.',
'First letter' => 'Первое письмо',
'Subject' => 'Тема',
'Message body' => 'Тело письма'
);

View file

@ -0,0 +1,29 @@
<form method="POST">
{{#has_errors}}
<p class="message">При проверке формы были найдены ошибки:</p>
<ul class="errors">
{{#get_errors}}
<li>{{.}}</li>
{{/get_errors}}
</ul>
{{/has_errors}}
<div class="row">
<div class="col-md-6">
{{#controls_course}}
<h4>{{heading}}</h4>
{{#controls}}
{{{.}}}
{{/controls}}
{{/controls_course}}
</div>
<div class="col-md-6">
{{#controls_letter}}
<h4>{{heading}}</h4>
{{#controls}}
{{{.}}}
{{/controls}}
{{/controls_letter}}
</div>
</div>
{{{get_controls}}}
</form>