Skip to content

Commit

Permalink
resolve: issues(fix #434, fix #421, fix #437)
Browse files Browse the repository at this point in the history
  • Loading branch information
jungeun-cho committed Oct 29, 2019
1 parent 487771e commit 07da5c1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
1 change: 1 addition & 0 deletions examples/js/data/calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function CalendarInfo() {
this.color = null;
this.bgColor = null;
this.borderColor = null;
this.dragBgColor = null;
}

function addCalendar(calendar) {
Expand Down
15 changes: 11 additions & 4 deletions src/js/controller/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
54 changes: 38 additions & 16 deletions src/js/factory/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down Expand Up @@ -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', {
* ...
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -1728,10 +1745,15 @@ Calendar.prototype.getViewName = function() {

/**
* Set calendar list
* @param {Array.<Object>} calendars - calendar list
* @param {Array.<CalendarProps>} 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();
};

Expand Down
3 changes: 2 additions & 1 deletion src/js/view/popup/scheduleCreationPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 07da5c1

Please sign in to comment.