social-media
Version:
190 lines • 9.51 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require('@angular/core');
var event_model_1 = require("./event.model");
var SchedulerComponent = (function () {
function SchedulerComponent() {
this.previewEvent = new core_1.EventEmitter();
this.newEvent = new core_1.EventEmitter();
this.editingEvent = new core_1.EventEmitter();
this.isEdit = false;
}
Object.defineProperty(SchedulerComponent.prototype, "groups", {
get: function () {
return this._groups;
},
set: function (value) {
this._groups = value;
},
enumerable: true,
configurable: true
});
;
SchedulerComponent.prototype.ngOnChanges = function (changes) {
if (changes && "groups" in changes) {
var groups = changes.groups.currentValue;
this._buildCalendar(groups);
}
};
SchedulerComponent.prototype.ngOnInit = function () {
var _this = this;
this.activeEvent = new event_model_1.EventModel();
var x = new Web2Cal.TimeControl(jQuery("#eventStartTime").get(0));
var y = new Web2Cal.TimeControl(jQuery("#eventEndTime").get(0), jQuery("#eventStartTime").get(0), {
onTimeSelect: updateDateForTime,
dateField: "eventEndDate"
});
$('#event-modal')
.on('hidden.bs.modal', function () {
_this._closeModal();
});
var btn = $('<button class="btn btn-default btn-xl">New Event</button>')
.css("margin-top", "15px")
.insertAfter(".leftNavGroupsList");
$(".plotterlink").hide();
btn.on("click", function (ev) {
var groupId = null;
if (_this.groups && _this.groups.length > 0) {
groupId = _this.groups[0].id;
}
var startTime = new Date();
var endTime = new Date(startTime.getFullYear(), startTime.getMonth(), startTime.getDay(), startTime.getHours() + 2);
_this._newEvent(startTime, endTime, groupId);
});
};
SchedulerComponent.prototype._buildCalendar = function (groups) {
var _this = this;
this.ical = new Web2Cal('calendarContainer', {
loadEvents: function () {
_this._loadGroupsAndEventsData((groups) ? groups : _this.groups);
_this.ical.render(_this.calendarGroups);
},
onPreview: function (evt, dataObj, html) {
$("#calInfoStatus").html("");
_this._setActiveEvent(dataObj.eventId, dataObj.groupId);
_this.previewEvent.emit(_this.activeEvent);
_this.isEdit = false;
$('#event-modal').modal('show');
},
onNewEvent: function (obj, groups, allday) {
var groupId = (groups && groups.length > 0) ? groups[groups.length - 1].groupId : null;
if (!groupId && _this.groups && _this.groups.length > 0) {
groupId = _this.groups[0].id;
}
$("#defaultNewEventTemplate").css("display", "none");
_this._newEvent(obj.startTime, obj.endTime, groupId);
}
});
this.ical.build();
};
SchedulerComponent.prototype._newEvent = function (startTime, endTime, groupId) {
var activeEvent = new event_model_1.EventModel();
activeEvent.id = -1;
activeEvent.startTime = startTime;
activeEvent.endTime = endTime;
activeEvent.groupId = groupId;
this.activeEvent = activeEvent;
this.isEdit = true;
this.newEvent.emit(activeEvent);
$('#event-modal').modal('show');
};
SchedulerComponent.prototype.saveActiveEvent = function () {
var groupData = null;
for (var _i = 0, _a = this.calendarGroups; _i < _a.length; _i++) {
var g = _a[_i];
if (g.groupId === this.activeEvent.groupId) {
groupData = g;
break;
}
}
var eventData = this.activeEvent.toEventData(groupData);
if (this.activeEvent.id <= 0) {
for (var _b = 0, _c = this.groups; _b < _c.length; _b++) {
var group = _c[_b];
if (group.id === this.activeEvent.groupId) {
this.activeEvent.id = Math.ceil(999 * Math.random());
group.events.push(this.activeEvent);
this.ical.addEvent(eventData);
break;
}
}
}
else {
this.ical.updateEvent(eventData);
}
$('#event-modal').modal('hide');
};
SchedulerComponent.prototype.editActiveEvent = function () {
this.editingEvent.emit(this.activeEvent);
this.isEdit = true;
};
SchedulerComponent.prototype._closeModal = function () {
if (this.activeEvent.id <= 0) {
this.ical.closeAddEvent();
}
};
SchedulerComponent.prototype._loadGroupsAndEventsData = function (groups) {
this.calendarGroups = new Array();
if (groups) {
for (var _i = 0, groups_1 = groups; _i < groups_1.length; _i++) {
var group = groups_1[_i];
var newGroup = group.toGroupData();
for (var _a = 0, _b = group.events; _a < _b.length; _a++) {
var event_1 = _b[_a];
var newEvent = event_1.toEventData(newGroup);
newGroup.events.push(newEvent);
}
this.calendarGroups.push(newGroup);
}
}
};
SchedulerComponent.prototype._setActiveEvent = function (eventId, groupId) {
for (var _i = 0, _a = this.groups; _i < _a.length; _i++) {
var group = _a[_i];
if (group.id === groupId) {
for (var _b = 0, _c = group.events; _b < _c.length; _b++) {
var event_2 = _c[_b];
if (event_2.id === eventId) {
this.activeEvent = event_2;
break;
}
}
}
}
};
__decorate([
core_1.Input(),
__metadata('design:type', Array)
], SchedulerComponent.prototype, "groups", null);
__decorate([
core_1.Output(),
__metadata('design:type', core_1.EventEmitter)
], SchedulerComponent.prototype, "previewEvent", void 0);
__decorate([
core_1.Output(),
__metadata('design:type', core_1.EventEmitter)
], SchedulerComponent.prototype, "newEvent", void 0);
__decorate([
core_1.Output(),
__metadata('design:type', core_1.EventEmitter)
], SchedulerComponent.prototype, "editingEvent", void 0);
SchedulerComponent = __decorate([
core_1.Component({
selector: 'app-scheduler',
template: "<div id=\"calendarContainer\"> </div> <!-- Modal --> <div id=\"event-modal\" class=\"modal\" role=\"dialog\"> <div class=\"modal-dialog\"> <!-- Modal content--> <div class=\"modal-content\"> <div class=\"modal-header\"> <button type=\"button\" class=\"close\" data-dismiss=\"modal\">×</button> <h4 class=\"modal-title\">{{activeEvent.name}}</h4> </div> <div class=\"modal-body\"> <ng-content select=\"preview-template\" *ngIf=\"!isEdit\"></ng-content> <ng-content select=\"edit-template\" *ngIf=\"isEdit\"></ng-content> <div class=\"modal-footer\"> <button type=\"button\" (click)=\"editActiveEvent()\" *ngIf=\"!isEdit\" class=\"btn btn-success\">Edit</button> <button type=\"button\" (click)=\"saveActiveEvent()\" *ngIf=\"isEdit\" class=\"btn btn-success\">Save</button> <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button> </div> </div> </div> </div> </div>",
styles: [".modal { -webkit-animation-duration: 3s; animation-duration: 3s; animation-name: slidein; -webkit-animation-iteration-count: infinite; animation-iteration-count: 1; } @keyframes slidein { from { margin-left: 100%; } to { margin-left: 0%; }"]
}),
__metadata('design:paramtypes', [])
], SchedulerComponent);
return SchedulerComponent;
}());
exports.SchedulerComponent = SchedulerComponent;
//# sourceMappingURL=scheduler.component.js.map