Bert Leunis pushed to branch feature/CHANNELMGR-1391 at cms-community / hippo-addon-channel-manager
Commits: 42a64d2a by Bert Leunis at 2018-03-09T19:32:24+01:00 CHANNELMGR-1391 enhances DateValue class to deal with empty date fields When creating a new document the date fields are initially empty. When a value is entered in one of the fields of the dateField, the DateValue is populated. When a document is saved with an empty dateField, the property is not set. This is a difference from what the editor in the content perspective does! To be continued... - - - - - 2 changed files: - content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/DateFieldType.java - frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.controller.js Changes: ===================================== content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/DateFieldType.java ===================================== --- a/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/DateFieldType.java +++ b/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/type/DateFieldType.java @@ -17,13 +17,14 @@ package org.onehippo.cms.channelmanager.content.documenttype.field.type; import javax.jcr.PropertyType; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class DateFieldType extends PrimitiveFieldType { private static final Logger log = LoggerFactory.getLogger(DateFieldType.class); - private static final String DEFAULT_VALUE = "0001-01-01T13:00:00.000+01:00"; + private static final String DEFAULT_VALUE = StringUtils.EMPTY; public DateFieldType() { setType(Type.DATE); ===================================== frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.controller.js ===================================== --- a/frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.controller.js +++ b/frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.controller.js @@ -18,7 +18,11 @@ import moment from 'moment-timezone'; class DateValue { constructor(dateString) { - this._init(moment(dateString)); + if (dateString === '') { + this._initBlank(); + } else { + this._init(moment(dateString)); + } } _init(initMoment) { @@ -26,19 +30,32 @@ class DateValue { this.jsDate = this.moment.toDate(); // ngModel for md-date-picker } + _initBlank() { + this.moment = null; + this.jsDate = null; + } + + _checkInit() { + if (this.moment === null) { + this._init(moment()); + } + } + get hours() { - return this.moment.hours(); + return this.moment ? this.moment.hours() : ''; } set hours(hours) { + this._checkInit(); this.moment.hours(hours); } get minutes() { - return this.moment.minutes(); + return this.moment ? this.moment.minutes() : ''; } set minutes(minutes) { + this._checkInit(); this.moment.minutes(minutes); } @@ -47,6 +64,7 @@ class DateValue { } set date(date) { + this._checkInit(); const newMoment = moment(date); newMoment.hours(this.moment.hours()); newMoment.minutes(this.moment.minutes()); @@ -54,7 +72,7 @@ class DateValue { } toDateString() { - return this.moment.format('YYYY-MM-DDTHH:mm:ss.SSSZ'); + return this.moment ? this.moment.format('YYYY-MM-DDTHH:mm:ss.SSSZ') : ''; } setToNow() { View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/42a64d2ad9545ba54f58b3e8dbd91e51e7593091 --- View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/42a64d2ad9545ba54f58b3e8dbd91e51e7593091 You're receiving this email because of your account on code.onehippo.org.
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn