Skip to content

Commit

Permalink
initial category and product options
Browse files Browse the repository at this point in the history
  • Loading branch information
ljb0904 committed Dec 31, 2019
1 parent 922877f commit ac47d37
Show file tree
Hide file tree
Showing 30 changed files with 728 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public function registerNavigation()
'url' => Backend::url('lbaig/catalog/products'),
'permissions' => ['lbaig.lshop.some_permission']
],
'options' => [
'label' => 'Options',
'icon' => 'icon-list-ul',
'url' => Backend::url('lbaig/catalog/options'),
'permissions' => ['lbaig.lshop.some_permission']
]
]
],
];
Expand Down
2 changes: 2 additions & 0 deletions assets/js/Sortable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions assets/js/initialize_sorting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function initializeSorting() {
var $tbody = $('.drag-handle').parents('table.data tbody');
Sortable.create($tbody[0], {
handle: '.drag-handle',
animation: 150,
onEnd: function (evt) {
var $inputs = $(evt.srcElement).find('td>div.drag-handle>input');
var $form = $('<form style="display: none;">');
$form.append($inputs.clone())
.request('onReorder', {
complete: function () {
$form.remove();
}
});
}
});
}

$(function () {
initializeSorting();

/* change cursor on hover */
$(".drag-handle").hover(function() {
$(this).css('cursor','move');
}, function() {
$(this).css('cursor','auto');
});
});
2 changes: 1 addition & 1 deletion controllers/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Categories extends Controller
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
'Backend.behaviors.ReorderController'
'Backend.Behaviors.ReorderController',
];

public $formConfig = 'config_form.yaml';
Expand Down
38 changes: 38 additions & 0 deletions controllers/Options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php namespace Lbaig\Catalog\Controllers;

use BackendMenu;
use Backend\Classes\Controller;
use Lbaig\Catalog\Models\OptionItem;
use Request;

/**
* Options Back-end Controller
*/
class Options extends Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
'Backend.Behaviors.RelationController'
];

public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';
public $relationConfig = 'config_relation.yaml';

public function __construct()
{
parent::__construct();

BackendMenu::setContext('Lbaig.Catalog', 'catalog', 'options');
$this->addJs('/plugins/lbaig/catalog/assets/js/Sortable.min.js');
$this->addJs('/plugins/lbaig/catalog/assets/js/initialize_sorting.js');
}

// to reorder the children OptionItem's
public function onReorder() {
$records = Request::input('rcd');
$model = new OptionItem;
$model->setSortableOrder($records, range(1, count($records)));
}
}
21 changes: 21 additions & 0 deletions controllers/options/_list_toolbar.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div data-control="toolbar">
<a
href="<?= Backend::url('lbaig/catalog/options/create') ?>"
class="btn btn-primary oc-icon-plus">
New Option
</a>

<button
class="btn btn-danger oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', { checked: $('.control-list').listWidget('getChecked') })"
data-request="onDelete"
data-request-confirm="Are you sure you want to delete the selected Options?"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', 'disabled')"
data-stripe-load-indicator>
Delete selected
</button>
</div>
1 change: 1 addition & 0 deletions controllers/options/_optionitems.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= $this->relationRender('optionItems') ?>
31 changes: 31 additions & 0 deletions controllers/options/config_form.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ===================================
# Form Behavior Config
# ===================================

# Record name
name: Option

# Model Form Field configuration
form: $/lbaig/catalog/models/option/fields.yaml

# Model Class name
modelClass: Lbaig\Catalog\Models\Option

# Default redirect location
defaultRedirect: lbaig/catalog/options

# Create page
create:
title: Create Option
redirect: lbaig/catalog/options/update/:id
redirectClose: lbaig/catalog/options

# Update page
update:
title: Edit Option
redirect: lbaig/catalog/options
redirectClose: lbaig/catalog/options

# Preview page
preview:
title: Preview Option
Loading

0 comments on commit ac47d37

Please sign in to comment.