Skip to content

Commit

Permalink
Making websites with October CMS - Part 25 - NEW! Ajax Form Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Doric committed Nov 27, 2016
1 parent 42d478f commit c8beeb8
Show file tree
Hide file tree
Showing 267 changed files with 4,310 additions and 1,026 deletions.
60 changes: 12 additions & 48 deletions modules/backend/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,54 +151,18 @@ protected function registerBackendPermissions()
protected function registerBackendWidgets()
{
WidgetManager::instance()->registerFormWidgets(function ($manager) {
$manager->registerFormWidget('Backend\FormWidgets\CodeEditor', [
'label' => 'Code editor',
'code' => 'codeeditor'
]);
$manager->registerFormWidget('Backend\FormWidgets\RichEditor', [
'label' => 'Rich editor',
'code' => 'richeditor'
]);
$manager->registerFormWidget('Backend\FormWidgets\MarkdownEditor', [
'label' => 'Markdown editor',
'code' => 'markdown'
]);
$manager->registerFormWidget('Backend\FormWidgets\FileUpload', [
'label' => 'File uploader',
'code' => 'fileupload'
]);
$manager->registerFormWidget('Backend\FormWidgets\Relation', [
'label' => 'Relationship',
'code' => 'relation'
]);
$manager->registerFormWidget('Backend\FormWidgets\DatePicker', [
'label' => 'Date picker',
'code' => 'datepicker'
]);
$manager->registerFormWidget('Backend\FormWidgets\TimePicker', [
'label' => 'Time picker',
'code' => 'timepicker'
]);
$manager->registerFormWidget('Backend\FormWidgets\ColorPicker', [
'label' => 'Color picker',
'code' => 'colorpicker'
]);
$manager->registerFormWidget('Backend\FormWidgets\DataTable', [
'label' => 'Data Table',
'code' => 'datatable'
]);
$manager->registerFormWidget('Backend\FormWidgets\RecordFinder', [
'label' => 'Record Finder',
'code' => 'recordfinder'
]);
$manager->registerFormWidget('Backend\FormWidgets\Repeater', [
'label' => 'Repeater',
'code' => 'repeater'
]);
$manager->registerFormWidget('Backend\FormWidgets\TagList', [
'label' => 'Tag List',
'code' => 'taglist'
]);
$manager->registerFormWidget('Backend\FormWidgets\CodeEditor', 'codeeditor');
$manager->registerFormWidget('Backend\FormWidgets\RichEditor', 'richeditor');
$manager->registerFormWidget('Backend\FormWidgets\MarkdownEditor', 'markdown');
$manager->registerFormWidget('Backend\FormWidgets\FileUpload', 'fileupload');
$manager->registerFormWidget('Backend\FormWidgets\Relation', 'relation');
$manager->registerFormWidget('Backend\FormWidgets\DatePicker', 'datepicker');
$manager->registerFormWidget('Backend\FormWidgets\TimePicker', 'timepicker');
$manager->registerFormWidget('Backend\FormWidgets\ColorPicker', 'colorpicker');
$manager->registerFormWidget('Backend\FormWidgets\DataTable', 'datatable');
$manager->registerFormWidget('Backend\FormWidgets\RecordFinder', 'recordfinder');
$manager->registerFormWidget('Backend\FormWidgets\Repeater', 'repeater');
$manager->registerFormWidget('Backend\FormWidgets\TagList', 'taglist');
});
}

