Skip to content

Commit

Permalink
Added cheesto to new Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
lfkeitel committed Mar 7, 2015
1 parent 00b5594 commit 7930beb
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 13 deletions.
53 changes: 47 additions & 6 deletions app/templates/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/**
* Dashboard page
*/
$this->layout('layouts::main', ['requiredCssFiles' => ['dashboard', 'jqueryui', 'jhtmlarea']]);
$this->layout('layouts::main', ['requiredCssFiles' => ['dashboard', 'jqueryui', 'jhtmlarea', 'datetimepicker']]);
?>
<div id="add-edit-form">
<div id="add-edit-form" class="hidden-dialog">
<form>
Title: <input type="text" id="log-title" value="" size="60"><br><br>
<textarea id="log-body" cols="80" rows="10"></textarea><br>
Expand All @@ -13,12 +13,53 @@
<div id="messages"></div>
</div>

<div id="cheesto-status-form" class="hidden-dialog">
<form>
<fieldset class="outer">
Time Quick Set:
<table>
<tr>
<td>10 Minutes<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(10);"></td>
<td>20 Minutes<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(20);"></td>
</tr>
<tr>
<td>30 Minutes<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(30);"></td>
<td>40 Minutes<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(40);"></td>
</tr>
<tr>
<td>50 Minutes<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(50);"></td>
<td>1 Hour<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(60);">
</tr>
<tr>
<td>1 Hour 15 Min.<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(75);"></td>
<td>1 Hour 30 Min.<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(90);"></td>
</tr>
<tr>
<td>1 Hour 45 Min.<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(105);"></td>
<td>2 Hours<input type="radio" name="quicktime" onClick="Cheesto.setDateTime(120);"></td>
</tr>
</table>
</fieldset>

<fieldset class="outer">
<fieldset>
<label for="cheesto-date-pick">Return Time:</label>
<input type="text" id="cheesto-date-pick" value="Today">
</fieldset>
<fieldset>
<label for="cheesto-message-text">Message:</label>
<textarea id="cheesto-message-text" cols="25" rows="10"></textarea>
</fieldset>
</fieldset>
</form>
</div>

<button type="button" class="section-title disabled" id="show-cheesto-button">Show Message Center</button>

<section id="messages-panel" class="messages-panel">
<?php if ($showCheesto): ?>
<div class="messages-cheesto">
<div class="messages-cheesto-header">
<div id="messages-cheesto">
<div id="messages-cheesto-header">
<span class="messages-title">Ĉeesto</span>

<div class="messages-controls">
Expand All @@ -28,7 +69,7 @@
</div>
</div>

<div id="cheesto-status-table" class="messages-cheesto-content"></div>
<div id="messages-cheesto-content">Loading...</div>
</div>
<?php endif; ?>

Expand Down Expand Up @@ -72,4 +113,4 @@
<?php endif; ?>
</section>

<?= $this->loadJS(['jquery', 'jqueryui', 'jhtmlarea', 'common', 'categories', 'dashboard']) ?>
<?= $this->loadJS(['jquery', 'jqueryui', 'jhtmlarea', 'timepicker', 'common', 'categories', 'cheesto', 'dashboard']) ?>
163 changes: 163 additions & 0 deletions public/source/js/cheesto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/* global $, setTimeout */

"use strict"; // jshint ignore:line

