Permalink
Browse files

Merge pull request #85 from edchat/date

Show the reminder date in red if it is in the past, and dont allow reminder dates to be set in the past. Fix for issue #62
  • Loading branch information...
2 parents 781dc43 + 906bb01 commit eae7d42e9a8aaa2a7ebc136764628ce83f9a701c @edchat committed Jun 1, 2012
View
@@ -23,6 +23,16 @@ html,body {
margin-left: 10px;
margin-right: 10px;
}
+
+.dateLabel {
+ font-size: .6em;
+ color: #324f85;
+}
+
+.dateLabelInvalid {
+ color: red;
+}
+
/*
button.baseBtn {
-webkit-background-clip: padding-box;
View
@@ -16,6 +16,7 @@
mblHideAddressBar: false,
mblAndroidWorkaround: false,
mblAlwaysHideAddressBar: false,
+ app: {debugApp: 1}, // set debugApp to log app transtions and view activate/deactivate
async: 1">
</script>
<script>
@@ -1,5 +1,4 @@
<div style="background:#c5ccd3;" class="view mblView">
- <script type="dojo/require">at: "dojox/mvc/at"</script>
<h1 data-dojo-type="dojox.mobile.Heading" label="Remind Me" back="Back"></h1>
<ul data-dojo-type="dojox.mobile.RoundRectList">
<li data-dojo-type="dojox.mobile.ListItem">
@@ -22,5 +21,6 @@ <h1 data-dojo-type="dojox.mobile.Heading" label="Date Picker">
<span data-dojo-type="dojox.mobile.ToolBarButton" id="reminddlgCancel" label="Cancel" class="mblColorBlue" style="position:absolute;width:45px;left:0;"></span>
</h1>
<div id="reminddlgpicker1" data-dojo-type="dojox.mobile.DatePicker"></div>
+ <div id="invalidDate" style="visibility:hidden; color:red;">Invalid date, the date can not be in the past!</div>
</div>
</div>
@@ -16,7 +16,8 @@ <h1 data-dojo-type="dojox.mobile.Heading" region="top" label="Details">
<ul data-dojo-type="dojox.mobile.RoundRectList">
<li id="detail_reminder" data-dojo-type="dojox.mobile.ListItem" clickable="true" transitionOptions='{title:"Remind",target:"details,EditItemRemindMe",url: "#details,EditItemRemindMe"}'>
<div data-dojo-type="dojox.mvc.Output" class="mblListItemRightText"
- data-dojo-props="value: at('rel:','reminderDate')"></div>
+ data-dojo-props="value: at('rel:','reminderDate'),
+ class: at('rel:','reminderDate').transform(dateClassTransform2)"></div>
Remind Me
</li>
@@ -20,8 +20,9 @@ <h2 data-dojo-type="dojox.mobile.RoundRectCategory" region="top">All items by da
<tr>
<td></td>
<td>
- <div data-dojo-type="dojox.mvc.Output" style="font-size: .6em; color: #324f85;"
- data-dojo-props="value: at('rel:#{this.index}','reminderDate')"></div>
+ <div data-dojo-type="dojox.mvc.Output" class="dateLabel"
+ data-dojo-props="value: at('rel:#{this.index}','reminderDate'),
+ class: at('rel:#{this.index}','reminderDate').direction(at.from).transform(dateListClassTransform)"></div>
</td>
</tr>
</table>
@@ -1,15 +1,14 @@
define(["dojo/dom", "dojo/_base/lang", "dojo/dom-style", "dojo/on", "dijit/registry", "dojox/mvc/at",
- "dojo/date/stamp"],
-function(dom, lang, domStyle, on, registry, at, datestamp){
+ "dojo/date/stamp", "dojo/dom-class"],
+function(dom, lang, domStyle, on, registry, at, stamp, domClass){
var itemlistmodel = null;
var signals = [];
var showDateDialog = function(widgetid){
var datamodel = itemlistmodel.model[todoApp.selected_item];
date = datamodel.get("reminderDate");
if(!date){
- var today = new Date();
- date = datestamp.toISOString(today, {selector: "date"});
+ date = stamp.toISOString(new Date(), {selector: "date"});
}
//console.log("remind showDateDialog date = ", date);
registry.byId("reminddlgpicker1").set("value", date);
@@ -30,7 +29,13 @@ function(dom, lang, domStyle, on, registry, at, datestamp){
//set remind time
widget = registry.byId('remind_date');
if (widget) {
- widget.set("label", at(datamodel, "reminderDate"));
+ widget.set("label", at(datamodel, "reminderDate"));
+ var value = datamodel.get("reminderDate");
+ if(value && value < stamp.toISOString(new Date(), {selector: "date"})){
+ domClass.add(widget.domNode, "dateLabelInvalid");
+ }else{
+ domClass.remove(widget.domNode, "dateLabelInvalid");
+ }
if(datamodel.reminderOnAday == "on"){
domStyle.set(dom.byId('remind_date'), 'display', '');
}else{
@@ -81,13 +86,24 @@ function(dom, lang, domStyle, on, registry, at, datestamp){
// update remind on a day value to the data model
var datamodel = this.loadedModels.itemlistmodel.model[todoApp.selected_item];
date = registry.byId("reminddlgpicker1").get("value");
- datamodel.set("reminderDate", date);
- registry.byId('datePicker').hide(true)
+ // have to check to see if the date is valid
+ var todayDate = stamp.toISOString(new Date(), {selector: "date"});
+ if(date < todayDate){
+ domStyle.set(dom.byId("invalidDate"), "visibility", "visible");
+ registry.byId("reminddlgpicker1").set("value", todayDate);
+
+ }else{
+ datamodel.set("reminderDate", date);
+ domClass.remove(registry.byId('remind_date').domNode, "dateLabelInvalid");
+ registry.byId('datePicker').hide(true);
+ domStyle.set(dom.byId("invalidDate"), "visibility", "hidden");
+ }
}));
signals.push(signal);
signal = on(dom.byId("reminddlgCancel"), "click", lang.hitch(this, function(){
//console.log("reminddlgCancel clicked ");
+ domStyle.set(dom.byId("invalidDate"), "visibility", "hidden");
registry.byId("datePicker").hide(false)
var datamodel = itemlistmodel.model[todoApp.selected_item];
date = datamodel.get("reminderDate");
@@ -1,13 +1,24 @@
define(["dojo/_base/lang", "dojo/dom", "dojo/dom-style", "dojo/on", "dijit/registry",
- "dojox/mobile/TransitionEvent", "dojox/mvc/getStateful", "dojox/mvc/at"],
-function(lang, dom, domStyle, on, registry, TransitionEvent, getStateful, at){
+ "dojox/mobile/TransitionEvent", "dojox/mvc/getStateful", "dojox/mvc/at", "dojo/date/stamp"],
+function(lang, dom, domStyle, on, registry, TransitionEvent, getStateful, at, stamp){
var itemlistmodel = null;
var listsmodel = null;
var signals = [];
var _isComplete = false;
var _isDelete = false;
todoApp._addNewItemCommit = false; // identify the new item is committed
+ dateClassTransform2 = {
+ format : function(value) {
+ // check to see if the date is in the past, if so display it in red
+ if(value && value < stamp.toISOString(new Date(), {selector: "date"})){
+ return "dateLabelInvalid";
+ }else{
+ return "";
+ }
+ }
+ };
+
// transform the repeat to the correct text
repeatTransform = {
format : function(value) {
@@ -1,7 +1,7 @@
-define(["dojo/dom", "dojo/_base/lang", "dojo/dom-style", "dojo/when", "dijit/registry", "dojox/mvc/at",
+define(["dojo/dom","dojo/_base/lang", "dojo/dom-style", "dojo/when", "dijit/registry", "dojox/mvc/at",
"dojox/mvc/EditStoreRefListController", "dojox/mvc/getStateful",
- "dojo/data/ItemFileWriteStore", "dojo/store/DataStore"],
-function(dom, lang, domStyle, when, registry, at, EditStoreRefListController, getStateful, ItemFileWriteStore, DataStore){
+ "dojo/data/ItemFileWriteStore", "dojo/store/DataStore", "dojo/date/stamp"],
+function(dom, lang, domStyle, when, registry, at, EditStoreRefListController, getStateful, ItemFileWriteStore, DataStore, stamp){
//set todoApp showItemDetails function
todoApp.cachedDataModel = {};
todoApp.currentItemListModel = null;
@@ -12,6 +12,17 @@ function(dom, lang, domStyle, when, registry, at, EditStoreRefListController, ge
itemlistmodel.set("cursorIndex",todoApp.selected_item);
};
+ dateListClassTransform = {
+ format : function(value) {
+ // check to see if the date is in the past, if so display it in red
+ if(value && value < stamp.toISOString(new Date(), {selector: "date"})){
+ return "dateLabelInvalid";
+ }else{
+ return "";
+ }
+ }
+ };
+
var listsmodel = null;
var itemlistmodel = null;

0 comments on commit eae7d42

Please sign in to comment.