Skip to content

Commit

Permalink
#53, adding a working version with much to clean up abstract and make…
Browse files Browse the repository at this point in the history
… available for publication lists.
  • Loading branch information
ChrisFrench committed Oct 24, 2014
1 parent 3f7dcd2 commit 5da0883
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
26 changes: 26 additions & 0 deletions src/Admin/Controllers/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,32 @@ protected function doRead(array $data, $key=null)
$f3->reroute( $route );
}

public function togglePublish() {
$item = $this->getItem();

if($item->published == true) {
$item->set('published', false);
$label = 'label-danger';
} else {
$item->set('published', true);
$label = 'label-success';
}
$item->store();
return $this->outputJson($this->getJsonResponse(array(
'result' => $label
)));


//TODO when navigation is using publishabletrait use this
/*
return $this->outputJson($this->getJsonResponse(array(
'result' => $this->getItem()->publishableToggle()
)));
*/


}

protected function displayRead() {}

}
2 changes: 2 additions & 0 deletions src/Admin/Controllers/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ protected function getModel()
return $model;
}



public function index()
{
$f3 = \Base::instance();
Expand Down
3 changes: 2 additions & 1 deletion src/Admin/Models/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
namespace Admin\Models;

class Navigation extends \Dsc\Mongo\Collections\Navigation
{
{
use \Dsc\Traits\Models\Publishable;
/**
* Converts this to a search item, used in the search template when displaying each search result
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Admin/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,17 @@ public function initialize()
'action' => 'moveUp'
) );



$this->add( '/menu/movedown/@id', 'GET', array(
'controller' => 'Menu',
'action' => 'moveDown'
) );

$this->add( '/menu/publishtoggle/@id', 'POST', array(
'controller' => 'Menu',
'action' => 'togglePublish'
) );
$this->add( '/cache/opcache', 'GET', array(
'namespace' => '\Admin\Controllers\Cache',
'controller' => 'OpCache',
Expand Down
43 changes: 37 additions & 6 deletions src/Admin/Views/menus/list_datatable.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
<style>
.publication .label {
cursor:pointer;
}
.publication .label-success:before {
content: "Published";
}
.publication .label-default:before {
content: "Undefined";
}
.publication .label-secondary:before, .publication .label-danger:before {
content: "UnPublished";
}
</style>


<div class="no-padding">

<div class="row">
Expand Down Expand Up @@ -75,7 +91,7 @@
<?php if (!empty($paginated->items)) { ?>

<?php foreach($paginated->items as $item) { ?>
<tr>
<tr data-id="<?php echo $item->_id; ?>">
<td class="checkbox-column">
<input type="checkbox" class="icheck-input" name="ids[]" value="<?php echo $item->_id; ?>">
</td>
Expand Down Expand Up @@ -105,13 +121,13 @@
</a>
</td>

<td class="text-center">
<td class="text-center publication">
<?php if (!isset($item->published)) { ?>
<span class="label label-default">Undefined</span>
<span class="label label-default"> </span>
<?php } elseif ($item->published) { ?>
<span class="label label-success">Published</span>
<span class="label label-success"> </span>
<?php } else { ?>
<span class="label label-secondary">Unpublished</span>
<span class="label label-secondary"> </span>
<?php } ?>
</td>

Expand Down Expand Up @@ -168,4 +184,19 @@
</div>

</div>
<!-- /.no-padding -->
<!-- /.no-padding -->
<!-- SNIPPET FOR PUBLISH UNPUBLISH -->
<script type="text/javascript">

jQuery(document).ready(function(){
jQuery('.publication span.label').click(function(){
id = jQuery(this).closest('tr').data('id');
url = '/admin/menu/publishtoggle/' + id;
el = jQuery(this);
$.post( url, function( data ) {
el.removeClass().addClass('label ' + data.result);
});
});
});
</script>

0 comments on commit 5da0883

Please sign in to comment.