/**
* Kendo UI v2016.1.112 (http://www.telerik.com/kendo-ui)
* Copyright 2016 Telerik AD. All rights reserved.
*
* Kendo UI commercial licenses may be obtained at
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
* If you do not own a commercial license, this file shall be governed by the trial license terms.
*/
(function (f, define) {
define('kendo.scheduler.view', ['kendo.core'], f);
}(function () {
var __meta__ = {
id: 'scheduler.view',
name: 'Scheduler View',
category: 'web',
description: 'The Scheduler Common View',
depends: ['core'],
hidden: true
};
(function ($) {
var kendo = window.kendo, ui = kendo.ui, Widget = ui.Widget, keys = kendo.keys, NS = '.kendoSchedulerView', math = Math;
function levels(values, key) {
var result = [];
function collect(depth, values) {
values = values[key];
if (values) {
var level = result[depth] = result[depth] || [];
for (var idx = 0; idx < values.length; idx++) {
level.push(values[idx]);
collect(depth + 1, values[idx]);
}
}
}
collect(0, values);
return result;
}
function cellspacing() {
if (kendo.support.cssBorderSpacing) {
return '';
}
return 'cellspacing="0"';
}
function table(tableRows, className) {
if (!tableRows.length) {
return '';
}
return '
').append(this.times.add(this.content).wrap('').parent());
},
_scroller: function () {
var that = this;
this.content.bind('scroll' + NS, function () {
that.datesHeader.find('>.k-scheduler-header-wrap').scrollLeft(this.scrollLeft);
that.times.scrollTop(this.scrollTop);
});
var touchScroller = kendo.touchScroller(this.content, {
avoidScrolling: function (e) {
return $(e.event.target).closest('.k-event.k-event-active').length > 0;
}
});
if (touchScroller && touchScroller.movable) {
this._touchScroller = touchScroller;
this.content = touchScroller.scrollElement;
touchScroller.movable.bind('change', function (e) {
that.datesHeader.find('>.k-scheduler-header-wrap').scrollLeft(-e.sender.x);
that.times.scrollTop(-e.sender.y);
});
}
},
_resourcesForGroups: function () {
var result = [];
var groups = this.options.group;
var resources = this.options.resources;
groups = groups && groups.resources ? groups.resources : [];
if (resources && groups.length) {
for (var idx = 0, length = resources.length; idx < length; idx++) {
for (var groupIdx = 0, groupLength = groups.length; groupIdx < groupLength; groupIdx++) {
if (resources[idx].name === groups[groupIdx]) {
result.push(resources[idx]);
}
}
}
}
this.groupedResources = result;
},
_createColumnsLayout: function (resources, inner, template) {
return createLayoutConfiguration('columns', resources, inner, template);
},
_groupOrientation: function () {
var groups = this.options.group;
return groups && groups.resources ? groups.orientation : 'horizontal';
},
_isVerticallyGrouped: function () {
return this.groupedResources.length && this._groupOrientation() === 'vertical';
},
_createRowsLayout: function (resources, inner, template) {
return createLayoutConfiguration('rows', resources, inner, template);
},
selectionByElement: function () {
return null;
},
clearSelection: function () {
this.content.find('.k-state-selected').removeAttr('id').attr('aria-selected', false).removeClass('k-state-selected');
},
destroy: function () {
var that = this;
Widget.fn.destroy.call(this);
if (that.table) {
kendo.destroy(that.table);
that.table.remove();
}
that.groups = null;
that.table = null;
that.content = null;
that.times = null;
that.datesHeader = null;
that.timesHeader = null;
that.footer = null;
that._resizeHint = null;
that._moveHint = null;
},
calendarInfo: function () {
return kendo.getCulture().calendars.standard;
},
prevGroupSlot: function (date, groupIndex, isDay) {
var collection;
var group = this.groups[groupIndex];
var slot = group.ranges(date, date, isDay, false)[0].start;
if (groupIndex <= 0) {
return;
}
if (this._isVerticallyGrouped()) {
if (!group.timeSlotCollectionCount()) {
collection = group._collection(group.daySlotCollectionCount() - 1, true);
return collection.at(slot.index);
} else {
collection = group._collection(isDay ? slot.index : slot.collectionIndex, false);
return collection.last();
}
} else {
if (!group.timeSlotCollectionCount()) {
collection = group._collection(slot.collectionIndex, true);
return collection.last();
} else {
collection = group._collection(isDay ? 0 : group.timeSlotCollectionCount() - 1, isDay);
return isDay ? collection.last() : collection.at(slot.index);
}
}
},
nextGroupSlot: function (date, groupIndex, isDay) {
var collection;
var group = this.groups[groupIndex];
var slot = group.ranges(date, date, isDay, false)[0].start;
var daySlotCollectionCount;
if (groupIndex >= this.groups.length - 1) {
return;
}
if (this._isVerticallyGrouped()) {
if (!group.timeSlotCollectionCount()) {
collection = group._collection(0, true);
return collection.at(slot.index);
} else {
daySlotCollectionCount = group.daySlotCollectionCount();
collection = group._collection(daySlotCollectionCount ? 0 : slot.collectionIndex, daySlotCollectionCount);
return isDay ? collection.first() : collection.at(slot.collectionIndex);
}
} else {
if (!group.timeSlotCollectionCount()) {
collection = group._collection(slot.collectionIndex, true);
return collection.first();
} else {
collection = group._collection(0, isDay);
return isDay ? collection.first() : collection.at(slot.index);
}
}
},
_eventOptionsForMove: function () {
return {};
},
_updateEventForResize: function () {
return;
},
_updateEventForSelection: function (event) {
return event;
}
});
function collidingEvents(elements, start, end) {
var idx, index, startIndex, overlaps, endIndex;
for (idx = elements.length - 1; idx >= 0; idx--) {
index = rangeIndex(elements[idx]);
startIndex = index.start;
endIndex = index.end;
overlaps = startIndex <= start && endIndex >= start;
if (overlaps || startIndex >= start && endIndex <= end || start <= startIndex && end >= startIndex) {
if (startIndex < start) {
start = startIndex;
}
if (endIndex > end) {
end = endIndex;
}
}
}
return eventsForSlot(elements, start, end);
}
function rangeIndex(eventElement) {
return {
start: eventElement.start,
end: eventElement.end
};
}
function eventsForSlot(elements, slotStart, slotEnd) {
var events = [];
for (var idx = 0; idx < elements.length; idx++) {
var event = rangeIndex(elements[idx]);
if (event.start < slotStart && event.end > slotStart || event.start >= slotStart && event.end <= slotEnd) {
events.push(elements[idx]);
}
}
return events;
}
function createColumns(eventElements) {
return _createColumns(eventElements);
}
function createRows(eventElements) {
return _createColumns(eventElements);
}
var Color = function (value) {
var color = this, formats = Color.formats, re, processor, parts, i, channels;
if (arguments.length === 1) {
value = color.resolveColor(value);
for (i = 0; i < formats.length; i++) {
re = formats[i].re;
processor = formats[i].process;
parts = re.exec(value);
if (parts) {
channels = processor(parts);
color.r = channels[0];
color.g = channels[1];
color.b = channels[2];
}
}
} else {
color.r = arguments[0];
color.g = arguments[1];
color.b = arguments[2];
}
color.r = color.normalizeByte(color.r);
color.g = color.normalizeByte(color.g);
color.b = color.normalizeByte(color.b);
};
Color.prototype = {
resolveColor: function (value) {
value = value || '#000';
if (value.charAt(0) == '#') {
value = value.substr(1, 6);
}
value = value.replace(/ /g, '');
value = value.toLowerCase();
value = Color.namedColors[value] || value;
return value;
},
normalizeByte: function (value) {
return value < 0 || isNaN(value) ? 0 : value > 255 ? 255 : value;
},
percBrightness: function () {
var color = this;
return math.sqrt(0.241 * color.r * color.r + 0.691 * color.g * color.g + 0.068 * color.b * color.b);
},
isDark: function () {
var color = this;
var brightnessValue = color.percBrightness();
return brightnessValue < 180;
}
};
Color.formats = [
{
re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
process: function (parts) {
return [
parseInt(parts[1], 10),
parseInt(parts[2], 10),
parseInt(parts[3], 10)
];
}
},
{
re: /^(\w{2})(\w{2})(\w{2})$/,
process: function (parts) {
return [
parseInt(parts[1], 16),
parseInt(parts[2], 16),
parseInt(parts[3], 16)
];
}
},
{
re: /^(\w{1})(\w{1})(\w{1})$/,
process: function (parts) {
return [
parseInt(parts[1] + parts[1], 16),
parseInt(parts[2] + parts[2], 16),
parseInt(parts[3] + parts[3], 16)
];
}
}
];
Color.namedColors = {
aqua: '00ffff',
azure: 'f0ffff',
beige: 'f5f5dc',
black: '000000',
blue: '0000ff',
brown: 'a52a2a',
coral: 'ff7f50',
cyan: '00ffff',
darkblue: '00008b',
darkcyan: '008b8b',
darkgray: 'a9a9a9',
darkgreen: '006400',
darkorange: 'ff8c00',
darkred: '8b0000',
dimgray: '696969',
fuchsia: 'ff00ff',
gold: 'ffd700',
goldenrod: 'daa520',
gray: '808080',
green: '008000',
greenyellow: 'adff2f',
indigo: '4b0082',
ivory: 'fffff0',
khaki: 'f0e68c',
lightblue: 'add8e6',
lightgrey: 'd3d3d3',
lightgreen: '90ee90',
lightpink: 'ffb6c1',
lightyellow: 'ffffe0',
lime: '00ff00',
limegreen: '32cd32',
linen: 'faf0e6',
magenta: 'ff00ff',
maroon: '800000',
mediumblue: '0000cd',
navy: '000080',
olive: '808000',
orange: 'ffa500',
orangered: 'ff4500',
orchid: 'da70d6',
pink: 'ffc0cb',
plum: 'dda0dd',
purple: '800080',
red: 'ff0000',
royalblue: '4169e1',
salmon: 'fa8072',
silver: 'c0c0c0',
skyblue: '87ceeb',
slateblue: '6a5acd',
slategray: '708090',
snow: 'fffafa',
steelblue: '4682b4',
tan: 'd2b48c',
teal: '008080',
tomato: 'ff6347',
turquoise: '40e0d0',
violet: 'ee82ee',
wheat: 'f5deb3',
white: 'ffffff',
whitesmoke: 'f5f5f5',
yellow: 'ffff00',
yellowgreen: '9acd32'
};
function _createColumns(eventElements) {
var columns = [];
for (var idx = 0; idx < eventElements.length; idx++) {
var event = eventElements[idx];
var eventRange = rangeIndex(event);
var column = null;
for (var j = 0, columnLength = columns.length; j < columnLength; j++) {
var endOverlaps = eventRange.start > columns[j].end;
if (eventRange.start < columns[j].start || endOverlaps) {
column = columns[j];
if (column.end < eventRange.end) {
column.end = eventRange.end;
}
break;
}
}
if (!column) {
column = {
start: eventRange.start,
end: eventRange.end,
events: []
};
columns.push(column);
}
column.events.push(event);
}
return columns;
}
function createLayoutConfiguration(name, resources, inner, template) {
var resource = resources[0];
if (resource) {
var configuration = [];
var data = resource.dataSource.view();
for (var dataIndex = 0; dataIndex < data.length; dataIndex++) {
var obj = {
text: template({
text: kendo.htmlEncode(kendo.getter(resource.dataTextField)(data[dataIndex])),
color: kendo.getter(resource.dataColorField)(data[dataIndex]),
field: resource.field,
title: resource.title,
name: resource.name,
value: kendo.getter(resource.dataValueField)(data[dataIndex])
}),
className: 'k-slot-cell'
};
obj[name] = createLayoutConfiguration(name, resources.slice(1), inner, template);
configuration.push(obj);
}
return configuration;
}
return inner;
}
function groupEqFilter(value) {
return function (item) {
if ($.isArray(item) || item instanceof kendo.data.ObservableArray) {
for (var idx = 0; idx < item.length; idx++) {
if (item[idx] == value) {
return true;
}
}
return false;
}
return item == value;
};
}
var selectedStateRegExp = /\s*k-state-selected/;
function addSelectedState(cell) {
cell.className = cell.className.replace(selectedStateRegExp, '') + ' k-state-selected';
}
$.extend(ui.SchedulerView, {
createColumns: createColumns,
createRows: createRows,
rangeIndex: rangeIndex,
collidingEvents: collidingEvents,
groupEqFilter: groupEqFilter
});
}(window.kendo.jQuery));
return window.kendo;
}, typeof define == 'function' && define.amd ? define : function (a1, a2, a3) {
(a3 || a2)();
})); |