Skip to content

Commit

Permalink
Add Date only initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrookes committed Nov 8, 2014
1 parent e76b304 commit 38fe141
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions app/assets/javascripts/upmin/attributes/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,8 @@
return curMoment;
}






// Initializing the attribute view.
var init = function(formId) {
// Initializing the DateTime attribute view.
var initDateTime = function(formId) {
var dtSection = $("." + formId + ".datetime-attribute");
var hiddenInput = dtSection.find("input#" + formId + "[type=hidden]");
var dateInput = dtSection.find("#" + formId + "-date");
Expand Down Expand Up @@ -123,12 +118,43 @@
});
}

// Initializing the Date attribute view.
// TODO: Dry this up against DateTime
var initDate = function(formId) {
var dtSection = $("." + formId + ".date-attribute");
var hiddenInput = dtSection.find("input#" + formId + "[type=hidden]");
var dateInput = dtSection.find("#" + formId + "-date");

var dtMoment = moment(hiddenInput.val());
if (hiddenInput.val() == "") {
dtMoment = null;
}

var handleDateSelect = function() {
var newDateMoment = parseDate(dateInput.val());
setInputDate(newDateMoment, hiddenInput);
return newDateMoment;
}

// Create Date Picker
var datePicker = new Pikaday({ field: $("#" + formId + "-date")[0], onSelect: handleDateSelect });

dtSection.closest("form").submit(function(event) {
event.preventDefault();

handleDateSelect();

event.target.submit();
});
}

if (window.Upmin == null) {
window.Upmin = {};
}
if (window.Upmin.Attributes == null) {
window.Upmin.Attributes = {};
}
window.Upmin.Attributes.DateTime = init;

window.Upmin.Attributes.DateTime = initDateTime;
window.Upmin.Attributes.Date = initDate;
})();

0 comments on commit 38fe141

Please sign in to comment.