(js) Fix creation of a Calendar
This commit is contained in:
parent
87fc7b39cc
commit
b30f20e1b3
|
@ -14,7 +14,7 @@
|
||||||
if (this.name && !this.id) {
|
if (this.name && !this.id) {
|
||||||
// Create a new calendar on the server
|
// Create a new calendar on the server
|
||||||
var newCalendarData = Calendar.$$resource.create('createFolder', this.name);
|
var newCalendarData = Calendar.$$resource.create('createFolder', this.name);
|
||||||
angular.extend(this, newCalendarData);
|
this.$unwrap(newCalendarData);
|
||||||
}
|
}
|
||||||
if (this.id) {
|
if (this.id) {
|
||||||
this.$acl = new Calendar.$$Acl('Calendar/' + this.id);
|
this.$acl = new Calendar.$$Acl('Calendar/' + this.id);
|
||||||
|
@ -239,6 +239,7 @@
|
||||||
* @param {object} data - attributes of calendar
|
* @param {object} data - attributes of calendar
|
||||||
*/
|
*/
|
||||||
Calendar.prototype.init = function(data) {
|
Calendar.prototype.init = function(data) {
|
||||||
|
this.color = this.color || '#AAAAAA';
|
||||||
angular.extend(this, data);
|
angular.extend(this, data);
|
||||||
// Add 'isOwned' and 'isSubscription' attributes based on active user (TODO: add it server-side?)
|
// Add 'isOwned' and 'isSubscription' attributes based on active user (TODO: add it server-side?)
|
||||||
this.isOwned = Calendar.activeUser.isSuperUser || this.owner == Calendar.activeUser.login;
|
this.isOwned = Calendar.activeUser.isSuperUser || this.owner == Calendar.activeUser.login;
|
||||||
|
@ -249,6 +250,25 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function $id
|
||||||
|
* @memberof Calendar.prototype
|
||||||
|
* @desc Resolve the calendar id.
|
||||||
|
* @returns a promise of the calendar id
|
||||||
|
*/
|
||||||
|
Calendar.prototype.$id = function() {
|
||||||
|
if (this.id) {
|
||||||
|
// Object already unwrapped
|
||||||
|
return Calendar.$q.when(this.id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Wait until object is unwrapped
|
||||||
|
return this.$futureCalendarData.then(function(calendar) {
|
||||||
|
return calendar.id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function getClassName
|
* @function getClassName
|
||||||
* @memberof Calendar.prototype
|
* @memberof Calendar.prototype
|
||||||
|
@ -383,6 +403,32 @@
|
||||||
return Calendar.$Component.$find(this.id, componentId, recurrenceId);
|
return Calendar.$Component.$find(this.id, componentId, recurrenceId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function $unwrap
|
||||||
|
* @memberof Calendar.prototype
|
||||||
|
* @desc Unwrap a promise
|
||||||
|
* @param {promise} futureCalendarData - a promise of the Calendar's data
|
||||||
|
*/
|
||||||
|
Calendar.prototype.$unwrap = function(futureCalendarData) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
// Expose and resolve the promise
|
||||||
|
this.$futureCalendarData = futureCalendarData.then(function(data) {
|
||||||
|
return Calendar.$timeout(function() {
|
||||||
|
// Extend Calendar instance with received data
|
||||||
|
_this.init(data);
|
||||||
|
return _this;
|
||||||
|
});
|
||||||
|
}, function(data) {
|
||||||
|
_this.isError = true;
|
||||||
|
if (angular.isObject(data)) {
|
||||||
|
Calendar.$timeout(function() {
|
||||||
|
angular.extend(_this, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function $omit
|
* @function $omit
|
||||||
* @memberof Calendar.prototype
|
* @memberof Calendar.prototype
|
||||||
|
|
|
@ -63,7 +63,9 @@
|
||||||
owner: UserLogin
|
owner: UserLogin
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Calendar.$add(calendar);
|
calendar.$id().then(function() {
|
||||||
|
Calendar.$add(calendar);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue