6 * @param {object} params
9 function GraphSchedule(params) {
16 GraphSchedule.prototype = {
28 GraphSchedule.prototype.createUI = function createUI() {
29 console.log('GraphSchedule..createUI');
30 var $tmp = $('<div></div>');
32 $tmp.html(this.template);
33 this.$flag = $tmp.find('.flag');
34 this.$graph = $tmp.find('.GraphSchedule');
35 this.ui = this.$graph;
37 this.addCurrentTimeBar();
43 GraphSchedule.prototype.center = function center() {
44 // set scroll position;
45 this.$graph[0].scrollLeft = 1000 * ((new Date().getHours() - 4) / 24);
48 GraphSchedule.prototype.refresh = function refresh() {
49 this.updateTimeRanges();
54 GraphSchedule.prototype.onTemplateLoad = function onTemplateLoad() {
55 console.log('GraphSchedule..onTemplateLoad');
58 GraphSchedule.prototype.init = function init(params) {
59 var $loader = $('<div></div>');
61 if (params && params.onSuccess) {
62 this.onTemplateLoad = params.onSuccess;
66 $loader.load('templates/GraphSchedule.tmpl', null, function (data) {
67 console.log('$loader.onLoad');
70 this.onTemplateLoad();
76 * @param {Array} times
79 GraphSchedule.prototype.pushTimeOfFlags = function pushTimeOfFlags(times) {
82 // clear previous times;
85 if (times instanceof Array) {
87 for (i = 0; i < count; i += 1) {
88 if (times[i] instanceof Date) {
89 this.flags.push({ time: times[i] });
91 throw {message: 'Bag argument at [' + i + '] element of Array. Expected {Date}'};
95 throw {message: 'Bad argument. Expected {Array} of {Date}'};
99 GraphSchedule.prototype.addCurrentTimeBar = function addCurrentTimeBar() {
100 console.log('addCurrentTimeBar()');
101 // remove old time bar;
102 var $currentTimeBar = this.$graph.find('.currentTimeBar'),
103 currentTime = new Date(),
104 hours = currentTime.getHours();
106 if ($currentTimeBar.length === 0) {
108 $currentTimeBar = $('<div class="currentTimeBar"></div>');
115 this.$graph.find('.ranges .h' + hours).append($currentTimeBar);
116 $currentTimeBar.css('left', 100 * currentTime.getMinutes() / 60 + '%');
118 setTimeout(this.addCurrentTimeBar.bind(this), 5 * 60 * 1000);
121 GraphSchedule.prototype.addFlag = function addFlag(newFlag) {
122 console.log('addFlag()');
123 var $flagClone, hours = newFlag.time.getHours();
127 $flagClone = this.$flag.clone();
128 this.$graph.find('.grid td:contains(' + hours + ')').append($flagClone);
129 $flagClone.css('left', 100 * newFlag.time.getMinutes() / 60 + '%');
132 GraphSchedule.prototype.showFlags = function showFlags() {
133 var i, len = this.flags.length;
137 // add all flags to view;
138 for (i = 0; i < len; i += 1) {
139 this.addFlag(this.flags[i]);
145 GraphSchedule.prototype.removeFlags = function removeFlags() {
146 this.$graph.find('.flag').remove();
149 GraphSchedule.prototype.setTimeRanges = function setTimeRanges(ranges) {
150 this.timeRanges = ranges;
153 GraphSchedule.prototype.setVisibleWeekend = function (bool) {
154 var row = this.ui.find('.rangesWeekend');
155 return bool ? row.show() : row.hide();
158 GraphSchedule.prototype.setVisibleWorkdays = function (bool) {
159 var row = this.ui.find('.ranges');
160 return bool ? row.show() : row.hide();
164 * Update time ranges on graph
165 * @param ranges {array} array of boolen, keys are hours, example: [false, false, false, true, true]
167 GraphSchedule.prototype.updateTimeRanges = function updateTimeRanges() {
170 this.$graph.find('.th').removeClass('th');
173 hours = this.timeRanges.workday;
175 for (i = 0; i < len; i += 1) {
177 this.$graph.find('.ranges .h' + ((i < 10) ? '0' + i : i)).addClass('th');
182 hours = this.timeRanges.weekend;
184 for (i = 0; i < len; i += 1) {
186 this.$graph.find('.rangesWeekend .h' + ((i < 10) ? '0' + i : i)).addClass('th');