Added a Sales Sheet page along with other changes.
This commit is contained in:
@@ -199,11 +199,31 @@
|
||||
if(this.$hidden && _this.$hidden.val()) {
|
||||
hiddenInputChanged();
|
||||
}
|
||||
|
||||
//TODO: Should probably check to ensure comparator is a function? Not that it will help much if the function is not written correctly. Stupid Javascript!
|
||||
if(this.options.selection && this.options.comparator) {
|
||||
Tracker.autorun(function() {
|
||||
let selectedData = this.options.selection.get();
|
||||
|
||||
if(selectedData) {
|
||||
let listItems = this.$list.children();
|
||||
let found = false;
|
||||
|
||||
for(let i = 0; !found && i < listItems.length; i++) {
|
||||
if(this.options.comparator($(listItems[i]).data('model'), selectedData)) {
|
||||
found = true;
|
||||
this.select($(listItems[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
Combo.DEFAULTS = {
|
||||
cursor: undefined, //A meteor Cursor.
|
||||
selection: undefined, //A meteor ReactiveVar whose value will be set to the current selection.
|
||||
comparator: undefined, //A function that takes two collection objects and compares them for equality. If the combo shows users for example, this comparator would compare one user id to another. Required for the combo to set the selection if the view changes it externally relative to this combo.
|
||||
textAttr: 'text', //The attribute of the data elements to use for the name. This can also be a function that takes the data object and returns the text.
|
||||
idAttr: 'id', //The attribute of the data elements to use for the ID. This can also be a function that takes the data obejct and returns the ID.
|
||||
// groupFunctions: The object containing three functions: 'groupParent', 'parentText', 'children'.
|
||||
@@ -222,7 +242,7 @@
|
||||
Combo.prototype.select = function($li) {
|
||||
if($li.length == 0) {
|
||||
if(this.$input.val() != '') {
|
||||
this.$input.val("")
|
||||
this.$input.val("");
|
||||
if(this.$hidden) this.$hidden.val(undefined).change();
|
||||
this.filter();
|
||||
//Note: Don't trigger the select event - for some reason it causes the dropdown to reopen and the control to retain focus when clicking out of the widget.
|
||||
@@ -242,13 +262,17 @@
|
||||
this.filter();
|
||||
//this.trigger('select', $li);
|
||||
|
||||
//Set the reactive var for the selection if one is provided.
|
||||
if(this.options.selection) {
|
||||
//Set the reactive var for the selection if one is provided and the selection has changed relative to the model.
|
||||
if(this.options.selection && this.options.selection.get() != $li.data('model')) {
|
||||
this.options.selection.set($li.data('model'));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Combo.prototype.escapeRegex = function(s) {
|
||||
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
};
|
||||
|
||||
//Filters the list items by marking those that match the text in the text field as having the class 'visible'.
|
||||
Combo.prototype.filter = function() {
|
||||
@@ -273,7 +297,7 @@
|
||||
|
||||
if(searches) {
|
||||
for(let i = 0; i < searches.length; i++) {
|
||||
regexs.push(new RegExp("\\b" + searches[i]));
|
||||
regexs.push(new RegExp("\\b" + this.escapeRegex(searches[i])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
|
||||
if (!Array.prototype.includes) {
|
||||
if(!Array.prototype.includes) {
|
||||
Object.defineProperty(Array.prototype, 'includes', {
|
||||
value: function(searchElement, fromIndex) {
|
||||
|
||||
@@ -8,10 +8,10 @@ if (!Array.prototype.includes) {
|
||||
throw new TypeError('"this" is null or not defined');
|
||||
}
|
||||
|
||||
var o = Object(this);
|
||||
let o = Object(this);
|
||||
|
||||
// 2. Let len be ? ToLength(? Get(O, "length")).
|
||||
var len = o.length >>> 0;
|
||||
let len = o.length >>> 0;
|
||||
|
||||
// 3. If len is 0, return false.
|
||||
if (len === 0) {
|
||||
@@ -20,14 +20,14 @@ if (!Array.prototype.includes) {
|
||||
|
||||
// 4. Let n be ? ToInteger(fromIndex).
|
||||
// (If fromIndex is undefined, this step produces the value 0.)
|
||||
var n = fromIndex | 0;
|
||||
let n = fromIndex | 0;
|
||||
|
||||
// 5. If n ≥ 0, then
|
||||
// a. Let k be n.
|
||||
// 6. Else n < 0,
|
||||
// a. Let k be len + n.
|
||||
// b. If k < 0, let k be 0.
|
||||
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
|
||||
let k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
|
||||
|
||||
// 7. Repeat, while k < len
|
||||
while (k < len) {
|
||||
@@ -45,4 +45,64 @@ if (!Array.prototype.includes) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//http://stackoverflow.com/questions/5306680/move-an-array-element-from-one-array-position-to-another
|
||||
if(!Array.prototype.move) {
|
||||
Array.prototype.move = function (old_index, new_index) {
|
||||
if (new_index >= this.length) {
|
||||
let k = new_index - this.length;
|
||||
while ((k--) + 1) {
|
||||
this.push(undefined);
|
||||
}
|
||||
}
|
||||
this.splice(new_index, 0, this.splice(old_index, 1)[0]);
|
||||
return this; // for testing purposes
|
||||
};
|
||||
}
|
||||
|
||||
//My own implementation to work around Javascript's shitty naming and support for collection operations.
|
||||
if(!Array.prototype.remove) {
|
||||
Array.prototype.remove = function(item) {
|
||||
let index = this.indexOf(item);
|
||||
|
||||
if(index != -1) {
|
||||
this.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//My own implementation to work around Javascript's shitty naming and support for collection operations.
|
||||
// index is optional
|
||||
if(!Array.prototype.add) {
|
||||
Array.prototype.add = function(item, index) {
|
||||
if(index == undefined || isNaN(index) || index >= this.length) return this.push(item);
|
||||
else return this.splice(index, 0, item);
|
||||
}
|
||||
}
|
||||
|
||||
//My own implementation to work around Javascript's shitty naming and support for collection operations.
|
||||
// Sorts a contiguous section of the array.
|
||||
// Index is the index of the first element to be sorted (inclusive).
|
||||
// Length is the number of elements of the array to be sorted (must be >= 2). If the length + index is greater than the array length then it will be adjusted to the end of the array.
|
||||
// All other invalid inputs will result in no sorting action taken and no error.
|
||||
if(!Array.prototype.partialSort) {
|
||||
Array.prototype.partialSort = function(index, length, compareFunction) {
|
||||
if(index >= 0 && length >= 2 && index <= (this.length - 2)) {
|
||||
//Adjust the length so it doesn't over-run the array. This is the only error correction we will perform.
|
||||
if(index + length > this.length) length = this.length - index;
|
||||
|
||||
//Shallow copy of the data in the segment to be sorted.
|
||||
let sorted = this.slice(index, length + index);
|
||||
|
||||
sorted.sort(compareFunction);
|
||||
|
||||
//Put the sorted array elements back into the array.
|
||||
for(let i = index, j = 0; i <= length; i++, j++) {
|
||||
this[i] = sorted[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
* @param {Number} [levels] How many levels to go up. Default is 1
|
||||
* @returns {Blaze.TemplateInstance}
|
||||
*/
|
||||
Blaze.TemplateInstance.prototype.parentTemplate = function(levels) {
|
||||
Blaze.TemplateInstance.prototype.parentTemplate = Blaze.TemplateInstance.prototype.parentInstance = function(levels) {
|
||||
let view = this.view;
|
||||
|
||||
levels = (typeof levels === "undefined") ? 1 : levels;
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
* validate(fn) - Forces validation to occur and takes an optional callback which will be passed a flag (boolean) indicating the success of the validation (isValid).
|
||||
* reset() - Resets the form's validation status. Clears all error information, without turning validation off.
|
||||
* update() - Updates the collection of fields that require validation. Call this after making changes to the form, including initializing any form elements that may generate HTML (such as Select2).
|
||||
*
|
||||
* Notes:
|
||||
* To handle decimal values "0.05", you need to add `step='0.01'` or similar to the input field.
|
||||
* To get the validator to validate a field, you must add `required` to the property list: `<input type='text' required/>`
|
||||
* I have modified this to not require a form-group or form-input classed container. If one is found, then the container will be used to mark for errors and success, otherwise the field element will be marked instead. Example: `<div class='form-group'><input type='text' required/></div>`
|
||||
*/
|
||||
|
||||
+function ($) {
|
||||
@@ -372,8 +377,11 @@
|
||||
|
||||
$block.empty().append(errors);
|
||||
|
||||
//Add the 'has-error' and 'has-danger' classes to the grouping.
|
||||
$group.addClass('has-error has-danger');
|
||||
if($group.length > 0)
|
||||
//Add the 'has-error' and 'has-danger' classes to the grouping.
|
||||
$group.addClass('has-error has-danger');
|
||||
else
|
||||
$el.addClass('has-error has-danger');
|
||||
|
||||
//If this is a select2 control then look for the child of a sibling that has the .select2-selection class and use it instead.
|
||||
if($el.hasClass('select2-hidden-accessible')) {
|
||||
@@ -395,7 +403,11 @@
|
||||
var $feedback = $group.find('.form-control-feedback');
|
||||
|
||||
$block.html($block.data('bs.validator.originalContent'));
|
||||
$group.removeClass('has-error has-danger has-success');
|
||||
|
||||
if($group.length > 0)
|
||||
$group.removeClass('has-error has-danger has-success');
|
||||
else
|
||||
$el.removeClass('has-error has-danger has-success');
|
||||
|
||||
//Clean the sibling controls for select2.
|
||||
$el.parent().find('.select2 .select2-selection').removeClass('has-error has-danger has-success');
|
||||
|
||||
Reference in New Issue
Block a user