Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move regitration to template based rendering #41

Merged
merged 1 commit into from
Jul 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 15 additions & 37 deletions _admin/art.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,28 @@
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once('class.RegisterAdminPage.php');
$page = new RegisterAdminPage('Burning Flipside - Tickets');

$page->addWellKnownJS(JS_DATATABLE);
$page->addWellKnownCSS(CSS_DATATABLE);
$page->addWellKnownJS(JS_BOOTBOX);
$page->addJSByURI('js/art.js');
$page = new RegisterAdminPage('Burning Flipside - Registration');
$page->setTemplateName('@Register/reg-admin.html');

if(!$page->is_art_admin)
{
$page->body .= '<div class="row"><h1>Not an art admin!</h1>/div>';
$page->setTemplateName('admin.html');
$page->body .= '<div class="row"><h1>Not an art admin!</h1>/div>';
}
else
{
$page->body .= '
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Art Project</h1>
</div>
</div>
<div class="row">
<a class="dl_link" href="../api/v1/art?fmt=csv&filter=year eq 2018&no_logo">Big Spreadsheet of Everything</a> |
<a class="dl_link" href="../api/v1/art/*/artLead?fmt=csv">Art Leads</a> |
<a class="dl_link" href="../api/v1/art/*/soundLead?fmt=csv">Sound Leads</a> |
<a class="dl_link" href="../api/v1/art/*/safetyLead?fmt=csv">Safety Leads</a> |
<a class="dl_link" href="../api/v1/art/*/cleanupLead?fmt=csv">Cleanup Leads</a>
Format Preference: <select id="dlFormat" onChange="changeDLType()">
<option value="csv" selected="selected">Comma Sepearated Value (.csv)</option>
<option value="xls">Excel 97-2003 (.xls)</option>
<option value="xlsx">Excel Workbook (.xlsx)</option>
</select>
</div>
<div class="row">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#coltoggle" aria-expanded="false" aria-controls="coltoggle">
Toggle Columns
</button>
<div class="collapse" id="coltoggle"></div>
<table id="art" class="table">
<thead></thead>
<tbody></tbody>
</table>
</div>
';
$page->content['title'] = 'Art Projects';
$page->content['reports'] = array(
array('link'=>'../api/v1/art?fmt=csv&filter=year eq current&no_logo', 'title'=>'Big Spreadsheet of Everything'),
array('link'=>'../api/v1/art/*/artLead?fmt=csv&filter=year eq current', 'title'=>'Art Leads'),
array('link'=>'../api/v1/art/*/soundLead?fmt=csv&filter=year eq current', 'title'=>'Sound Leads'),
array('link'=>'../api/v1/art/*/safetyLead?fmt=csv&filter=year eq current', 'title'=>'Safety Leads'),
array('link'=>'../api/v1/art/*/cleanupLead?fmt=csv&filter=year eq current', 'title'=>'Cleanup Leads')
);
$page->content['endpoint'] = 'art';
$page->content['editUri'] = '../art_reg.php';
}

$page->print_page();
$page->printPage();
// vim: set tabstop=4 shiftwidth=4 expandtab:

