Skip to content

Commit

Permalink
First commit. Adding backend products and categories
Browse files Browse the repository at this point in the history
  • Loading branch information
dshoreman committed Oct 10, 2014
1 parent 98408de commit f12756a
Show file tree
Hide file tree
Showing 29 changed files with 744 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
63 changes: 63 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php namespace DShoreman\Shop;

use Backend;
use System\Classes\PluginBase;

/**
* Shop Plugin Information File
*/
class Plugin extends PluginBase
{

/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'Shop',
'description' => 'No description provided yet...',
'author' => 'Dave Shoreman',
'icon' => 'icon-shopping-cart'
];
}

public function registerNavigation()
{
return [
'shop' => [
'label' => 'Shop',
'url' => Backend::url('dshoreman/shop/products'),
'icon' => 'icon-shopping-cart',
'permissions' => ['dshoreman.shop.*'],
'order' => 300,

'sideMenu' => [
'products' => [
'label' => 'Products',
'url' => Backend::url('dshoreman/shop/products'),
'icon' => 'icon-gift',
'permissions' => ['dshoreman.shop.access_products']
],
'categories' => [
'label' => 'Categories',
'url' => Backend::url('dshoreman/shop/categories'),
'icon' => 'icon-list-ul',
'permissions' => ['dshoreman.shop.access_categories'],
],
],
],
];
}

public function registerPermissions()
{
return [
'dshoreman.shop.access_products' => ['label' => "Manage the shop's products"],
'dshoreman.shop.access_categories' => ['label' => "Manage the shop categories"],
];
}

}
25 changes: 25 additions & 0 deletions controllers/Categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php namespace DShoreman\Shop\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

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

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

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

BackendMenu::setContext('DShoreman.Shop', 'shop', 'categories');
}
}
25 changes: 25 additions & 0 deletions controllers/Products.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php namespace DShoreman\Shop\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

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

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

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

BackendMenu::setContext('DShoreman.Shop', 'shop', 'products');
}
}
3 changes: 3 additions & 0 deletions controllers/categories/_list_toolbar.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div data-control="toolbar">
<a href="<?= Backend::url('dshoreman/shop/categories/create') ?>" class="btn btn-primary oc-icon-plus">New Category</a>
</div>
31 changes: 31 additions & 0 deletions controllers/categories/config_form.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ===================================
# Form Behavior Config
# ===================================

# Record name
name: Category

# Model Form Field configuration
form: $/dshoreman/shop/models/category/fields.yaml

# Model Class name
modelClass: DShoreman\Shop\Models\Category

# Default redirect location
defaultRedirect: dshoreman/shop/categories

# Create page
create:
title: Create Category
redirect: dshoreman/shop/categories/update/:id
redirectClose: dshoreman/shop/categories

# Update page
update:
title: Edit Category
redirect: dshoreman/shop/categories
redirectClose: dshoreman/shop/categories

# Preview page
preview:
title: Preview Category
44 changes: 44 additions & 0 deletions controllers/categories/config_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ===================================
# List Behavior Config
# ===================================

# Model List Column configuration
list: $/dshoreman/shop/models/category/columns.yaml

# Model Class name
modelClass: DShoreman\Shop\Models\Category

# List Title
title: Manage Categories

# Link URL for each record
recordUrl: dshoreman/shop/categories/update/:id

# Message to display if the list is empty
noRecordsMessage: backend::lang.list.no_records

# Records to display per page
recordsPerPage: 25

# Displays the list column set up button
showSetup: true

# Displays the sorting link on each column
showSorting: true

# Default sorting column
defaultSort:
column: sort_order
direction: asc

# Display checkboxes next to each record
showCheckboxes: true

# Toolbar widget configuration
toolbar:
# Partial for toolbar buttons
buttons: list_toolbar

# Search widget configuration
search:
prompt: backend::lang.list.search_prompt
46 changes: 46 additions & 0 deletions controllers/categories/create.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('dshoreman/shop/categories') ?>">Categories</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<?= Form::open(['class'=>'layout-item stretch layout-column']) ?>

<?= $this->formRender() ?>

<div class="form-buttons layout-item fix">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="Creating Category..."
class="btn btn-primary">
Create
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="Creating Category..."
class="btn btn-default">
Create and Close
</button>
<span class="btn-text">
or <a href="<?= Backend::url('dshoreman/shop/categories') ?>">Cancel</a>
</span>
</div>
</div>

<?= Form::close() ?>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('dshoreman/shop/categories') ?>" class="btn btn-default">Return to categories list</a></p>

<?php endif ?>
2 changes: 2 additions & 0 deletions controllers/categories/index.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<?= $this->listRender() ?>
19 changes: 19 additions & 0 deletions controllers/categories/preview.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('dshoreman/shop/categories') ?>">Categories</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<div class="layout-item stretch layout-column form-preview">
<?= $this->formRenderPreview() ?>
</div>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('dshoreman/shop/categories') ?>" class="btn btn-default">Return to categories list</a></p>

<?php endif ?>
54 changes: 54 additions & 0 deletions controllers/categories/update.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('dshoreman/shop/categories') ?>">Categories</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<?= Form::open(['class'=>'layout-item stretch layout-column']) ?>

<?= $this->formRender() ?>

<div class="form-buttons layout-item fix">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-request-data="redirect:0"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="Saving Category..."
class="btn btn-primary">
<u>S</u>ave
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="Saving Category..."
class="btn btn-default">
Save and Close
</button>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="Deleting Category..."
data-request-confirm="Do you really want to delete this category?">
</button>
<span class="btn-text">
or <a href="<?= Backend::url('dshoreman/shop/categories') ?>">Cancel</a>
</span>
</div>
</div>

<?= Form::close() ?>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('dshoreman/shop/categories') ?>" class="btn btn-default">Return to categories list</a></p>

<?php endif ?>
3 changes: 3 additions & 0 deletions controllers/products/_list_toolbar.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div data-control="toolbar">
<a href="<?= Backend::url('dshoreman/shop/products/create') ?>" class="btn btn-primary oc-icon-plus">New Product</a>
</div>
31 changes: 31 additions & 0 deletions controllers/products/config_form.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ===================================
# Form Behavior Config
# ===================================

# Record name
name: Product

# Model Form Field configuration
form: $/dshoreman/shop/models/product/fields.yaml

# Model Class name
modelClass: DShoreman\Shop\Models\Product

# Default redirect location
defaultRedirect: dshoreman/shop/products

# Create page
create:
title: Create Product
redirect: dshoreman/shop/products/update/:id
redirectClose: dshoreman/shop/products

# Update page
update:
title: Edit Product
redirect: dshoreman/shop/products
redirectClose: dshoreman/shop/products

# Preview page
preview:
title: Preview Product
Loading

0 comments on commit f12756a

Please sign in to comment.