diff --git a/examples/js/data/calendars.js b/examples/js/data/calendars.js index 89b7e3850..a2f981384 100644 --- a/examples/js/data/calendars.js +++ b/examples/js/data/calendars.js @@ -11,6 +11,7 @@ function CalendarInfo() { this.color = null; this.bgColor = null; this.borderColor = null; + this.dragBgColor = null; } function addCalendar(calendar) { diff --git a/src/js/controller/base.js b/src/js/controller/base.js index 427e09707..7759c45d1 100644 --- a/src/js/controller/base.js +++ b/src/js/controller/base.js @@ -154,6 +154,17 @@ Base.prototype.updateSchedule = function(schedule, options) { var end = options.end || schedule.end; options = options || {}; + if (!util.isUndefined(options.isAllDay)) { + schedule.set('isAllDay', options.isAllDay); + } + + if (options.category && options.category === 'allday') { + schedule.set('isAllDay', true); + } + + if (options.calendarId !== schedule.calendarId) { + schedule.set('calendarId', options.calendarId); + } if (options.title) { schedule.set('title', options.title); @@ -187,10 +198,6 @@ Base.prototype.updateSchedule = function(schedule, options) { schedule.set('origin', options.origin); } - if (!util.isUndefined(options.isAllDay)) { - schedule.set('isAllDay', options.isAllDay); - } - if (!util.isUndefined(options.isPending)) { schedule.set('isPending', options.isPending); } diff --git a/src/js/factory/calendar.js b/src/js/factory/calendar.js index 9df072250..a93e6bb34 100644 --- a/src/js/factory/calendar.js +++ b/src/js/factory/calendar.js @@ -367,6 +367,7 @@ var mmin = Math.min; * @property {string} [color] - The calendar color * @property {string} [bgColor] - The calendar background color * @property {string} [borderColor] - The calendar left border color + * @property {string} [dragBgColor] - The Background color displayed when you drag a calendar's schedule */ /** @@ -395,6 +396,7 @@ var mmin = Math.min; * @property {string} color - The text color when schedule is displayed * @property {string} bgColor - The background color schedule is displayed * @property {string} borderColor - The color of left border or bullet point when schedule is displayed + * @property {string} dragBgColor - The background color when schedule dragging * @example * var cal = new Calendar('#calendar', { * ... @@ -749,18 +751,9 @@ Calendar.prototype._initialize = function(options) { * ]); */ Calendar.prototype.createSchedules = function(schedules, silent) { - var calColor = this._calendarColor; - util.forEach(schedules, function(obj) { - var color = calColor[obj.calendarId]; - - //overwrite schedule color with calendar's only if schedule is not customized - if (color) { - obj.color = obj.color || color.color; - obj.bgColor = obj.bgColor || color.bgColor; - obj.borderColor = obj.borderColor || color.borderColor; - } - }); + this._setScheduleColor(obj.calendarId, obj); + }, this); this._controller.createSchedules(schedules, silent); @@ -805,8 +798,13 @@ Calendar.prototype.updateSchedule = function(scheduleId, calendarId, scheduleDat var ctrl = this._controller, ownSchedules = ctrl.schedules, schedule = ownSchedules.single(function(model) { - return model.id === scheduleId && model.calendarId === calendarId; + return model.__fe_id === (scheduleData.__fe_id || scheduleData._feId); }); + var hasChangedCalendar = schedule && schedule.calendarId !== calendarId; + + scheduleData = hasChangedCalendar ? + this._setScheduleColor(calendarId, scheduleData) : + scheduleData; if (schedule) { ctrl.updateSchedule(schedule, scheduleData); @@ -817,6 +815,20 @@ Calendar.prototype.updateSchedule = function(scheduleId, calendarId, scheduleDat } }; +Calendar.prototype._setScheduleColor = function(calendarId, schedule) { + var calColor = this._calendarColor; + var color = calColor[calendarId]; + + if (color) { + schedule.color = schedule.color || color.color; + schedule.bgColor = schedule.bgColor || color.bgColor; + schedule.borderColor = schedule.borderColor || color.borderColor; + schedule.dragBgColor = schedule.dragBgColor || color.dragBgColor; + } + + return schedule; +}; + /** * Delete a schedule. * @param {string} scheduleId - ID of schedule to delete @@ -1185,16 +1197,19 @@ Calendar.prototype._getCurrentView = function() { * color: '#e8e8e8', * bgColor: '#585858', * borderColor: '#a1b56c' + * dragBgColor: '#585858', * }); * calendar.setCalendarColor('2', { * color: '#282828', * bgColor: '#dc9656', - * borderColor: '#a1b56c' + * borderColor: '#a1b56c', + * dragBgColor: '#dc9656', * }); * calendar.setCalendarColor('3', { * color: '#a16946', * bgColor: '#ab4642', - * borderColor: '#a1b56c' + * borderColor: '#a1b56c', + * dragBgColor: '#ab4642', * }); */ Calendar.prototype.setCalendarColor = function(calendarId, option, silent) { @@ -1209,7 +1224,8 @@ Calendar.prototype.setCalendarColor = function(calendarId, option, silent) { ownColor = calColor[calendarId] = util.extend({ color: '#000', bgColor: '#a1b56c', - borderColor: '#a1b56c' + borderColor: '#a1b56c', + dragBgColor: '#a1b56c' }, option); ownSchedules.each(function(model) { @@ -1220,6 +1236,7 @@ Calendar.prototype.setCalendarColor = function(calendarId, option, silent) { model.color = ownColor.color; model.bgColor = ownColor.bgColor; model.borderColor = ownColor.borderColor; + model.dragBgColor = ownColor.dragBgColor; }); if (!silent) { @@ -1728,10 +1745,15 @@ Calendar.prototype.getViewName = function() { /** * Set calendar list - * @param {Array.} calendars - calendar list + * @param {Array.} calendars - {@link CalendarProps} List */ Calendar.prototype.setCalendars = function(calendars) { + util.forEach(calendars || [], function(calendar) { + this.setCalendarColor(calendar.id, calendar, true); + }, this); + this._controller.setCalendars(calendars); + this.render(); }; diff --git a/src/js/view/popup/scheduleCreationPopup.js b/src/js/view/popup/scheduleCreationPopup.js index 59d2e31ba..2bc6f0d9e 100644 --- a/src/js/view/popup/scheduleCreationPopup.js +++ b/src/js/view/popup/scheduleCreationPopup.js @@ -295,7 +295,8 @@ ScheduleCreationPopup.prototype._onClickSaveSchedule = function(target) { isAllDay: isAllDay, state: state.innerText, triggerEventName: 'click', - id: this._schedule.id + id: this._schedule.id, + _feId: this._schedule.__fe_id }, start: start, end: end,