var Cheesto =
{
firstgen: true,

dashboardInit: function() {
Cheesto.getStatuses();
},

getStatuses: function () {
$.getJSON("api/i/cheesto/read",
function (data) {
if (data.errorcode == 5) {
return;
}

Cheesto.generateView(data.data);

if (Cheesto.firstgen) {
setTimeout(Cheesto.getStatuses, 30000);
}
});
},

generateView: function (dataObj) {
Cheesto.generateTable(dataObj);
if (Cheesto.firstgen) {
Cheesto.makeStatusSelect(dataObj);
}
return;
},


makeStatusSelect: function (dataObj) {
var statusSelect = $('<select/>').attr('id', 'status-select');
statusSelect.change(Cheesto.setStatus);

statusSelect.append('<option value="-1">Set Status:</option>');

for (var key2 in dataObj.statusOptions) {
var html = '<option value="' + dataObj.statusOptions[key2] + '">' + dataObj.statusOptions[key2] + '</option>';
statusSelect.append(html);
}

$('#status-select').replaceWith(statusSelect);
Cheesto.firstgen = false;
return;
},

generateTable: function (dataObj) {
var div = $('<div/>').attr('id', 'messages-cheesto-content');
var table = $('<table/>');
table.append('<thead><tr><td>Name</td><td>Status</td></tr></thead><tbody>');

for (var key in dataObj) {
if (dataObj.hasOwnProperty(key)) {
if (key !== "statusOptions") {
var user = dataObj[key];

var html = '<tr><td>' + user.realname + '</td>'+
'<td class="status-cell" title="' + user.message + '&#013;Return: ' + user.returntime + '">'+
user.status + '</td></tr>';

table.append(html);
}
}
}

table.append('</tbody>');
div.append(table);
$('#messages-cheesto-content').replaceWith(div);

$('td.status-cell').tooltip({
track: true,
show: {
effect: 'fade',
delay: 50
}
});
return;
},

setStatus: function () {
var newStatus = $("#status-select").val();

if (newStatus != 'Available') {
// Status requires a return time and optional message
$('#cheesto-status-form').dialog({
height: 440,
width: 640,
title: 'Ĉeesto Status',
modal: true,
open: function(evt, ui) {
$('#cheesto-date-pick').datetimepicker({
timeFormat: "HH:mm",
controlType: 'select',
stepMinute: 10,
});
},
show: {
effect: 'fade',
duration: 500
},
hide: {
effect: 'fade',
duration: 500
},
buttons: {
'Save': function() {
Cheesto.processStatus(newStatus);
},
Cancel: function() {
$(this).dialog('close');
$("#status-select").prop("selectedIndex", 0);
}
}
});
} else {
// Status is Available
Cheesto.sendNewStatus(newStatus, '00:00:00', '');
}
},

processStatus: function(status) {
var message = $('#cheesto-message-text');
var returnTime = $('#cheesto-date-pick');

Cheesto.sendNewStatus(status, returnTime.val(), message.val());
$('#cheesto-status-form').dialog('close');

$("#status-select").prop("selectedIndex", 0);
message.val('');
returnTime.val('Today');
},

sendNewStatus: function (stat, rt, message) {
$.post('api/i/cheesto/update', {status: stat, returntime: rt, message: message})
.done(function() { Cheesto.getStatuses(); });
},

setDateTime: function(delta) {
var currentdate = new Date();

var minutes = currentdate.getMinutes()+(delta % 60);
var hours = currentdate.getHours()+((delta-(delta % 60))/60);

if (minutes > 59) {
minutes = minutes - 60;
hours++;
}

var datetime = ('0' + (currentdate.getMonth()+1)).slice(-2) + '/' +
('0' + currentdate.getDate()).slice(-2) + '/' +
currentdate.getFullYear() + ' ' +
('0' + hours).slice(-2) + ':' +
('0' + minutes).slice(-2);

$('#cheesto-date-pick').val(datetime);
}
};
4 changes: 2 additions & 2 deletions public/source/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Scripts for Dashboard
*/
/* global document, window, searchFun, $, setInterval,
setTimeout, clearInterval, console, Categories, alert */
setTimeout, clearInterval, Categories, Cheesto */

"use strict"; // jshint ignore:line

Expand All @@ -13,6 +13,7 @@ $(document).ready(function() {
Refresh.init();
View.init();
Search.init();
Cheesto.dashboardInit();

$('#show-cheesto-button').click(function() {
Section.show(this, 'messages-panel');
Expand Down Expand Up @@ -288,7 +289,6 @@ var AddEdit =
$.alert(json.data, 'Create Log', function() {
$('#add-edit-form').dialog('close');
});
console.log(json.data);
}, 'json');
} else {
$('#messages').html('<span class="bad">Log entries must have a title, category, and entry text.</span>').fadeIn();
Expand Down
33 changes: 28 additions & 5 deletions public/source/less/dashboard.less
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
height: initial;
});

#add-edit-form {
display: none;
}

.section-title {
font-size: 1.5em;
width: 100%;
Expand Down Expand Up @@ -93,7 +89,7 @@
}
}

.messages-cheesto {
#messages-cheesto {
.messages-common-styles();

#status-select {
Expand Down Expand Up @@ -221,3 +217,30 @@
}
}
}

#cheesto-status-form {
fieldset {
border: none;

table {
margin-top: 10px;

td {
border: 1px solid black;
padding: 5px;

input {
margin-left: 5px;
}
}
}

label {
display: block;
}

&.outer {
float: left;
}
}
}
16 changes: 16 additions & 0 deletions public/source/less/datetimepicker.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* css for timepicker */
.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
.ui-timepicker-div dl { text-align: left; }
.ui-timepicker-div dl dt { float: left; clear:left; padding: 0 0 0 5px; }
.ui-timepicker-div dl dd { margin: 0 10px 10px 45%; }
.ui-timepicker-div td { font-size: 90%; }
.ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }

.ui-timepicker-rtl{ direction: rtl; }
.ui-timepicker-rtl dl { text-align: right; padding: 0 5px 0 0; }
.ui-timepicker-rtl dl dt{ float: right; clear: right; }
.ui-timepicker-rtl dl dd { margin: 0 45% 10px 10px; }

div.ui-datepicker{
font-size:15px;
}
4 changes: 4 additions & 0 deletions public/source/less/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ a {
display: initial !important;
}

.hidden-dialog {
display: none;
}

@import "header";
@import "footer";

Expand Down

0 comments on commit 7930beb

Please sign in to comment.