Initial commit. Modified the Meteor todos app to create the Petit Teton data tracking app. Has working data for sales. Requires a Mongo database.
This commit is contained in:
314
imports/util/selectize/selectize.default.import.styl
vendored
Normal file
314
imports/util/selectize/selectize.default.import.styl
vendored
Normal file
@@ -0,0 +1,314 @@
|
||||
/**
|
||||
* selectize.default.css (v0.12.0) - Default Theme
|
||||
* Copyright (c) 2013–2015 Brian Reavis & contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under
|
||||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
* ANY KIND, either express or implied. See the License for the specific language
|
||||
* governing permissions and limitations under the License.
|
||||
*
|
||||
* @author Brian Reavis <brian@thirdroute.com>
|
||||
*/
|
||||
.selectize-control.plugin-drag_drop.multi > .selectize-input > div.ui-sortable-placeholder
|
||||
visibility visible !important
|
||||
background #f2f2f2 !important
|
||||
background rgba(0, 0, 0, 0.06) !important
|
||||
border 0 none !important
|
||||
-webkit-box-shadow inset 0 0 12px 4px #ffffff
|
||||
box-shadow inset 0 0 12px 4px #ffffff
|
||||
.selectize-control.plugin-drag_drop .ui-sortable-placeholder::after
|
||||
content '!'
|
||||
visibility hidden
|
||||
.selectize-control.plugin-drag_drop .ui-sortable-helper
|
||||
-webkit-box-shadow 0 2px 5px rgba(0, 0, 0, 0.2)
|
||||
box-shadow 0 2px 5px rgba(0, 0, 0, 0.2)
|
||||
.selectize-dropdown-header
|
||||
position relative
|
||||
padding 5px 8px
|
||||
border-bottom 1px solid #d0d0d0
|
||||
background #f8f8f8
|
||||
-webkit-border-radius 3px 3px 0 0
|
||||
-moz-border-radius 3px 3px 0 0
|
||||
border-radius 3px 3px 0 0
|
||||
.selectize-dropdown-header-close
|
||||
position absolute
|
||||
right 8px
|
||||
top 50%
|
||||
color #303030
|
||||
opacity 0.4
|
||||
margin-top -12px
|
||||
line-height 20px
|
||||
font-size 20px !important
|
||||
.selectize-dropdown-header-close:hover
|
||||
color #000000
|
||||
.selectize-dropdown.plugin-optgroup_columns .optgroup
|
||||
border-right 1px solid #f2f2f2
|
||||
border-top 0 none
|
||||
float left
|
||||
-webkit-box-sizing border-box
|
||||
-moz-box-sizing border-box
|
||||
box-sizing border-box
|
||||
.selectize-dropdown.plugin-optgroup_columns .optgroup:last-child
|
||||
border-right 0 none
|
||||
.selectize-dropdown.plugin-optgroup_columns .optgroup:before
|
||||
display none
|
||||
.selectize-dropdown.plugin-optgroup_columns .optgroup-header
|
||||
border-top 0 none
|
||||
.selectize-control.plugin-remove_button [data-value]
|
||||
position relative
|
||||
padding-right 24px !important
|
||||
.selectize-control.plugin-remove_button [data-value] .remove
|
||||
z-index 1
|
||||
/* fixes ie bug (see #392) */
|
||||
position absolute
|
||||
top 0
|
||||
right 0
|
||||
bottom 0
|
||||
width 17px
|
||||
text-align center
|
||||
font-weight bold
|
||||
font-size 12px
|
||||
color inherit
|
||||
text-decoration none
|
||||
vertical-align middle
|
||||
display inline-block
|
||||
padding 2px 0 0 0
|
||||
border-left 1px solid #0073bb
|
||||
-webkit-border-radius 0 2px 2px 0
|
||||
-moz-border-radius 0 2px 2px 0
|
||||
border-radius 0 2px 2px 0
|
||||
-webkit-box-sizing border-box
|
||||
-moz-box-sizing border-box
|
||||
box-sizing border-box
|
||||
.selectize-control.plugin-remove_button [data-value] .remove:hover
|
||||
background rgba(0, 0, 0, 0.05)
|
||||
.selectize-control.plugin-remove_button [data-value].active .remove
|
||||
border-left-color #00578d
|
||||
.selectize-control.plugin-remove_button .disabled [data-value] .remove:hover
|
||||
background none
|
||||
.selectize-control.plugin-remove_button .disabled [data-value] .remove
|
||||
border-left-color #aaaaaa
|
||||
.selectize-control
|
||||
position relative
|
||||
.selectize-dropdown, .selectize-input, .selectize-input input
|
||||
color #303030
|
||||
font-family inherit
|
||||
font-size 13px
|
||||
line-height 18px
|
||||
-webkit-font-smoothing inherit
|
||||
.selectize-input, .selectize-control.single .selectize-input.input-active
|
||||
background #ffffff
|
||||
cursor text
|
||||
display inline-block
|
||||
.selectize-input
|
||||
border 1px solid #d0d0d0
|
||||
padding 8px 8px
|
||||
display inline-block
|
||||
width 100%
|
||||
overflow hidden
|
||||
position relative
|
||||
z-index 1
|
||||
-webkit-box-sizing border-box
|
||||
-moz-box-sizing border-box
|
||||
box-sizing border-box
|
||||
-webkit-box-shadow inset 0 1px 1px rgba(0, 0, 0, 0.1)
|
||||
box-shadow inset 0 1px 1px rgba(0, 0, 0, 0.1)
|
||||
-webkit-border-radius 3px
|
||||
-moz-border-radius 3px
|
||||
border-radius 3px
|
||||
.selectize-control.multi .selectize-input.has-items
|
||||
padding 5px 8px 2px
|
||||
.selectize-input.full
|
||||
background-color #ffffff
|
||||
.selectize-input.disabled, .selectize-input.disabled *
|
||||
cursor default !important
|
||||
.selectize-input.focus
|
||||
-webkit-box-shadow inset 0 1px 2px rgba(0, 0, 0, 0.15)
|
||||
box-shadow inset 0 1px 2px rgba(0, 0, 0, 0.15)
|
||||
.selectize-input.dropdown-active
|
||||
-webkit-border-radius 3px 3px 0 0
|
||||
-moz-border-radius 3px 3px 0 0
|
||||
border-radius 3px 3px 0 0
|
||||
.selectize-input > *
|
||||
vertical-align baseline
|
||||
display -moz-inline-stack
|
||||
display inline-block
|
||||
zoom 1
|
||||
*display inline .selectize-control.multi .selectize-input > div
|
||||
cursor pointer
|
||||
margin 0 3px 3px 0
|
||||
padding 2px 6px
|
||||
background #1da7ee
|
||||
color #ffffff
|
||||
border 1px solid #0073bb
|
||||
.selectize-control.multi .selectize-input > div.active
|
||||
background #92c836
|
||||
color #ffffff
|
||||
border 1px solid #00578d
|
||||
.selectize-control.multi .selectize-input.disabled > div, .selectize-control.multi .selectize-input.disabled > div.active
|
||||
color #ffffff
|
||||
background #d2d2d2
|
||||
border 1px solid #aaaaaa
|
||||
.selectize-input > input
|
||||
display inline-block !important
|
||||
padding 0 !important
|
||||
min-height 0 !important
|
||||
max-height none !important
|
||||
max-width 100% !important
|
||||
margin 0 1px !important
|
||||
text-indent 0 !important
|
||||
border 0 none !important
|
||||
background none !important
|
||||
line-height inherit !important
|
||||
-webkit-user-select auto !important
|
||||
-webkit-box-shadow none !important
|
||||
box-shadow none !important
|
||||
.selectize-input > input::-ms-clear
|
||||
display none
|
||||
.selectize-input > input:focus
|
||||
outline none !important
|
||||
.selectize-input::after
|
||||
content ' '
|
||||
display block
|
||||
clear left
|
||||
.selectize-input.dropdown-active::before
|
||||
content ' '
|
||||
display block
|
||||
position absolute
|
||||
background #f0f0f0
|
||||
height 1px
|
||||
bottom 0
|
||||
left 0
|
||||
right 0
|
||||
.selectize-dropdown
|
||||
position absolute
|
||||
z-index 10
|
||||
border 1px solid #d0d0d0
|
||||
background #ffffff
|
||||
margin -1px 0 0 0
|
||||
border-top 0 none
|
||||
-webkit-box-sizing border-box
|
||||
-moz-box-sizing border-box
|
||||
box-sizing border-box
|
||||
-webkit-box-shadow 0 1px 3px rgba(0, 0, 0, 0.1)
|
||||
box-shadow 0 1px 3px rgba(0, 0, 0, 0.1)
|
||||
-webkit-border-radius 0 0 3px 3px
|
||||
-moz-border-radius 0 0 3px 3px
|
||||
border-radius 0 0 3px 3px
|
||||
.selectize-dropdown [data-selectable]
|
||||
cursor pointer
|
||||
overflow hidden
|
||||
.selectize-dropdown [data-selectable] .highlight
|
||||
background rgba(125, 168, 208, 0.2)
|
||||
-webkit-border-radius 1px
|
||||
-moz-border-radius 1px
|
||||
border-radius 1px
|
||||
.selectize-dropdown [data-selectable], .selectize-dropdown .optgroup-header
|
||||
padding 5px 8px
|
||||
.selectize-dropdown .optgroup:first-child .optgroup-header
|
||||
border-top 0 none
|
||||
.selectize-dropdown .optgroup-header
|
||||
color #303030
|
||||
background #ffffff
|
||||
cursor default
|
||||
.selectize-dropdown .active
|
||||
background-color #f5fafd
|
||||
color #495c68
|
||||
.selectize-dropdown .active.create
|
||||
color #495c68
|
||||
.selectize-dropdown .create
|
||||
color rgba(48, 48, 48, 0.5)
|
||||
.selectize-dropdown-content
|
||||
overflow-y auto
|
||||
overflow-x hidden
|
||||
max-height 200px
|
||||
.selectize-control.single .selectize-input, .selectize-control.single .selectize-input input
|
||||
cursor pointer
|
||||
.selectize-control.single .selectize-input.input-active, .selectize-control.single .selectize-input.input-active input
|
||||
cursor text
|
||||
.selectize-control.single .selectize-input:after
|
||||
content ' '
|
||||
display block
|
||||
position absolute
|
||||
top 50%
|
||||
right 15px
|
||||
margin-top -3px
|
||||
width 0
|
||||
height 0
|
||||
border-style solid
|
||||
border-width 5px 5px 0 5px
|
||||
border-color #808080 transparent transparent transparent
|
||||
.selectize-control.single .selectize-input.dropdown-active:after
|
||||
margin-top -4px
|
||||
border-width 0 5px 5px 5px
|
||||
border-color transparent transparent #808080 transparent
|
||||
.selectize-control.rtl.single .selectize-input:after
|
||||
left 15px
|
||||
right auto
|
||||
.selectize-control.rtl .selectize-input > input
|
||||
margin 0 4px 0 -2px !important
|
||||
.selectize-control .selectize-input.disabled
|
||||
opacity 0.5
|
||||
background-color #fafafa
|
||||
.selectize-control.multi .selectize-input.has-items
|
||||
padding-left 5px
|
||||
padding-right 5px
|
||||
.selectize-control.multi .selectize-input.disabled [data-value]
|
||||
color #999
|
||||
text-shadow none
|
||||
background none
|
||||
-webkit-box-shadow none
|
||||
box-shadow none
|
||||
.selectize-control.multi .selectize-input.disabled [data-value], .selectize-control.multi .selectize-input.disabled [data-value] .remove
|
||||
border-color #e6e6e6
|
||||
.selectize-control.multi .selectize-input.disabled [data-value] .remove
|
||||
background none
|
||||
.selectize-control.multi .selectize-input [data-value]
|
||||
text-shadow 0 1px 0 rgba(0, 51, 83, 0.3)
|
||||
-webkit-border-radius 3px
|
||||
-moz-border-radius 3px
|
||||
border-radius 3px
|
||||
background-color #1b9dec
|
||||
background-image -moz-linear-gradient(top, rgb(29, 167, 238, 1), rgb(23, 142, 233, 1))
|
||||
background-image -webkit-gradient(linear, 0 0, 0 100%, from(rgb(29, 167, 238, 1)), to(rgb(23, 142, 233, 1)))
|
||||
background-image -webkit-linear-gradient(top, rgb(29, 167, 238, 1), rgb(23, 142, 233, 1))
|
||||
background-image -o-linear-gradient(top, rgb(29, 167, 238, 1), rgb(23, 142, 233, 1))
|
||||
background-image linear-gradient(to bottom, rgb(29, 167, 238, 1), rgb(23, 142, 233, 1))
|
||||
background-repeat repeat-x
|
||||
filter unquote("progid:DXImageTransform.Microsoft.gradient('#ff1da7ee', '#ff178ee9', 0)")
|
||||
-webkit-box-shadow 0 1px 0 rgba(0, 0, 0, 0.2), inset 0 1px rgba(255, 255, 255, 0.03)
|
||||
box-shadow 0 1px 0 rgba(0, 0, 0, 0.2), inset 0 1px rgba(255, 255, 255, 0.03)
|
||||
.selectize-control.multi .selectize-input [data-value].active
|
||||
background-color #0085d4
|
||||
background-image -moz-linear-gradient(top, rgb(0, 143, 216, 1), rgb(0, 117, 207, 1))
|
||||
background-image -webkit-gradient(linear, 0 0, 0 100%, from(rgb(0, 143, 216, 1)), to(rgb(0, 117, 207, 1)))
|
||||
background-image -webkit-linear-gradient(top, rgb(0, 143, 216, 1), rgb(0, 117, 207, 1))
|
||||
background-image -o-linear-gradient(top, rgb(0, 143, 216, 1), rgb(0, 117, 207, 1))
|
||||
background-image linear-gradient(to bottom, rgb(0, 143, 216, 1), rgb(0, 117, 207, 1))
|
||||
background-repeat repeat-x
|
||||
filter unquote("progid:DXImageTransform.Microsoft.gradient('#ff008fd8', '#ff0075cf', 0)")
|
||||
.selectize-control.single .selectize-input
|
||||
-webkit-box-shadow 0 1px 0 rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.8)
|
||||
box-shadow 0 1px 0 rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.8)
|
||||
background-color #f9f9f9
|
||||
background-image -moz-linear-gradient(top, rgb(254, 254, 254, 1), rgb(242, 242, 242, 1))
|
||||
background-image -webkit-gradient(linear, 0 0, 0 100%, from(rgb(254, 254, 254, 1)), to(rgb(242, 242, 242, 1)))
|
||||
background-image -webkit-linear-gradient(top, rgb(254, 254, 254, 1), rgb(242, 242, 242, 1))
|
||||
background-image -o-linear-gradient(top, rgb(254, 254, 254, 1), rgb(242, 242, 242, 1))
|
||||
background-image linear-gradient(to bottom, rgb(254, 254, 254, 1), rgb(242, 242, 242, 1))
|
||||
background-repeat repeat-x
|
||||
filter unquote("progid:DXImageTransform.Microsoft.gradient('#fffefefe', '#fff2f2f2', 0)")
|
||||
.selectize-control.single .selectize-input, .selectize-dropdown.single
|
||||
border-color #b8b8b8
|
||||
.selectize-dropdown .optgroup-header
|
||||
padding-top 7px
|
||||
font-weight bold
|
||||
font-size 0.85em
|
||||
.selectize-dropdown .optgroup
|
||||
border-top 1px solid #f0f0f0
|
||||
.selectize-dropdown .optgroup:first-child
|
||||
border-top 0 none
|
||||
57
imports/util/selectize/selectize.html
Normal file
57
imports/util/selectize/selectize.html
Normal file
@@ -0,0 +1,57 @@
|
||||
<template name="Selectize">
|
||||
<div class="selectize-control selectize {{#if multiple}}multi{{else}}single{{/if}} {{#if removeButton}}plugin-remove_button{{/if}} {{#if loading}}loading{{/if}}">
|
||||
<select name={{name}} multiple={{multiple}} id={{id}} data-schema-key={{dataSchemaKey}}>
|
||||
<option value=""></option>
|
||||
{{#each getItems}}
|
||||
<option value={{value}} selected={{selected}}>{{label}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
|
||||
<div class="selectize-input items not-full has-options has-items {{#if disabled}}disabled{{/if}} {{#if open}}focus input-active dropdown-active{{/if}}">
|
||||
{{#if getPlaceholder}}
|
||||
<div class="selectize-placeholder {{#if open}}hidden{{/if}}">
|
||||
{{getPlaceholder}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if inputPosition -1}}
|
||||
<input type="text" autocomplete="off" tabindex="" class="js-selectizeInput">
|
||||
{{/if}}
|
||||
|
||||
{{#each getItemsSelected}}
|
||||
<div data-value={{value}} class="item">
|
||||
{{label}}
|
||||
{{#if removeButton}}
|
||||
<a href="#" class="remove" tabindex="-1" title="Remove">×</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#if inputPosition @index}}
|
||||
<input type="text" autocomplete="off" tabindex="" class="js-selectizeInput">
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</div>
|
||||
|
||||
<div class="selectize-dropdown js-selectize-dropdown {{#unless open}}hidden{{/unless}}">
|
||||
<div class="selectize-dropdown-content">
|
||||
{{#each getItemsUnselected}}
|
||||
<div data-value={{value}} data-index={{@index}} data-selectable class="option {{#if activeOption @index}}active{{/if}} {{isPlaceholder}}">
|
||||
{{label}}
|
||||
</div>
|
||||
{{/each}}
|
||||
{{#if create}}
|
||||
{{#if getSearchText}}
|
||||
<div data-selectable="" data-index='create' class="create {{#if activeOption 'create'}}active{{/if}}">
|
||||
{{#if createText}}
|
||||
{{{createText}}}
|
||||
{{else}}
|
||||
Add
|
||||
{{/if}}
|
||||
<strong>{{getSearchText}}</strong>…
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
38
imports/util/selectize/selectize.import.styl
vendored
Normal file
38
imports/util/selectize/selectize.import.styl
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
.selectize.selectize-control
|
||||
position relative
|
||||
.hidden
|
||||
display none
|
||||
select
|
||||
display none
|
||||
.selectize-input
|
||||
input
|
||||
width 4px
|
||||
opacity 1
|
||||
position relative
|
||||
left 0px
|
||||
div.selectize-placeholder
|
||||
color #bbb
|
||||
background none
|
||||
border none
|
||||
&.input-active
|
||||
div.selectize-placeholder
|
||||
display none
|
||||
.selectize-dropdown
|
||||
width 100% !important
|
||||
top 36px
|
||||
&.loading:after
|
||||
content ""
|
||||
width 16px
|
||||
height 16px
|
||||
//background '/packages/vazco_selectize/img/loading.gif' no-repeat
|
||||
background 'public/images/loading.gif' no-repeat
|
||||
position absolute
|
||||
top 10px
|
||||
right 10px
|
||||
z-index 1000
|
||||
&.multi
|
||||
.selectize-input
|
||||
height 36px
|
||||
.uniPlaceholder
|
||||
color #bbb
|
||||
696
imports/util/selectize/selectize.js
Normal file
696
imports/util/selectize/selectize.js
Normal file
@@ -0,0 +1,696 @@
|
||||
|
||||
import './selectize.html';
|
||||
|
||||
/* Meteor need globals */
|
||||
/* eslint strict: 0 */
|
||||
/* jshint strict: false */
|
||||
|
||||
UniSelectize = function (options, template) {
|
||||
this.items = new ReactiveVar([]);
|
||||
this.itemsSelected = new ReactiveVar([]);
|
||||
this.itemsUnselected = new ReactiveVar([]);
|
||||
|
||||
this.open = new ReactiveVar(false);
|
||||
this.loading = new ReactiveVar(false);
|
||||
this.searchText = new ReactiveVar();
|
||||
this.activeOption = new ReactiveVar(-1);
|
||||
this.inputPosition = new ReactiveVar(-1);
|
||||
this.optionsMethodParams = new ReactiveVar();
|
||||
|
||||
this.create = options.create;
|
||||
this.template = template;
|
||||
this.multiple = options.multiple;
|
||||
this.sortMethod = _.isUndefined(options.sortMethod) ? 'label' : options.sortMethod;
|
||||
this.placeholder = options.placeholder;
|
||||
this.removeButton = options.removeButton !== false;
|
||||
this.createMethod = options.createMethod;
|
||||
this.optionsMethod = options.optionsMethod;
|
||||
this.optionsPlaceholder = options.optionsPlaceholder;
|
||||
|
||||
};
|
||||
|
||||
UniSelectize.prototype.triggerChangeEvent = function() {
|
||||
var self = this;
|
||||
Meteor.defer(function () {
|
||||
$(self.template.find('select')).change();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
UniSelectize.prototype.setItems = function (items, value) {
|
||||
if (!_.isArray(items)) {
|
||||
console.warn('invalid options format');
|
||||
}
|
||||
|
||||
var values = value && (_.isArray(value) ? value : [value]);
|
||||
|
||||
items = _.filter(items, function (item) {
|
||||
if (!item.value || !item.label) {
|
||||
console.info('invalid option', item);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
var itemValues = items.map(function (item) {
|
||||
return item.value;
|
||||
});
|
||||
|
||||
_.each(values, function (val) {
|
||||
if (!_.contains(itemValues, val) && val) {
|
||||
items.push({
|
||||
value: val,
|
||||
label: val
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
_.each(items, function (item) {
|
||||
if (_.contains(values, item.value)) {
|
||||
item.selected = true;
|
||||
}
|
||||
});
|
||||
this.items.set(items);
|
||||
};
|
||||
|
||||
UniSelectize.prototype.addItems = function (newItems, value) {
|
||||
if (!_.isArray(newItems)) {
|
||||
console.warn('invalid options format');
|
||||
}
|
||||
|
||||
var values = value && (_.isArray(value) ? value : [value]);
|
||||
var items = this.items.get();
|
||||
var itemsValues = items.map(function (item) {
|
||||
return item.value;
|
||||
});
|
||||
|
||||
_.each(newItems, function (newItem) {
|
||||
if (!newItem.value || !newItem.label) {
|
||||
console.info('invalid option', newItem);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_.contains(itemsValues, newItem.value)) {
|
||||
var item = {
|
||||
value: newItem.value,
|
||||
label: newItem.label,
|
||||
selected: newItem.selected
|
||||
};
|
||||
|
||||
if (_.contains(values, newItem.value)) {
|
||||
item.selected = true;
|
||||
}
|
||||
|
||||
items.push(item);
|
||||
} else if (typeof newItem.selected !== 'undefined') {
|
||||
var item = _.find(items, function (item) {
|
||||
return item.value === newItem.value;
|
||||
});
|
||||
item.selected = newItem.selected;
|
||||
}
|
||||
});
|
||||
|
||||
this.items.set(items);
|
||||
};
|
||||
|
||||
|
||||
UniSelectize.prototype.removeUnusedItems = function (newItems) {
|
||||
if (!_.isArray(newItems)) {
|
||||
console.warn('invalid options format');
|
||||
}
|
||||
|
||||
var items = this.items.get();
|
||||
var newItemsValues = newItems.map(function (item) {
|
||||
return item.value;
|
||||
});
|
||||
|
||||
items = _.filter(items, function (item) {
|
||||
return _.contains(newItemsValues, item.value) || item.selected;
|
||||
});
|
||||
|
||||
this.items.set(items);
|
||||
};
|
||||
|
||||
UniSelectize.prototype.itemsAutorun = function () {
|
||||
var items = this.items.get();
|
||||
var itemsSelected = [];
|
||||
var itemsUnselected = [];
|
||||
|
||||
_.each(items, function (item) {
|
||||
if (item.selected) {
|
||||
itemsSelected.push(item);
|
||||
} else {
|
||||
itemsUnselected.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.sortMethod) {
|
||||
itemsSelected = _.sortBy(itemsSelected, this.sortMethod);
|
||||
itemsUnselected = _.sortBy(itemsUnselected, this.sortMethod);
|
||||
}
|
||||
|
||||
var itemsSelectedPrev = this.itemsSelected.get();
|
||||
if (!_.isEqual(itemsSelectedPrev, itemsSelected)) {
|
||||
this.itemsSelected.set(itemsSelected);
|
||||
}
|
||||
|
||||
if (this.placeholder && this.optionsPlaceholder) {
|
||||
itemsUnselected.unshift({
|
||||
value: '',
|
||||
label: _.isString(this.optionsPlaceholder) ? this.optionsPlaceholder: this.placeholder
|
||||
});
|
||||
}
|
||||
|
||||
this.itemsUnselected.set(itemsUnselected);
|
||||
};
|
||||
|
||||
UniSelectize.prototype.itemsSelectedAutorun = function () {
|
||||
var itemsSelected = this.template.uniSelectize.itemsSelected.get();
|
||||
this.template.uniSelectize.inputPosition.set(itemsSelected.length - 1);
|
||||
};
|
||||
|
||||
UniSelectize.prototype.inputFocus = function () {
|
||||
var self = this;
|
||||
Meteor.defer(function () {
|
||||
var $input = $(self.template.find('input'));
|
||||
$input.focus();
|
||||
});
|
||||
};
|
||||
|
||||
UniSelectize.prototype.selectItem = function (value) {
|
||||
var items = this.items.get();
|
||||
var multiple = this.multiple;
|
||||
|
||||
_.each(items, function (item) {
|
||||
if (value === '') {
|
||||
item.selected = false;
|
||||
} else if (item.value === value) {
|
||||
item.selected = true;
|
||||
} else if (!multiple) {
|
||||
item.selected = false;
|
||||
}
|
||||
});
|
||||
|
||||
this.setItems(items);
|
||||
this.triggerChangeEvent();
|
||||
};
|
||||
|
||||
UniSelectize.prototype.unselectItem = function (value, reset) {
|
||||
var items = this.items.get();
|
||||
|
||||
_.each(items, function (item) {
|
||||
if (item.value === value || reset) {
|
||||
item.selected = false;
|
||||
}
|
||||
});
|
||||
|
||||
this.setItems(items);
|
||||
this.triggerChangeEvent()
|
||||
};
|
||||
|
||||
UniSelectize.prototype.removeItemBeforeInput = function () {
|
||||
var items = this.itemsSelected.get();
|
||||
var inputPosition = this.inputPosition.get();
|
||||
var itemToRemove;
|
||||
|
||||
_.each(items, function (item, index) {
|
||||
if (index === inputPosition) {
|
||||
itemToRemove = item;
|
||||
}
|
||||
});
|
||||
|
||||
if (itemToRemove) {
|
||||
this.unselectItem(itemToRemove.value, false);
|
||||
}
|
||||
};
|
||||
|
||||
UniSelectize.prototype.removeItemAfterInput = function () {
|
||||
var items = this.itemsSelected.get();
|
||||
var inputPosition = this.inputPosition.get();
|
||||
var itemToRemove;
|
||||
|
||||
_.each(items, function (item, index) {
|
||||
if (index === inputPosition + 1) {
|
||||
itemToRemove = item;
|
||||
}
|
||||
});
|
||||
|
||||
if (itemToRemove) {
|
||||
this.unselectItem(itemToRemove.value, false);
|
||||
}
|
||||
};
|
||||
|
||||
UniSelectize.prototype.selectActiveItem = function () {
|
||||
var itemsUnselected = this.getItemsUnselectedFiltered();
|
||||
var activeOption = this.activeOption.get();
|
||||
var itemToSelect = itemsUnselected && itemsUnselected[activeOption];
|
||||
|
||||
if (activeOption === itemsUnselected.length && this.create) {
|
||||
this.createItem();
|
||||
return;
|
||||
}
|
||||
|
||||
itemToSelect && this.selectItem(itemToSelect.value);
|
||||
|
||||
if (this.multiple) {
|
||||
this.open.set(true);
|
||||
this.inputFocus();
|
||||
} else {
|
||||
this.open.set(false);
|
||||
}
|
||||
};
|
||||
|
||||
UniSelectize.prototype.insertItem = function (item) {
|
||||
var items = this.items.get();
|
||||
|
||||
if (!_.find(items, function (obj) {
|
||||
if (obj.value === item.value) {
|
||||
obj.selected = item.selected;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})) {
|
||||
items.push(item);
|
||||
}
|
||||
|
||||
this.setItems(items);
|
||||
this.triggerChangeEvent();
|
||||
};
|
||||
|
||||
UniSelectize.prototype.createItem = function () {
|
||||
var self = this;
|
||||
var template = this.template;
|
||||
var searchText = this.searchText.get();
|
||||
|
||||
if (!searchText) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var item = {
|
||||
label: searchText,
|
||||
value: searchText,
|
||||
selected: true
|
||||
};
|
||||
|
||||
if (template.uniSelectize.createMethod) {
|
||||
Meteor.call(template.uniSelectize.createMethod, searchText, searchText, function (error, value) {
|
||||
if (error) {
|
||||
console.error('universe selectize create method error:', error);
|
||||
return;
|
||||
}
|
||||
|
||||
Meteor.defer(function () {
|
||||
item.value = value || item.value;
|
||||
self.insertItem(item);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.insertItem(item);
|
||||
}
|
||||
|
||||
if (this.multiple) {
|
||||
this.inputFocus();
|
||||
} else {
|
||||
this.open.set(false);
|
||||
}
|
||||
};
|
||||
|
||||
UniSelectize.prototype.getItemsUnselectedFiltered = function () {
|
||||
var items = this.itemsUnselected.get();
|
||||
var searchText = this.searchText.get();
|
||||
|
||||
return _.filter(items, function (item) {
|
||||
if (item.label && item.label.search(new RegExp(searchText, 'i')) !== -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
UniSelectize.prototype.checkDisabled = function () {
|
||||
if (this.template.data.disabled) {
|
||||
throw new Meteor.Error('This field is disabled');
|
||||
}
|
||||
};
|
||||
|
||||
UniSelectize.prototype.measureString = function (str, $parent) {
|
||||
if (!str) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var $test = $('<test>').css({
|
||||
position: 'absolute',
|
||||
top: -99999,
|
||||
left: -99999,
|
||||
width: 'auto',
|
||||
padding: 0,
|
||||
whiteSpace: 'pre'
|
||||
}).text(str).appendTo('body');
|
||||
|
||||
this.transferStyles($parent, $test, [
|
||||
'letterSpacing',
|
||||
'fontSize',
|
||||
'fontFamily',
|
||||
'fontWeight',
|
||||
'textTransform'
|
||||
]);
|
||||
|
||||
var width = $test.width();
|
||||
$test.remove();
|
||||
|
||||
return width;
|
||||
};
|
||||
|
||||
UniSelectize.prototype.transferStyles = function ($from, $to, properties) {
|
||||
var i, n, styles = {};
|
||||
|
||||
if (properties) {
|
||||
for (i = 0, n = properties.length; i < n; i++) {
|
||||
styles[properties[i]] = $from.css(properties[i]);
|
||||
}
|
||||
} else {
|
||||
styles = $from.css();
|
||||
}
|
||||
|
||||
$to.css(styles);
|
||||
};
|
||||
|
||||
UniSelectize.prototype.getOptionsFromMethod = function (values) {
|
||||
var self = this;
|
||||
var methodName = this.optionsMethod;
|
||||
var searchText = this.searchText.get();
|
||||
var params = this.optionsMethodParams.get();
|
||||
|
||||
if (!methodName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var searchVal = {
|
||||
searchText: searchText,
|
||||
values: values || [],
|
||||
params: params || null
|
||||
};
|
||||
|
||||
self.loading.set(true);
|
||||
Meteor.call(methodName, searchVal, function (err, options) {
|
||||
self.loading.set(false);
|
||||
if (params) {
|
||||
self.removeUnusedItems(options);
|
||||
}
|
||||
self.addItems(options, values);
|
||||
});
|
||||
};
|
||||
|
||||
Template.Selectize.onCreated(function () {
|
||||
var template = this;
|
||||
template.uniSelectize = new UniSelectize(template.data, template);
|
||||
});
|
||||
|
||||
Template.Selectize.onRendered(function () {
|
||||
var template = this;
|
||||
|
||||
template.autorun(function () {
|
||||
var data = Template.currentData();
|
||||
var value = data.value;
|
||||
|
||||
if (template.uniSelectize.optionsMethod) {
|
||||
template.uniSelectize.getOptionsFromMethod(value);
|
||||
} else {
|
||||
var options = data.options;
|
||||
template.uniSelectize.setItems(options, value);
|
||||
}
|
||||
});
|
||||
|
||||
template.autorun(function () {
|
||||
template.uniSelectize.itemsAutorun();
|
||||
});
|
||||
|
||||
template.autorun(function () {
|
||||
template.uniSelectize.itemsSelectedAutorun();
|
||||
});
|
||||
|
||||
template.autorun(function () {
|
||||
var data = Template.currentData();
|
||||
var methodParams = data.optionsMethodParams;
|
||||
var params = _.isFunction(methodParams) ? methodParams() : methodParams;
|
||||
|
||||
template.uniSelectize.optionsMethodParams.set(params);
|
||||
});
|
||||
|
||||
this.form = $(template.find('select')).parents('form');
|
||||
this.form.bind('reset', function () {
|
||||
template.uniSelectize.unselectItem(null, true);
|
||||
});
|
||||
});
|
||||
|
||||
Template.Selectize.onDestroyed(function () {
|
||||
if (this.form) {
|
||||
this.form.unbind('reset');
|
||||
}
|
||||
});
|
||||
|
||||
Template.Selectize.helpers({
|
||||
multiple: function () {
|
||||
var template = Template.instance();
|
||||
return template.uniSelectize.multiple;
|
||||
},
|
||||
removeButton: function () {
|
||||
var template = Template.instance();
|
||||
return template.uniSelectize.multiple && template.uniSelectize.removeButton;
|
||||
},
|
||||
getItems: function () {
|
||||
var template = Template.instance();
|
||||
return template.uniSelectize.items.get();
|
||||
},
|
||||
getItemsSelected: function () {
|
||||
var template = Template.instance();
|
||||
return template.uniSelectize.itemsSelected.get();
|
||||
},
|
||||
getItemsUnselected: function () {
|
||||
var template = Template.instance();
|
||||
return template.uniSelectize.getItemsUnselectedFiltered();
|
||||
},
|
||||
getSearchText: function () {
|
||||
var template = Template.instance();
|
||||
return template.uniSelectize.searchText.get();
|
||||
},
|
||||
open: function () {
|
||||
var template = Template.instance();
|
||||
return template.uniSelectize.open.get();
|
||||
},
|
||||
loading: function () {
|
||||
var template = Template.instance();
|
||||
return template.uniSelectize.loading.get();
|
||||
},
|
||||
inputPosition: function (position) {
|
||||
var template = Template.instance();
|
||||
var inputPosition = template.uniSelectize.inputPosition.get();
|
||||
return position === inputPosition;
|
||||
},
|
||||
activeOption: function (position) {
|
||||
var template = Template.instance();
|
||||
var activeOption = template.uniSelectize.activeOption.get();
|
||||
var itemsUnselected = template.uniSelectize.getItemsUnselectedFiltered();
|
||||
var createOption = template.uniSelectize.create;
|
||||
|
||||
if (activeOption === itemsUnselected.length && createOption) {
|
||||
return position === 'create';
|
||||
}
|
||||
|
||||
return position === activeOption;
|
||||
},
|
||||
getPlaceholder: function () {
|
||||
var template = Template.instance();
|
||||
var itemsSelected = template.uniSelectize.itemsSelected.get();
|
||||
|
||||
if (itemsSelected.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return template.uniSelectize.placeholder;
|
||||
},
|
||||
isPlaceholder: function () {
|
||||
return this.value === '' ? 'uniPlaceholder' : '';
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Template.Selectize.events({
|
||||
'click .selectize-input': function (e, template) {
|
||||
template.uniSelectize.checkDisabled();
|
||||
template.uniSelectize.inputFocus(template);
|
||||
|
||||
template.uniSelectize.getOptionsFromMethod();
|
||||
},
|
||||
'keydown input.js-selectizeInput': function (e, template) {
|
||||
var uniSelectize = template.uniSelectize;
|
||||
var itemsSelected = uniSelectize.itemsSelected.get();
|
||||
var itemsUnselected = uniSelectize.getItemsUnselectedFiltered();
|
||||
var inputPosition = uniSelectize.inputPosition.get();
|
||||
var activeOption = uniSelectize.activeOption.get();
|
||||
|
||||
template.uniSelectize.checkDisabled();
|
||||
|
||||
var $input = $(e.target);
|
||||
var width = template.uniSelectize.measureString($input.val(), $input) + 10;
|
||||
|
||||
$input.width(width);
|
||||
|
||||
switch (e.keyCode) {
|
||||
case 8: // backspace
|
||||
if ($input.val() === '') {
|
||||
e.preventDefault();
|
||||
uniSelectize.removeItemBeforeInput();
|
||||
}
|
||||
uniSelectize.open.set(true);
|
||||
uniSelectize.inputFocus();
|
||||
|
||||
break;
|
||||
|
||||
case 46: // delete
|
||||
if ($input.val() === '') {
|
||||
uniSelectize.removeItemAfterInput();
|
||||
}
|
||||
uniSelectize.open.set(true);
|
||||
uniSelectize.inputFocus();
|
||||
|
||||
break;
|
||||
|
||||
case 27: // escape
|
||||
$input.blur();
|
||||
break;
|
||||
|
||||
case 13: // enter
|
||||
e.preventDefault();
|
||||
|
||||
if (activeOption === -1 && $input.val() === '') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (itemsUnselected && itemsUnselected.length > 0) {
|
||||
uniSelectize.selectActiveItem(template);
|
||||
uniSelectize.searchText.set('');
|
||||
$input.val('');
|
||||
} else if (uniSelectize.create /*&& createOnBlur*/) {
|
||||
uniSelectize.createItem();
|
||||
uniSelectize.searchText.set('');
|
||||
$input.val('');
|
||||
}
|
||||
|
||||
break;
|
||||
case 37: // left
|
||||
if (!uniSelectize.multiple) {
|
||||
break;
|
||||
}
|
||||
if (inputPosition > -1) {
|
||||
uniSelectize.inputPosition.set(inputPosition - 1);
|
||||
uniSelectize.inputFocus();
|
||||
}
|
||||
break;
|
||||
case 39: // right
|
||||
if (!uniSelectize.multiple) {
|
||||
break;
|
||||
}
|
||||
if (inputPosition < itemsSelected.length - 1) {
|
||||
uniSelectize.inputPosition.set(inputPosition + 1);
|
||||
uniSelectize.inputFocus();
|
||||
}
|
||||
break;
|
||||
case 38: // up
|
||||
if (activeOption > -1) {
|
||||
uniSelectize.activeOption.set(activeOption - 1);
|
||||
}
|
||||
break;
|
||||
case 40: // down
|
||||
if (activeOption < itemsUnselected.length - 1 ||
|
||||
(activeOption < itemsUnselected.length && uniSelectize.create)) {
|
||||
uniSelectize.activeOption.set(activeOption + 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!template.uniSelectize.multiple && itemsSelected.length) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'keyup input.js-selectizeInput': function (e, template) {
|
||||
template.uniSelectize.checkDisabled();
|
||||
|
||||
var $el = $(e.target);
|
||||
var value = $el.val();
|
||||
template.uniSelectize.searchText.set(value);
|
||||
template.uniSelectize.getOptionsFromMethod();
|
||||
},
|
||||
'focus input.js-selectizeInput': function (e, template) {
|
||||
template.uniSelectize.checkDisabled();
|
||||
template.uniSelectize.open.set(true);
|
||||
|
||||
Meteor.clearTimeout(template.uniSelectize.timeoutId);
|
||||
},
|
||||
'change input.js-selectizeInput': function(e, template) {
|
||||
template.uniSelectize.checkDisabled();
|
||||
|
||||
// prevent non-autoform fields changes from submitting the form when autosave is enabled
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
},
|
||||
'blur input.js-selectizeInput': function (e, template) {
|
||||
template.uniSelectize.checkDisabled();
|
||||
|
||||
template.uniSelectize.timeoutId = Meteor.setTimeout(function () {
|
||||
template.uniSelectize.open.set(false);
|
||||
}, 500);
|
||||
},
|
||||
'scroll .selectize-dropdown-content': function (e, template) {
|
||||
Meteor.clearTimeout(template.uniSelectize.timeoutId);
|
||||
template.uniSelectize.timeoutId = Meteor.setTimeout(function () {
|
||||
template.uniSelectize.open.set(false);
|
||||
}, 5000);
|
||||
},
|
||||
'click .selectize-dropdown-content > div:not(.create)': function (e, template) {
|
||||
e.preventDefault();
|
||||
template.uniSelectize.checkDisabled();
|
||||
var $input = $(template.find('input'));
|
||||
var itemsUnselected = template.uniSelectize.getItemsUnselectedFiltered();
|
||||
var itemsUnselectedLength = itemsUnselected && itemsUnselected.length;
|
||||
|
||||
template.uniSelectize.selectItem(this.value);
|
||||
template.uniSelectize.searchText.set('');
|
||||
$input.val('');
|
||||
|
||||
if (template.uniSelectize.multiple && itemsUnselectedLength && this.value) {
|
||||
template.uniSelectize.inputFocus();
|
||||
} else {
|
||||
template.uniSelectize.open.set(false);
|
||||
}
|
||||
},
|
||||
'mouseenter .selectize-dropdown-content > div': function (e, template) {
|
||||
var $el = $(e.target);
|
||||
var elIndex = $el.attr('data-index');
|
||||
var itemsUnselected = template.uniSelectize.getItemsUnselectedFiltered();
|
||||
|
||||
if (elIndex === 'create') {
|
||||
elIndex = itemsUnselected.length;
|
||||
} else {
|
||||
elIndex = parseInt(elIndex);
|
||||
}
|
||||
|
||||
template.uniSelectize.activeOption.set(elIndex);
|
||||
},
|
||||
'click .create': function (e, template) {
|
||||
e.preventDefault();
|
||||
template.uniSelectize.checkDisabled();
|
||||
var $input = $(template.find('input'));
|
||||
|
||||
template.uniSelectize.createItem();
|
||||
template.uniSelectize.searchText.set('');
|
||||
$input.val('');
|
||||
},
|
||||
'click .remove': function (e, template) {
|
||||
e.preventDefault();
|
||||
template.uniSelectize.checkDisabled();
|
||||
|
||||
template.uniSelectize.unselectItem(this.value, false);
|
||||
}
|
||||
});
|
||||
0
imports/util/selectize/temp.import.styl
vendored
Normal file
0
imports/util/selectize/temp.import.styl
vendored
Normal file
Reference in New Issue
Block a user