9 changes: 8 additions & 1 deletion _admin/class.RegisterAdminPage.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
require_once('class.FlipSession.php');
require_once('../../class.SecurePage.php');
class RegisterAdminPage extends \Http\FlipAdminPage
{
use SecureWebPage;

public $is_tc_admin;
public $is_art_admin;
public $is_dmv_admin;
Expand All @@ -15,6 +18,9 @@ function __construct($title)
$this->is_dmv_admin = false;
$this->is_event_admin = false;
parent::__construct($title, 'RegistrationAdmins');
$this->addTemplateDir('../../templates', 'Secure');
$this->addTemplateDir('../templates', 'Register');
$this->secure_root = $this->getSecureRoot();
if($this->user !== false && $this->user !== null)
{
if($this->user->isInGroupNamed('RegistrationAdmins'))
Expand Down Expand Up @@ -65,7 +71,7 @@ function __construct($title)
}
if($this->is_dmv_admin)
{
$this->content['header']['sidebar']['Art Cars'] = array('icon' => 'fa-car', 'menu' => 'dmv.php');
$this->content['header']['sidebar']['Art Cars'] = array('icon' => 'fa-car', 'url' => 'dmv.php');
}
if($this->is_event_admin)
{
Expand All @@ -75,6 +81,7 @@ function __construct($title)
{
$this->content['header']['sidebar']['Variables'] = array('icon' => 'fa-cog', 'url' => 'vars.php');
}
$this->content['loginUrl'] = $this->secure_root.'api/v1/login';
}

public function isAdmin()
Expand Down
38 changes: 10 additions & 28 deletions _admin/dmv.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,24 @@
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once('class.RegisterAdminPage.php');
$page = new RegisterAdminPage('Burning Flipside - Tickets');

$page->addWellKnownJS(JS_DATATABLE);
$page->addWellKnownCSS(CSS_DATATABLE);
$page->addWellKnownJS(JS_BOOTBOX);
$page->addJSByURI('js/dmv.js');
$page = new RegisterAdminPage('Burning Flipside - Registration');
$page->setTemplateName('@Register/reg-admin.html');

if(!$page->is_dmv_admin)
{
$page->setTemplateName('admin.html');
$page->body .= '<div class="row"><h1>Not a DMV admin!</h1>/div>';
}
else
{
$page->body .= '
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">DMV</h1>
</div>
</div>
<div class="row">
<a class="dl_link" href="../api/v1/dmv?fmt=csv&filter=year eq current&no_logo">Big Spreadsheet of Everything</a>
Format Preference: <select id="dlFormat" onChange="changeDLType()">
<option value="csv" selected="selected">Comma Sepearated Value (.csv)</option>
<option value="xls">Excel 97-2003 (.xls)</option>
<option value="xlsx">Excel Workbook (.xlsx)</option>
</select>
</div>
<div class="row">
<table id="dmv" class="table">
<thead></thead>
<tbody></tbody>
</table>
</div>
';
$page->content['title'] = 'DMV';
$page->content['reports'] = array(
array('link'=>'../api/v1/dmv?fmt=csv&filter=year eq current&no_logo', 'title'=>'Big Spreadsheet of Everything')
);
$page->content['endpoint'] = 'dmv';
$page->content['editUri'] = '../artCar_reg.php';
}

$page->print_page();
$page->printPage();
// vim: set tabstop=4 shiftwidth=4 expandtab:

47 changes: 14 additions & 33 deletions _admin/evt.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,28 @@
error_reporting(E_ALL);
require_once('class.RegisterAdminPage.php');
$page = new RegisterAdminPage('Burning Flipside - Events');

$page->addWellKnownJS(JS_DATATABLE, false);
$page->addWellKnownCSS(CSS_DATATABLE, false);
$page->addWellKnownJS(JS_BOOTBOX);
$page->addJSByURI('js/evt.js');
$page->setTemplateName('@Register/reg-admin.html');

if(!$page->is_event_admin)
{
$page->setTemplateName('admin.html');
$page->body .= '<div class="row"><h1>Not an Event admin!</h1>/div>';
}
else
{
$page->body .= '
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Events</h1>
</div>
</div>
<div class="row">
<a class="dl_link" href="../api/v1/event?fmt=csv">Data Dump Of Doom</a> |
<a class="dl_link" href="../api/v1/event?no_logo=1&fmt=csv">No logos</a> |
<a class="dl_link" href="../api/v1/event?no_logo=1&$filter=year eq current and Thursday eq true&fmt=csv">Thursday</a> |
<a class="dl_link" href="../api/v1/event?no_logo=1&$filter=year eq current and Friday eq true&fmt=csv">Friday</a> |
<a class="dl_link" href="../api/v1/event?no_logo=1&$filter=year eq current and Saturday eq true&fmt=csv">Saturday</a> |
<a class="dl_link" href="../api/v1/event?no_logo=1&$filter=year eq current and Sunday eq true&fmt=csv">Sunday</a> |
<a class="dl_link" href="../api/v1/event?no_logo=1&$filter=year eq current and Monday eq true&fmt=csv">Monday</a>
Format Preference: <select id="dlFormat" onChange="changeDLType()">
<option value="csv" selected="selected">Comma Sepearated Value (.csv)</option>
<option value="xls">Excel 97-2003 (.xls)</option>
<option value="xlsx">Excel Workbook (.xlsx)</option>
</select>
</div>
<div class="row">
<table id="evt" class="table">
<thead></thead>
<tbody></tbody>
</table>
</div>
';
$page->content['title'] = 'Events';
$page->content['reports'] = array(
array('link'=>'../api/v1/event?fmt=csv&filter=year eq current&no_logo', 'title'=>'Big Spreadsheet of Everything'),
array('link'=>'../api/v1/event?fmt=csv&filter=year eq current and Thursday eq true&no_logo', 'title'=>'Thursday'),
array('link'=>'../api/v1/event?fmt=csv&filter=year eq current and Friday eq true&no_logo', 'title'=>'Friday'),
array('link'=>'../api/v1/event?fmt=csv&filter=year eq current and Saturday eq true&no_logo', 'title'=>'Saturday'),
array('link'=>'../api/v1/event?fmt=csv&filter=year eq current and Sunday eq true&no_logo', 'title'=>'Sunday'),
array('link'=>'../api/v1/event?fmt=csv&filter=year eq current and Monday eq true&no_logo', 'title'=>'Monday')
);
$page->content['endpoint'] = 'event';
$page->content['editUri'] = '../event_reg.php';
}

$page->print_page();
$page->printPage();
// vim: set tabstop=4 shiftwidth=4 expandtab:

115 changes: 115 additions & 0 deletions _admin/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
function getAPICall()
{
var finished = getParameterByName('finished');
var filter = '';
if(finished !== null)
{
filter = '&$filter=final eq true and year eq current';
}
return '../api/v1/'+$('#listTable').data('source')+'?no_logo=1&fmt=json-ss'+filter;
}

function getEditPage()
{
return $('#listTable').data('editor');
}

function renderName(data, type, row)
{
return '<a href="'+getEditPage()+'?id='+row[1]+'&is_admin=true">'+data+'</a>';
}

var renderers = [
{'name': renderName}
];

function dataObtained(data)
{
if(data.length === 0) return;
var columns = [{
'data': null,
'defaultContent': '<button name="del"><span class="fa fa-remove"></span></button> <button name="unlock"><span class="fa fa-unlock"></span></button>'
}];
var toggles = $('#coltoggle');
var idIndex = -1;
var nameIndex = -1;
for(var_name in data[0])
{
var col = {};
col.title = var_name;
for(i = 0; i < renderers.length; i++)
{
if(renderers[i][var_name] !== undefined)
{
col.render = renderers[i][var_name];
}
}
if($.inArray(var_name, hidden) !== -1)
{
col.visible=false;
}
var len = columns.push(col);
if(col.title === 'name')
{
nameIndex = len-1;
}
else if(col.title === '_id')
{
idIndex = len-1;
}
toggles.append('<a class="toggle-vis" data-column="'+var_name+'">'+var_name+'</a> | ');
}
$.fn.dataTable.ext.errMode = 'none';
$('#listTable').dataTable({
'colReorder': true,
'data': [],
'columns': columns
});
var table = $('#listTable').DataTable();
for(i = 0; i < data.length; i++)
{
var obj = data[i];
var arr = [];
for(j = 0; j < columns.length; j++)
{
if(obj[columns[j].title] !== undefined)
{
arr.push(obj[columns[j].title]);
}
else
{
arr.push(null);
}
}
table.row.add(arr);
}
table.colReorder.move(idIndex, 1);
table.colReorder.move(nameIndex, 2);
table.order([2, 'desc']);
table.draw(false);
$('a.toggle-vis').on('click', function (e){
e.preventDefault();
// Get the column API object
var column = table.column(":contains("+$(this).attr('data-column')+")");
// Toggle the visibility
column.visible( ! column.visible() );
});
}

function changeDLType()
{
var format = $('#dlFormat').val();
var links = $('.dl_link').each(function(){
this.href = this.href.replace(/(fmt=)[^\&]+/, '$1'+format);
});
}

function initPage()
{
$.ajax({
url: getAPICall(),
success: dataObtained
});
}

$(initPage);
10 changes: 0 additions & 10 deletions _admin/js/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ var hidden = [
'_id'
];

function changeDLType()
{
var format = $('#dlFormat').val();
var links = $('.dl_link').each(function(){
this.href = this.href.replace(/(fmt=)[^\&]+/, '$1'+format);
});
}

function get_id_for_event(trigger)
{
var tr = $(trigger).closest('tr');
Expand Down Expand Up @@ -143,5 +135,3 @@ function tc_page_loaded()
$('#tc tbody').on('click', 'button[name="unlock"]', unlockObject);
$('#tc tbody').on('click', 'button[name="structs"]', getStructs);
}

$(tc_page_loaded);
Loading