|
|
@@ -1,29 +1,35 @@
|
|
|
|
|
|
-/*
|
|
|
-Caller must:
|
|
|
-- call initFillSystem
|
|
|
-- implement renderFill
|
|
|
-*/
|
|
|
-var FillSystemMixin = { // use for highlight, background events, business hours
|
|
|
+var FillSystem = Class.extend({ // use for highlight, background events, business hours
|
|
|
|
|
|
+ component: null,
|
|
|
elsByFill: null, // a hash of jQuery element sets used for rendering each fill. Keyed by fill name.
|
|
|
|
|
|
|
|
|
- initFillSystem: function() {
|
|
|
+ /*
|
|
|
+ component defines:
|
|
|
+ - fillSegTag (optional, defaults to 'div')
|
|
|
+ - *SegEl
|
|
|
+ - *SegClasses
|
|
|
+ - *SegCss
|
|
|
+ */
|
|
|
+ constructor: function(component) {
|
|
|
+ this.component = component;
|
|
|
this.elsByFill = {};
|
|
|
},
|
|
|
|
|
|
|
|
|
- // Renders a set of rectangles over the given segments of time.
|
|
|
- // MUST RETURN a subset of segs, the segs that were actually rendered.
|
|
|
- // Responsible for populating this.elsByFill. TODO: better API for expressing this requirement
|
|
|
- renderFill: function(type, segs) {
|
|
|
- // subclasses must implement
|
|
|
+ reportEls: function(type, nodes) {
|
|
|
+ if (this.elsByFill[type]) {
|
|
|
+ this.elsByFill[type] = this.elsByFill[type].add(nodes);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.elsByFill[type] = $(nodes);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
|
|
|
// Unrenders a specific type of fill that is currently rendered on the grid
|
|
|
- unrenderFill: function(type) {
|
|
|
+ unrender: function(type) {
|
|
|
var el = this.elsByFill[type];
|
|
|
|
|
|
if (el) {
|
|
|
@@ -35,11 +41,9 @@ var FillSystemMixin = { // use for highlight, background events, business hours
|
|
|
|
|
|
// Renders and assigns an `el` property for each fill segment. Generic enough to work with different types.
|
|
|
// Only returns segments that successfully rendered.
|
|
|
- // To be harnessed by renderFill (implemented by subclasses).
|
|
|
- // Analagous to renderFgSegEls.
|
|
|
- renderFillSegEls: function(type, segs) {
|
|
|
- var _this = this;
|
|
|
- var segElMethod = this[type + 'SegEl'];
|
|
|
+ buildSegEls: function(type, segs) {
|
|
|
+ var component = this.component;
|
|
|
+ var segElMethod = component[type + 'SegEl'];
|
|
|
var html = '';
|
|
|
var renderedSegs = [];
|
|
|
var i;
|
|
|
@@ -48,7 +52,7 @@ var FillSystemMixin = { // use for highlight, background events, business hours
|
|
|
|
|
|
// build a large concatenation of segment HTML
|
|
|
for (i = 0; i < segs.length; i++) {
|
|
|
- html += this.fillSegHtml(type, segs[i]);
|
|
|
+ html += this.buildSegHtml(type, segs[i]);
|
|
|
}
|
|
|
|
|
|
// Grab individual elements from the combined HTML string. Use each as the default rendering.
|
|
|
@@ -59,14 +63,14 @@ var FillSystemMixin = { // use for highlight, background events, business hours
|
|
|
|
|
|
// allow custom filter methods per-type
|
|
|
if (segElMethod) {
|
|
|
- el = segElMethod.call(_this, seg, el);
|
|
|
+ el = segElMethod.call(component, seg, el);
|
|
|
}
|
|
|
|
|
|
if (el) { // custom filters did not cancel the render
|
|
|
el = $(el); // allow custom filter to return raw DOM node
|
|
|
|
|
|
// correct element type? (would be bad if a non-TD were inserted into a table for example)
|
|
|
- if (el.is(_this.fillSegTag)) {
|
|
|
+ if (el.is(component.fillSegTag || 'div')) {
|
|
|
seg.el = el;
|
|
|
renderedSegs.push(seg);
|
|
|
}
|
|
|
@@ -78,23 +82,21 @@ var FillSystemMixin = { // use for highlight, background events, business hours
|
|
|
},
|
|
|
|
|
|
|
|
|
- fillSegTag: 'div', // subclasses can override
|
|
|
-
|
|
|
-
|
|
|
// Builds the HTML needed for one fill segment. Generic enough to work with different types.
|
|
|
- fillSegHtml: function(type, seg) {
|
|
|
+ buildSegHtml: function(type, seg) {
|
|
|
+ var component = this.component;
|
|
|
|
|
|
// custom hooks per-type
|
|
|
- var classesMethod = this[type + 'SegClasses'];
|
|
|
- var cssMethod = this[type + 'SegCss'];
|
|
|
+ var classesMethod = component[type + 'SegClasses'];
|
|
|
+ var cssMethod = component[type + 'SegCss'];
|
|
|
|
|
|
- var classes = classesMethod ? classesMethod.call(this, seg) : [];
|
|
|
- var css = cssToStr(cssMethod ? cssMethod.call(this, seg) : {});
|
|
|
+ var classes = classesMethod ? classesMethod.call(component, seg) : [];
|
|
|
+ var css = cssToStr(cssMethod ? cssMethod.call(component, seg) : {});
|
|
|
|
|
|
- return '<' + this.fillSegTag +
|
|
|
+ return '<' + (component.fillSegTag || 'div') +
|
|
|
(classes.length ? ' class="' + classes.join(' ') + '"' : '') +
|
|
|
(css ? ' style="' + css + '"' : '') +
|
|
|
' />';
|
|
|
}
|
|
|
|
|
|
-};
|
|
|
+});
|