Added an enable/disable feature.
This commit is contained in:
parent
7ba8d76843
commit
a3941843b1
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ build : increment-build-number
|
||||
mkdir -p build/js
|
||||
cp src/www/*.* build
|
||||
cp -r resources/* build/.
|
||||
cp src/www/js/personal-display.js build/js/personal-display-$(VERSION).$(BUILD_NUMBER)js
|
||||
cp src/www/js/personal-display.js build/js/personal-display-$(VERSION).$(BUILD_NUMBER).js
|
||||
sed -i "s/%VERSION%/$(VERSION).$(BUILD_NUMBER)/g" build/index.html
|
||||
sass src/www/css/personal-display.scss build/css/personal-display.css
|
||||
tar czf personal-display-$(VERSION).$(BUILD_NUMBER).tar.gz build
|
||||
|
@ -1 +1 @@
|
||||
5
|
||||
19
|
||||
|
@ -46,6 +46,8 @@
|
||||
<span class=validate-tips></span>
|
||||
<section class=timestamper-config>
|
||||
<span class=config-section-header>TimeStamper</span>
|
||||
<div class=enabled><label>Enabled?</label>
|
||||
<input type=checkbox class=enabled></div>
|
||||
<div><label>Server Name: </label>
|
||||
<input type=text class=host></div>
|
||||
<div><label>Username: </label>
|
||||
@ -59,6 +61,8 @@
|
||||
</section>
|
||||
<section class=gtd-config>
|
||||
<span class=config-section-header>Getting Things Done</span>
|
||||
<div class=enabled><label>Enabled?</label>
|
||||
<input type=checkbox class=enabled></div>
|
||||
<div><label>Server Name: </label>
|
||||
<input type=text class=host></div>
|
||||
<div><label>Username: </label>
|
||||
|
@ -110,12 +110,13 @@
|
||||
"change .gtd-config .category" : "addCategory",
|
||||
"click .remove-button" : "removeCategory",
|
||||
|
||||
"click .save-button" : "saveAndClose" },
|
||||
"click .save-button" : "saveAndClose",
|
||||
"change input.enabled" : "enableDisable"},
|
||||
|
||||
initialize: function() {
|
||||
_.bindAll(this, "show", "hide", "tsLogin", "gtdLogin",
|
||||
"loadTsData", "loadGtdData", "addCategory", "makeCategoryItem",
|
||||
"removeCategory", "saveAndClose"); },
|
||||
_.bindAll(this, "addCategory", "enableDisable", "gtdLogin", "hide",
|
||||
"loadGtdData", "loadTsData", "makeCategoryItem", "removeCategory",
|
||||
"saveAndClose", "show", "tsLogin"); },
|
||||
|
||||
show: function() {
|
||||
var $tsSection = this.$el.find(".timestamper-config");
|
||||
@ -126,11 +127,13 @@
|
||||
$tsSection.find(".username").val(PD.tsCfg.username);
|
||||
$tsSection.find(".password").val(PD.tsCfg.password);
|
||||
$tsSection.find(".host").val(PD.tsCfg.host);
|
||||
$tsSection.find("input.enabled")[0].checked = PD.tsCfg.enabled;
|
||||
|
||||
if (PD.tsAuth) {
|
||||
this.loadTsData(PD.tsCfg.host, PD.tsCfg.username); }
|
||||
|
||||
this.$el.find('.timeline').val(PD.tsCfg.timelineId); }
|
||||
this.$el.find('.timeline').val(PD.tsCfg.timelineId);
|
||||
this.enableDisable({target: $tsSection.find("input.enabled")[0]}); }
|
||||
|
||||
// Or suggest a default server.
|
||||
else { $tsSection.find(".host").val("timestamper.jdb-labs.com"); }
|
||||
@ -140,12 +143,15 @@
|
||||
$gtdSection.find(".username").val(PD.gtdCfg.username);
|
||||
$gtdSection.find(".password").val(PD.gtdCfg.password);
|
||||
$gtdSection.find(".host").val(PD.gtdCfg.host);
|
||||
$gtdSection.find("input.enabled")[0].checked = PD.gtdCfg.enabled;
|
||||
|
||||
if (PD.gtdAuth) { this.loadGtdData(PD.gtdCfg.host); }
|
||||
|
||||
// Create the items for the selected categories
|
||||
$(".category-name").parent().remove();
|
||||
_.forEach(PD.gtdCfg.categories, this.makeCategoryItem); }
|
||||
_.forEach(PD.gtdCfg.categories, this.makeCategoryItem);
|
||||
|
||||
this.enableDisable({target: $gtdSection.find("input.enabled")[0]}); }
|
||||
|
||||
this.$el.find('.refresh-period').val(
|
||||
PD.refreshPeriod ? PD.refreshPeriod / 1000 : 15);
|
||||
@ -158,6 +164,7 @@
|
||||
var username = this.$el.find(".timestamper-config .username").val();
|
||||
var password = this.$el.find(".timestamper-config .password").val();
|
||||
var host = this.$el.find(".timestamper-config .host").val();
|
||||
var thisView = this;
|
||||
|
||||
if (!PD.tsCfg) { PD.tsCfg = {}; }
|
||||
|
||||
@ -185,7 +192,7 @@
|
||||
PD.tsAuth = false;
|
||||
|
||||
// Hide the wait overlay.
|
||||
this.$el.find(".wait-overlay").fadeOut(); },
|
||||
thisView.$el.find(".wait-overlay").fadeOut(); },
|
||||
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
PD.tsAuth = true;
|
||||
@ -196,7 +203,7 @@
|
||||
PD.configDialog.loadTsData(host, username);
|
||||
|
||||
// Hide the wait overlay.
|
||||
this.$el.find(".wait-overlay").fadeOut(); }
|
||||
thisView.$el.find(".wait-overlay").fadeOut(); }
|
||||
});
|
||||
|
||||
},
|
||||
@ -205,6 +212,7 @@
|
||||
var username = this.$el.find(".gtd-config .username").val();
|
||||
var password = this.$el.find(".gtd-config .password").val();
|
||||
var host = this.$el.find(".gtd-config .host").val();
|
||||
var thisView = this;
|
||||
|
||||
if (!PD.gtdCfg) { PD.gtdCfg = {}; }
|
||||
|
||||
@ -230,7 +238,7 @@
|
||||
"trying to log into the Getting Things Done service: " +
|
||||
error); }
|
||||
PD.gtdAuth = false;
|
||||
this.$el.find(".wait-overlay").fadeOut(); },
|
||||
thisView.$el.find(".wait-overlay").fadeOut(); },
|
||||
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
PD.gtdAuth = true;
|
||||
@ -238,7 +246,7 @@
|
||||
$(".validate-tips").text("");
|
||||
|
||||
PD.configDialog.loadGtdData(host);
|
||||
this.$el.find(".wait-overlay").fadeOut(); }
|
||||
thisView.$el.find(".wait-overlay").fadeOut(); }
|
||||
});
|
||||
|
||||
},
|
||||
@ -250,7 +258,6 @@
|
||||
url: 'https://' + host + '/ts_api/timelines/' + username,
|
||||
xhrFields: { withCredentials: true },
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
debugger;
|
||||
PD.tsCfg.timelines = data;
|
||||
|
||||
// Populate the available timelines list.
|
||||
@ -268,7 +275,7 @@
|
||||
|
||||
|
||||
// Load the user's contexts
|
||||
var contextedLoaded = $.ajax({
|
||||
var contextLoaded = $.ajax({
|
||||
url: 'http://' + host + '/gtd/contexts',
|
||||
xhrFields: { withCredentials: true },
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
@ -294,7 +301,7 @@
|
||||
$optionEl.attr("value", category.id);
|
||||
$optionEl.text(category.id);
|
||||
$categorySelectEl.append($optionEl); });
|
||||
$categorySelectEl[0].selectedIndex = 0; }},
|
||||
$categorySelectEl[0].selectedIndex = 0; }); },
|
||||
|
||||
makeCategoryItem: function(catName) {
|
||||
var $liEl = $(
|
||||
@ -313,6 +320,18 @@
|
||||
removeCategory: function(source) {
|
||||
$(source.target).parent().remove(); },
|
||||
|
||||
enableDisable: function (e) {
|
||||
var cbEl = e.target;
|
||||
var $cbEl = $(cbEl);
|
||||
var $section = $cbEl.closest('section');
|
||||
|
||||
if (cbEl.checked) {
|
||||
$section.find('div, ul').show(); }
|
||||
|
||||
else {
|
||||
$section.find('div, ul').hide();
|
||||
$section.find('div.enabled').show(); } },
|
||||
|
||||
saveAndClose: function() {
|
||||
if (!PD.tsCfg) { PD.tsCfg = {}; }
|
||||
if (!PD.gtdCfg) { PD.gtdCfg = {}; }
|
||||
@ -323,12 +342,14 @@
|
||||
PD.tsCfg.username = $tsEl.find(".username").val();
|
||||
PD.tsCfg.password = $tsEl.find(".password").val();
|
||||
PD.tsCfg.timelineId = $tsEl.find(".timeline").val();
|
||||
PD.tsCfg.enabled = $tsEl.find("input.enabled")[0].checked;
|
||||
|
||||
// Save Getting Things Done configuration.
|
||||
var $gtdEl = this.$el.find(".gtd-config");
|
||||
PD.gtdCfg.host = $gtdEl.find(".host").val();
|
||||
PD.gtdCfg.username = $gtdEl.find(".username").val();
|
||||
PD.gtdCfg.password = $gtdEl.find(".password").val();
|
||||
PD.gtdCfg.enabled = $gtdEl.find("input.enabled")[0].checked;
|
||||
PD.gtdCfg.categories = _.map(
|
||||
this.$el.find(".category-name"),
|
||||
function(span) { return $(span).text(); });
|
||||
@ -342,7 +363,7 @@
|
||||
localStorage.setItem("refreshPeriod",
|
||||
JSON.stringify(PD.refreshPeriod)); }
|
||||
|
||||
this.hide();
|
||||
this.hide(400, PD.main.refresh);
|
||||
}
|
||||
});
|
||||
|
||||
@ -399,7 +420,7 @@
|
||||
|
||||
// Check that we are authenticated to the services we need. Try to
|
||||
// authenticate if we are not.
|
||||
if (!PD.tsAuth) {
|
||||
if (PD.tsCfg.enabled && !PD.tsAuth) {
|
||||
$.ajax({
|
||||
url: "https://" + PD.tsCfg.host + "/ts_api/login",
|
||||
xhrFields: { withCredentials: true },
|
||||
@ -420,7 +441,7 @@
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
PD.tsAuth = true; }}); }
|
||||
|
||||
if (!PD.gtdAuth) {
|
||||
if (PD.gtdCfg.enabled && !PD.gtdAuth) {
|
||||
$.ajax({
|
||||
url: "http://" + PD.gtdCfg.host + "/gtd/login",
|
||||
xhrFields: { withCredentials: true },
|
||||
@ -444,9 +465,12 @@
|
||||
|
||||
// Check that we have successfully authenticated to both services.
|
||||
// If we are not, we will skip this refresh.
|
||||
if (!(PD.tsAuth && PD.gtdAuth)) { return; }
|
||||
if ((PD.tsCfg.enabled && !PD.tsAuth) ||
|
||||
(PD.gtdCfg.enabled && !PD.gtdAuth)) { return; }
|
||||
|
||||
// Get the latest timestamp from the TimeStamper service.
|
||||
if (PD.tsCfg.enabled) {
|
||||
$("section#current-task").show();
|
||||
$.ajax({
|
||||
url: "https://" + PD.tsCfg.host + "/ts_api/entries/" +
|
||||
PD.tsCfg.username + "/" + PD.tsCfg.timelineId,
|
||||
@ -459,17 +483,23 @@
|
||||
error: function(jqXHR, textStatus, errorText) {
|
||||
if (jqXHR.status == 401) { PD.tsAuth = false; }
|
||||
else {
|
||||
alert("Unable to retrieve current timestamp: " + errorText);
|
||||
alert("Unable to retrieve current timestamp: " +
|
||||
errorText);
|
||||
PD.configDialog.show(); } },
|
||||
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
PD.currentActivityModel.set(data[0]); } });
|
||||
PD.currentActivityModel.set(data[0]); } }); }
|
||||
|
||||
// If the TimeStamper section is not enabled, hide the UI for it
|
||||
else $("section#current-task").hide();
|
||||
|
||||
// Get the list of GTD entries for each of our categories.
|
||||
if (PD.gtdCfg.enabled) {
|
||||
var categories = _.reduce(
|
||||
PD.gtdCfg.categories,
|
||||
function(acc, cat) { return acc ? acc + "," + cat : cat; }, "");
|
||||
|
||||
$("section#priorities").show();
|
||||
$.ajax({
|
||||
url: "http://" + PD.gtdCfg.host + "/gtd/next-actions/" +
|
||||
categories,
|
||||
@ -482,7 +512,8 @@
|
||||
if (jqXHR.status == 401) { PD.gtdAtuh = false; }
|
||||
else if (jqXHR.status == 500) { return; }
|
||||
else {
|
||||
alert("Unable to retrieve next actions: " + errorText);
|
||||
alert("Unable to retrieve next actions: " +
|
||||
errorText);
|
||||
PD.configDialog.show(); } },
|
||||
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
@ -503,7 +534,10 @@
|
||||
// longer in our retrieved data and remove them.
|
||||
collection.forEach(function(model) {
|
||||
if (!_.any(data, model.equals)) {
|
||||
collection.remove(model); }}); } });
|
||||
collection.remove(model); }}); } }); }
|
||||
|
||||
// If the GTD section is not enabled, hid the UI.
|
||||
else $("section#priorities").hide();
|
||||
|
||||
if (evt) evt.preventDefault();
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user