Expand Down
2 changes: 1 addition & 1 deletion modules/backend/assets/less/controls/filelist.less
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
&.single-line {
ul {
li a span.title {
text-overflow: ellipsis;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
Expand Down
17 changes: 11 additions & 6 deletions modules/backend/behaviors/FormController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Backend\Behaviors;

use Db;
use Str;
use Lang;
use Flash;
Expand Down Expand Up @@ -211,9 +212,11 @@ public function create_onSave($context = null)
$this->controller->formBeforeCreate($model);

$modelsToSave = $this->prepareModelsToSave($model, $this->formWidget->getSaveData());
foreach ($modelsToSave as $modelToSave) {
$modelToSave->save(null, $this->formWidget->getSessionKey());
}
Db::transaction(function() use ($modelsToSave) {
foreach ($modelsToSave as $modelToSave) {
$modelToSave->save(null, $this->formWidget->getSessionKey());
}
});

$this->controller->formAfterSave($model);
$this->controller->formAfterCreate($model);
Expand Down Expand Up @@ -267,9 +270,11 @@ public function update_onSave($recordId = null, $context = null)
$this->controller->formBeforeUpdate($model);

$modelsToSave = $this->prepareModelsToSave($model, $this->formWidget->getSaveData());
foreach ($modelsToSave as $modelToSave) {
$modelToSave->save(null, $this->formWidget->getSessionKey());
}
Db::transaction(function() use ($modelsToSave) {
foreach ($modelsToSave as $modelToSave) {
$modelToSave->save(null, $this->formWidget->getSessionKey());
}
});

$this->controller->formAfterSave($model);
$this->controller->formAfterUpdate($model);
Expand Down
23 changes: 19 additions & 4 deletions modules/backend/behaviors/ImportExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function prepareImportVars()

public function importRender()
{
return $this->importExportMakePartial('import');
return $this->importExportMakePartial('container_import');
}

public function importGetModel()
Expand Down Expand Up @@ -456,7 +456,7 @@ public function prepareExportVars()

public function exportRender()
{
return $this->importExportMakePartial('export');
return $this->importExportMakePartial('container_export');
}

public function exportGetModel()
Expand Down Expand Up @@ -538,14 +538,21 @@ protected function processExportColumnsFromPost()

protected function checkUseListExportMode()
{
if (!$listDefinition = $this->getConfig('export[useList]')) {
if (!$useList = $this->getConfig('export[useList]')) {
return false;
}

if (!$this->controller->isClassExtendedWith('Backend.Behaviors.ListController')) {
throw new ApplicationException(Lang::get('backend::lang.import_export.behavior_missing_uselist_error'));
}

if (is_array($useList)) {
$listDefinition = array_get($useList, 'definition');
}
else {
$listDefinition = $useList;
}

$this->exportFromList($listDefinition);
}

Expand Down Expand Up @@ -594,12 +601,20 @@ public function exportFromList($definition = null, $options = [])
/*
* Add records
*/
$getter = $this->getConfig('export[useList][raw]', false)
? 'getColumnValueRaw'
: 'getColumnValue';

$model = $widget->prepareModel();
$results = $model->get();
foreach ($results as $result) {
$record = [];
foreach ($columns as $column) {
$record[] = $widget->getColumnValue($result, $column);
$value = $widget->$getter($result, $column);
if (is_array($value)) {
$value = implode('|', $value);
}
$record[] = $value;
}
$csv->insertOne($record);
}
Expand Down
29 changes: 18 additions & 11 deletions modules/backend/behaviors/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function makeList($definition = null)
'showCheckboxes',
'showTree',
'treeExpanded',
'customViewPath',
];

foreach ($configFieldsToTransfer as $field) {
Expand Down Expand Up @@ -342,18 +343,8 @@ public function listRender($definition = null)
'toolbar' => null,
'filter' => null,
'list' => null,
'topPartial' => null,
'sidePartial' => null
];

if (isset($listConfig->topPartial)) {
$vars['topPartial'] = $listConfig->topPartial;
}

if (isset($listConfig->sidePartial)) {
$vars['sidePartial'] = $listConfig->sidePartial;
}

if (isset($this->toolbarWidgets[$definition])) {
$vars['toolbar'] = $this->toolbarWidgets[$definition];
}
Expand All @@ -364,7 +355,23 @@ public function listRender($definition = null)

$vars['list'] = $this->listWidgets[$definition];

return $this->makePartial('list', $vars);
return $this->listMakePartial('container', $vars);
}

/**
* Controller accessor for making partials within this behavior.
* @param string $partial
* @param array $params
* @return string Partial contents
*/
public function listMakePartial($partial, $params = [])
{
$contents = $this->controller->makePartial('list_'.$partial, $params + $this->vars, false);
if (!$contents) {
$contents = $this->makePartial($partial, $params);
}

return $contents;
}

/**
Expand Down
Loading

0 comments on commit c8beeb8

Please sign in to comment.