smartkiosk-server 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +32 -0
- data/.rspec +1 -0
- data/Capfile +4 -0
- data/Gemfile +71 -0
- data/Gemfile.lock +439 -0
- data/Guardfile +25 -0
- data/LICENSE +287 -0
- data/README.md +13 -0
- data/Rakefile +5 -0
- data/app/acquirers/cards_mkb_acquirer.rb +87 -0
- data/app/acquirers/cash_acquirer.rb +22 -0
- data/app/admin/agents.rb +108 -0
- data/app/admin/collections.rb +62 -0
- data/app/admin/commissions.rb +87 -0
- data/app/admin/gateways.rb +183 -0
- data/app/admin/limits.rb +82 -0
- data/app/admin/payments.rb +246 -0
- data/app/admin/provider_groups.rb +60 -0
- data/app/admin/provider_profiles.rb +11 -0
- data/app/admin/provider_receipt_templates.rb +82 -0
- data/app/admin/providers.rb +201 -0
- data/app/admin/rebates.rb +83 -0
- data/app/admin/report_results.rb +66 -0
- data/app/admin/report_templates.rb +209 -0
- data/app/admin/reports.rb +158 -0
- data/app/admin/revisions.rb +120 -0
- data/app/admin/system_receipt_templates.rb +76 -0
- data/app/admin/terminal_builds.rb +39 -0
- data/app/admin/terminal_profiles.rb +123 -0
- data/app/admin/terminals.rb +388 -0
- data/app/admin/users.rb +117 -0
- data/app/admin/versions.rb +131 -0
- data/app/admin/welcome.rb +64 -0
- data/app/assets/fonts/PT_Sans-Web-Bold.eot +0 -0
- data/app/assets/fonts/PT_Sans-Web-Bold.svg +6386 -0
- data/app/assets/fonts/PT_Sans-Web-Bold.ttf +0 -0
- data/app/assets/fonts/PT_Sans-Web-Bold.woff +0 -0
- data/app/assets/fonts/PT_Sans-Web-Regular.eot +0 -0
- data/app/assets/fonts/PT_Sans-Web-Regular.svg +5650 -0
- data/app/assets/fonts/PT_Sans-Web-Regular.ttf +0 -0
- data/app/assets/fonts/PT_Sans-Web-Regular.woff +0 -0
- data/app/assets/images/chosen-sprite.png +0 -0
- data/app/assets/javascripts/active_admin/chosen.js.erb.coffee +12 -0
- data/app/assets/javascripts/active_admin/qtip.js.coffee +22 -0
- data/app/assets/javascripts/active_admin/sortable_forms.js.coffee +14 -0
- data/app/assets/javascripts/active_admin.js.coffee +9 -0
- data/app/assets/javascripts/application.js +15 -0
- data/app/assets/javascripts/report_templates.js.coffee +10 -0
- data/app/assets/javascripts/terminals.js.coffee +12 -0
- data/app/assets/stylesheets/active_admin/PIE.css.scss +18 -0
- data/app/assets/stylesheets/active_admin/filter_numeric_range.css.scss +14 -0
- data/app/assets/stylesheets/active_admin/selectable_check_boxes.css.scss +12 -0
- data/app/assets/stylesheets/active_admin/sortable_forms.css.scss +11 -0
- data/app/assets/stylesheets/active_admin.css.scss +705 -0
- data/app/assets/stylesheets/fonts.css.scss +14 -0
- data/app/assets/stylesheets/provider_groups.css.scss +12 -0
- data/app/assets/stylesheets/provider_receipt_templates.css.scss +12 -0
- data/app/assets/stylesheets/terminals.css.scss +9 -0
- data/app/controllers/application_controller.rb +12 -0
- data/app/controllers/collections_controller.rb +10 -0
- data/app/controllers/payments_controller.rb +73 -0
- data/app/controllers/system_receipt_templates_controller.rb +10 -0
- data/app/controllers/terminal_builds_controller.rb +5 -0
- data/app/controllers/terminal_orders_controller.rb +25 -0
- data/app/controllers/terminal_pings_controller.rb +45 -0
- data/app/controllers/welcome_controller.rb +5 -0
- data/app/helpers/active_admin/report_templates_helper.rb +56 -0
- data/app/helpers/active_admin/views_helper.rb +20 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/mailers/.gitkeep +0 -0
- data/app/models/.gitkeep +0 -0
- data/app/models/ability.rb +30 -0
- data/app/models/agent.rb +24 -0
- data/app/models/collection.rb +65 -0
- data/app/models/commission.rb +77 -0
- data/app/models/commission_section.rb +75 -0
- data/app/models/gateway.rb +99 -0
- data/app/models/gateway_attachment.rb +9 -0
- data/app/models/gateway_setting.rb +7 -0
- data/app/models/gateway_switch.rb +7 -0
- data/app/models/limit.rb +77 -0
- data/app/models/limit_section.rb +58 -0
- data/app/models/payment.rb +322 -0
- data/app/models/provider.rb +59 -0
- data/app/models/provider_field.rb +7 -0
- data/app/models/provider_gateway.rb +47 -0
- data/app/models/provider_group.rb +45 -0
- data/app/models/provider_profile.rb +9 -0
- data/app/models/provider_rebate.rb +69 -0
- data/app/models/provider_receipt_template.rb +85 -0
- data/app/models/rebate.rb +84 -0
- data/app/models/report.rb +71 -0
- data/app/models/report_result.rb +11 -0
- data/app/models/report_template.rb +56 -0
- data/app/models/revision.rb +104 -0
- data/app/models/role.rb +48 -0
- data/app/models/system_receipt_template.rb +13 -0
- data/app/models/terminal.rb +126 -0
- data/app/models/terminal_build.rb +62 -0
- data/app/models/terminal_order.rb +42 -0
- data/app/models/terminal_ping.rb +120 -0
- data/app/models/terminal_profile.rb +51 -0
- data/app/models/terminal_profile_promotion.rb +18 -0
- data/app/models/terminal_profile_provider.rb +11 -0
- data/app/models/terminal_profile_provider_group.rb +19 -0
- data/app/models/user.rb +38 -0
- data/app/models/user_role.rb +45 -0
- data/app/reports/agents_report.rb +81 -0
- data/app/reports/collections_report.rb +151 -0
- data/app/reports/payments_report.rb +189 -0
- data/app/reports/terminals_report.rb +123 -0
- data/app/uploaders/file_uploader.rb +53 -0
- data/app/uploaders/icon_uploader.rb +15 -0
- data/app/uploaders/zip_uploader.rb +53 -0
- data/app/views/admin/gateways/providers.html.arb +10 -0
- data/app/views/admin/revisions/payments.html.arb +28 -0
- data/app/views/admin/terminal_profiles/_tree.html.haml +35 -0
- data/app/views/admin/terminal_profiles/sort.html.haml +21 -0
- data/app/views/admin/terminals/pings.html.arb +55 -0
- data/app/views/admin/terminals/upgrade_build.html.arb +30 -0
- data/app/views/layouts/application.html.erb +1 -0
- data/app/views/welcome/index.html.erb +25 -0
- data/app/workers/pay_worker.rb +11 -0
- data/app/workers/report_worker.rb +7 -0
- data/app/workers/revise_worker.rb +7 -0
- data/config/acquiring.yml +13 -0
- data/config/application.rb +75 -0
- data/config/boot.rb +6 -0
- data/config/database.yml +17 -0
- data/config/deploy/roundlake-passenger.rb +3 -0
- data/config/deploy/roundlake-trinidad.rb +3 -0
- data/config/deploy.rb +37 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +39 -0
- data/config/environments/production.rb +67 -0
- data/config/environments/test.rb +37 -0
- data/config/initializers/active_admin.rb +31 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/devise.rb +232 -0
- data/config/initializers/inflections.rb +15 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/money.rb +6 -0
- data/config/initializers/redis.rb +4 -0
- data/config/initializers/secret_token.rb +7 -0
- data/config/initializers/session_store.rb +8 -0
- data/config/initializers/setup_rack.rb +1 -0
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/active_admin.ru.yml +71 -0
- data/config/locales/activerecord.ru.yml +645 -0
- data/config/locales/devise.ru.yml +57 -0
- data/config/locales/ru.yml +33 -0
- data/config/locales/smartkiosk.gateways.ru.yml +241 -0
- data/config/locales/smartkiosk.hardware.ru.yml +38 -0
- data/config/locales/smartkiosk.reports.ru.yml +56 -0
- data/config/locales/smartkiosk.ru.yml +163 -0
- data/config/nginx.conf +9 -0
- data/config/redis.yml +9 -0
- data/config/routes.rb +48 -0
- data/config/schedule.rb +13 -0
- data/config/sidekiq.yml +5 -0
- data/config/trinidad.yml +6 -0
- data/config.ru +4 -0
- data/db/migrate/20120825083035_create_terminals.rb +47 -0
- data/db/migrate/20120825083305_create_payments.rb +51 -0
- data/db/migrate/20120827062618_devise_create_users.rb +50 -0
- data/db/migrate/20120827132621_create_admin_notes.rb +17 -0
- data/db/migrate/20120827132622_move_admin_notes_to_comments.rb +25 -0
- data/db/migrate/20120903193346_create_providers.rb +24 -0
- data/db/migrate/20120922075345_create_collections.rb +26 -0
- data/db/migrate/20120922080440_create_agents.rb +29 -0
- data/db/migrate/20120922081104_create_commissions.rb +10 -0
- data/db/migrate/20120927035841_create_gateways.rb +13 -0
- data/db/migrate/20120927040626_create_provider_gateways.rb +13 -0
- data/db/migrate/20120927091849_create_limits.rb +10 -0
- data/db/migrate/20120927164647_create_roles.rb +14 -0
- data/db/migrate/20121003131522_create_report_templates.rb +18 -0
- data/db/migrate/20121007135652_create_reports.rb +13 -0
- data/db/migrate/20121008073905_create_report_results.rb +10 -0
- data/db/migrate/20121017114538_create_gateway_settings.rb +12 -0
- data/db/migrate/20121017114556_create_gateway_attachments.rb +10 -0
- data/db/migrate/20121019132606_create_revisions.rb +19 -0
- data/db/migrate/20121023073501_create_gateway_switches.rb +10 -0
- data/db/migrate/20121112142743_create_terminal_orders.rb +13 -0
- data/db/migrate/20121118191553_create_versions.rb +19 -0
- data/db/migrate/20121125093414_create_system_receipt_templates.rb +9 -0
- data/db/migrate/20121127192257_create_terminal_builds.rb +10 -0
- data/db/migrate/20121212053441_create_rebates.rb +15 -0
- data/db/migrate/20121216143855_create_provider_receipt_templates.rb +9 -0
- data/db/migrate/20130101091100_create_terminal_profiles.rb +13 -0
- data/db/migrate/20130101091734_create_provider_rebates.rb +21 -0
- data/db/migrate/20130102164447_create_limit_sections.rb +14 -0
- data/db/migrate/20130102164503_create_commission_sections.rb +17 -0
- data/db/migrate/20130102171743_create_provider_profiles.rb +10 -0
- data/db/migrate/20130103152507_create_provider_fields.rb +17 -0
- data/db/migrate/20130103154526_create_provider_groups.rb +10 -0
- data/db/migrate/20130104063628_create_terminal_profile_providers.rb +11 -0
- data/db/migrate/20130104090957_create_terminal_profile_provider_groups.rb +11 -0
- data/db/migrate/20130108091644_create_terminal_profile_promotions.rb +10 -0
- data/db/schema.rb +489 -0
- data/db/seeds/receipt_templates/payment.txt +19 -0
- data/db/seeds/receipt_templates/system/balance.txt +13 -0
- data/db/seeds/receipt_templates/system/collection.txt +17 -0
- data/db/seeds/receipt_templates/system/touchtest.txt +15 -0
- data/db/seeds.rb +18 -0
- data/doc/README_FOR_APP +2 -0
- data/init.rb +1 -0
- data/lib/active_admin/cancan_integration.rb +81 -0
- data/lib/active_admin/form_builder_fix.rb +76 -0
- data/lib/active_admin/inputs/filter_date_range_input_fix.rb +24 -0
- data/lib/active_admin/inputs/filter_multiple_select_input.rb +18 -0
- data/lib/active_admin/inputs/filter_numeric_range_input.rb +31 -0
- data/lib/active_admin/resource_controller_fix.rb +23 -0
- data/lib/active_admin/views/pages/base_fix.rb +13 -0
- data/lib/assets/.gitkeep +0 -0
- data/lib/blueprints.rb +79 -0
- data/lib/date_expander.rb +38 -0
- data/lib/dav4rack/build_resource.rb +59 -0
- data/lib/formtastic/inputs/selectable_check_boxes.rb +39 -0
- data/lib/paper_trail/version_fix.rb +3 -0
- data/lib/report_builder.rb +88 -0
- data/lib/seeder.rb +103 -0
- data/lib/smartkiosk/server/version.rb +5 -0
- data/lib/smartkiosk/server.rb +35 -0
- data/lib/string_file.rb +12 -0
- data/lib/tasks/.gitkeep +0 -0
- data/lib/tasks/db.rake +27 -0
- data/lib/tasks/dump.rake +53 -0
- data/lib/tasks/matrioshka.rake +16 -0
- data/log/.gitkeep +0 -0
- data/log/gateways/.gitkeep +0 -0
- data/public/404.html +26 -0
- data/public/422.html +26 -0
- data/public/500.html +25 -0
- data/public/robots.txt +5 -0
- data/script/rails +6 -0
- data/smartkiosk-server.gemspec +23 -0
- data/spec/controllers/collections_controller_spec.rb +32 -0
- data/spec/controllers/payments_controller_spec.rb +123 -0
- data/spec/controllers/system_receipt_templates_controller_spec.rb +5 -0
- data/spec/controllers/terminal_builds_controller_spec.rb +5 -0
- data/spec/controllers/terminal_orders_controller_spec.rb +32 -0
- data/spec/controllers/terminal_pings_controller_spec.rb +31 -0
- data/spec/spec_helper.rb +66 -0
- data/vendor/assets/javascripts/.gitkeep +0 -0
- data/vendor/assets/javascripts/chosen.jquery.js +1026 -0
- data/vendor/assets/javascripts/datepicker-ru.jquery.js +21 -0
- data/vendor/assets/javascripts/nestedSortable.jquery.js +429 -0
- data/vendor/assets/javascripts/qtip.jquery.js +3403 -0
- data/vendor/assets/stylesheets/.gitkeep +0 -0
- data/vendor/assets/stylesheets/chosen.jquery.css +397 -0
- data/vendor/assets/stylesheets/modules/PIE.htc +96 -0
- data/vendor/assets/stylesheets/qtip.jquery.css.scss +604 -0
- data/vendor/plugins/.gitkeep +0 -0
- metadata +333 -0
@@ -0,0 +1,1026 @@
|
|
1
|
+
// Chosen, a Select Box Enhancer for jQuery and Protoype
|
2
|
+
// by Patrick Filler for Harvest, http://getharvest.com
|
3
|
+
//
|
4
|
+
// Version 0.9.8
|
5
|
+
// Full source at https://github.com/harvesthq/chosen
|
6
|
+
// Copyright (c) 2011 Harvest http://getharvest.com
|
7
|
+
|
8
|
+
// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
|
9
|
+
// This file is generated by `cake build`, do not edit it by hand.
|
10
|
+
(function() {
|
11
|
+
var SelectParser;
|
12
|
+
|
13
|
+
SelectParser = (function() {
|
14
|
+
|
15
|
+
function SelectParser() {
|
16
|
+
this.options_index = 0;
|
17
|
+
this.parsed = [];
|
18
|
+
}
|
19
|
+
|
20
|
+
SelectParser.prototype.add_node = function(child) {
|
21
|
+
if (child.nodeName.toUpperCase() === "OPTGROUP") {
|
22
|
+
return this.add_group(child);
|
23
|
+
} else {
|
24
|
+
return this.add_option(child);
|
25
|
+
}
|
26
|
+
};
|
27
|
+
|
28
|
+
SelectParser.prototype.add_group = function(group) {
|
29
|
+
var group_position, option, _i, _len, _ref, _results;
|
30
|
+
group_position = this.parsed.length;
|
31
|
+
this.parsed.push({
|
32
|
+
array_index: group_position,
|
33
|
+
group: true,
|
34
|
+
label: group.label,
|
35
|
+
children: 0,
|
36
|
+
disabled: group.disabled
|
37
|
+
});
|
38
|
+
_ref = group.childNodes;
|
39
|
+
_results = [];
|
40
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
41
|
+
option = _ref[_i];
|
42
|
+
_results.push(this.add_option(option, group_position, group.disabled));
|
43
|
+
}
|
44
|
+
return _results;
|
45
|
+
};
|
46
|
+
|
47
|
+
SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
|
48
|
+
if (option.nodeName.toUpperCase() === "OPTION") {
|
49
|
+
if (option.text !== "") {
|
50
|
+
if (group_position != null) this.parsed[group_position].children += 1;
|
51
|
+
this.parsed.push({
|
52
|
+
array_index: this.parsed.length,
|
53
|
+
options_index: this.options_index,
|
54
|
+
value: option.value,
|
55
|
+
text: option.text,
|
56
|
+
html: option.innerHTML,
|
57
|
+
selected: option.selected,
|
58
|
+
disabled: group_disabled === true ? group_disabled : option.disabled,
|
59
|
+
group_array_index: group_position,
|
60
|
+
classes: option.className,
|
61
|
+
style: option.style.cssText
|
62
|
+
});
|
63
|
+
} else {
|
64
|
+
this.parsed.push({
|
65
|
+
array_index: this.parsed.length,
|
66
|
+
options_index: this.options_index,
|
67
|
+
empty: true
|
68
|
+
});
|
69
|
+
}
|
70
|
+
return this.options_index += 1;
|
71
|
+
}
|
72
|
+
};
|
73
|
+
|
74
|
+
return SelectParser;
|
75
|
+
|
76
|
+
})();
|
77
|
+
|
78
|
+
SelectParser.select_to_array = function(select) {
|
79
|
+
var child, parser, _i, _len, _ref;
|
80
|
+
parser = new SelectParser();
|
81
|
+
_ref = select.childNodes;
|
82
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
83
|
+
child = _ref[_i];
|
84
|
+
parser.add_node(child);
|
85
|
+
}
|
86
|
+
return parser.parsed;
|
87
|
+
};
|
88
|
+
|
89
|
+
this.SelectParser = SelectParser;
|
90
|
+
|
91
|
+
}).call(this);
|
92
|
+
|
93
|
+
/*
|
94
|
+
Chosen source: generate output using 'cake build'
|
95
|
+
Copyright (c) 2011 by Harvest
|
96
|
+
*/
|
97
|
+
|
98
|
+
(function() {
|
99
|
+
var AbstractChosen, root;
|
100
|
+
|
101
|
+
root = this;
|
102
|
+
|
103
|
+
AbstractChosen = (function() {
|
104
|
+
|
105
|
+
function AbstractChosen(form_field, options) {
|
106
|
+
this.form_field = form_field;
|
107
|
+
this.options = options != null ? options : {};
|
108
|
+
this.set_default_values();
|
109
|
+
this.is_multiple = this.form_field.multiple;
|
110
|
+
this.set_default_text();
|
111
|
+
this.setup();
|
112
|
+
this.set_up_html();
|
113
|
+
this.register_observers();
|
114
|
+
this.finish_setup();
|
115
|
+
}
|
116
|
+
|
117
|
+
AbstractChosen.prototype.set_default_values = function() {
|
118
|
+
var _this = this;
|
119
|
+
this.click_test_action = function(evt) {
|
120
|
+
return _this.test_active_click(evt);
|
121
|
+
};
|
122
|
+
this.activate_action = function(evt) {
|
123
|
+
return _this.activate_field(evt);
|
124
|
+
};
|
125
|
+
this.active_field = false;
|
126
|
+
this.mouse_on_container = false;
|
127
|
+
this.results_showing = false;
|
128
|
+
this.result_highlighted = null;
|
129
|
+
this.result_single_selected = null;
|
130
|
+
this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
|
131
|
+
this.disable_search_threshold = this.options.disable_search_threshold || 0;
|
132
|
+
this.disable_search = this.options.disable_search || false;
|
133
|
+
this.search_contains = this.options.search_contains || false;
|
134
|
+
this.choices = 0;
|
135
|
+
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
|
136
|
+
return this.max_selected_options = this.options.max_selected_options || Infinity;
|
137
|
+
};
|
138
|
+
|
139
|
+
AbstractChosen.prototype.set_default_text = function() {
|
140
|
+
if (this.form_field.getAttribute("data-placeholder")) {
|
141
|
+
this.default_text = this.form_field.getAttribute("data-placeholder");
|
142
|
+
} else if (this.is_multiple) {
|
143
|
+
this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || "Select Some Options";
|
144
|
+
} else {
|
145
|
+
this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || "Выберите";
|
146
|
+
}
|
147
|
+
return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || "No results match";
|
148
|
+
};
|
149
|
+
|
150
|
+
AbstractChosen.prototype.mouse_enter = function() {
|
151
|
+
return this.mouse_on_container = true;
|
152
|
+
};
|
153
|
+
|
154
|
+
AbstractChosen.prototype.mouse_leave = function() {
|
155
|
+
return this.mouse_on_container = false;
|
156
|
+
};
|
157
|
+
|
158
|
+
AbstractChosen.prototype.input_focus = function(evt) {
|
159
|
+
var _this = this;
|
160
|
+
if (!this.active_field) {
|
161
|
+
return setTimeout((function() {
|
162
|
+
return _this.container_mousedown();
|
163
|
+
}), 50);
|
164
|
+
}
|
165
|
+
};
|
166
|
+
|
167
|
+
AbstractChosen.prototype.input_blur = function(evt) {
|
168
|
+
var _this = this;
|
169
|
+
if (!this.mouse_on_container) {
|
170
|
+
this.active_field = false;
|
171
|
+
return setTimeout((function() {
|
172
|
+
return _this.blur_test();
|
173
|
+
}), 100);
|
174
|
+
}
|
175
|
+
};
|
176
|
+
|
177
|
+
AbstractChosen.prototype.result_add_option = function(option) {
|
178
|
+
var classes, style;
|
179
|
+
if (!option.disabled) {
|
180
|
+
option.dom_id = this.container_id + "_o_" + option.array_index;
|
181
|
+
classes = option.selected && this.is_multiple ? [] : ["active-result"];
|
182
|
+
if (option.selected) classes.push("result-selected");
|
183
|
+
if (option.group_array_index != null) classes.push("group-option");
|
184
|
+
if (option.classes !== "") classes.push(option.classes);
|
185
|
+
style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
|
186
|
+
return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
|
187
|
+
} else {
|
188
|
+
return "";
|
189
|
+
}
|
190
|
+
};
|
191
|
+
|
192
|
+
AbstractChosen.prototype.results_update_field = function() {
|
193
|
+
if (!this.is_multiple) this.results_reset_cleanup();
|
194
|
+
this.result_clear_highlight();
|
195
|
+
this.result_single_selected = null;
|
196
|
+
return this.results_build();
|
197
|
+
};
|
198
|
+
|
199
|
+
AbstractChosen.prototype.results_toggle = function() {
|
200
|
+
if (this.results_showing) {
|
201
|
+
return this.results_hide();
|
202
|
+
} else {
|
203
|
+
return this.results_show();
|
204
|
+
}
|
205
|
+
};
|
206
|
+
|
207
|
+
AbstractChosen.prototype.results_search = function(evt) {
|
208
|
+
if (this.results_showing) {
|
209
|
+
return this.winnow_results();
|
210
|
+
} else {
|
211
|
+
return this.results_show();
|
212
|
+
}
|
213
|
+
};
|
214
|
+
|
215
|
+
AbstractChosen.prototype.keyup_checker = function(evt) {
|
216
|
+
var stroke, _ref;
|
217
|
+
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
218
|
+
this.search_field_scale();
|
219
|
+
switch (stroke) {
|
220
|
+
case 8:
|
221
|
+
if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
|
222
|
+
return this.keydown_backstroke();
|
223
|
+
} else if (!this.pending_backstroke) {
|
224
|
+
this.result_clear_highlight();
|
225
|
+
return this.results_search();
|
226
|
+
}
|
227
|
+
break;
|
228
|
+
case 13:
|
229
|
+
evt.preventDefault();
|
230
|
+
if (this.results_showing) return this.result_select(evt);
|
231
|
+
break;
|
232
|
+
case 27:
|
233
|
+
if (this.results_showing) this.results_hide();
|
234
|
+
return true;
|
235
|
+
case 9:
|
236
|
+
case 38:
|
237
|
+
case 40:
|
238
|
+
case 16:
|
239
|
+
case 91:
|
240
|
+
case 17:
|
241
|
+
break;
|
242
|
+
default:
|
243
|
+
return this.results_search();
|
244
|
+
}
|
245
|
+
};
|
246
|
+
|
247
|
+
AbstractChosen.prototype.generate_field_id = function() {
|
248
|
+
var new_id;
|
249
|
+
new_id = this.generate_random_id();
|
250
|
+
this.form_field.id = new_id;
|
251
|
+
return new_id;
|
252
|
+
};
|
253
|
+
|
254
|
+
AbstractChosen.prototype.generate_random_char = function() {
|
255
|
+
var chars, newchar, rand;
|
256
|
+
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
257
|
+
rand = Math.floor(Math.random() * chars.length);
|
258
|
+
return newchar = chars.substring(rand, rand + 1);
|
259
|
+
};
|
260
|
+
|
261
|
+
return AbstractChosen;
|
262
|
+
|
263
|
+
})();
|
264
|
+
|
265
|
+
root.AbstractChosen = AbstractChosen;
|
266
|
+
|
267
|
+
}).call(this);
|
268
|
+
|
269
|
+
/*
|
270
|
+
Chosen source: generate output using 'cake build'
|
271
|
+
Copyright (c) 2011 by Harvest
|
272
|
+
*/
|
273
|
+
|
274
|
+
(function() {
|
275
|
+
var $, Chosen, get_side_border_padding, root,
|
276
|
+
__hasProp = Object.prototype.hasOwnProperty,
|
277
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
278
|
+
|
279
|
+
root = this;
|
280
|
+
|
281
|
+
$ = jQuery;
|
282
|
+
|
283
|
+
$.fn.extend({
|
284
|
+
chosen: function(options) {
|
285
|
+
if ($.browser.msie && ($.browser.version === "6.0" || ($.browser.version === "7.0" && document.documentMode === 7))) {
|
286
|
+
return this;
|
287
|
+
}
|
288
|
+
return this.each(function(input_field) {
|
289
|
+
var $this;
|
290
|
+
$this = $(this);
|
291
|
+
if (!$this.hasClass("chzn-done")) {
|
292
|
+
return $this.data('chosen', new Chosen(this, options));
|
293
|
+
}
|
294
|
+
});
|
295
|
+
}
|
296
|
+
});
|
297
|
+
|
298
|
+
Chosen = (function(_super) {
|
299
|
+
|
300
|
+
__extends(Chosen, _super);
|
301
|
+
|
302
|
+
function Chosen() {
|
303
|
+
Chosen.__super__.constructor.apply(this, arguments);
|
304
|
+
}
|
305
|
+
|
306
|
+
Chosen.prototype.setup = function() {
|
307
|
+
this.form_field_jq = $(this.form_field);
|
308
|
+
this.current_value = this.form_field_jq.val();
|
309
|
+
return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
|
310
|
+
};
|
311
|
+
|
312
|
+
Chosen.prototype.finish_setup = function() {
|
313
|
+
return this.form_field_jq.addClass("chzn-done");
|
314
|
+
};
|
315
|
+
|
316
|
+
Chosen.prototype.set_up_html = function() {
|
317
|
+
var container_div, dd_top, dd_width, sf_width;
|
318
|
+
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
|
319
|
+
this.container_id += "_chzn";
|
320
|
+
this.f_width = this.form_field_jq.outerWidth();
|
321
|
+
container_div = $("<div />", {
|
322
|
+
id: this.container_id,
|
323
|
+
"class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
|
324
|
+
style: 'width: ' + this.f_width + 'px;'
|
325
|
+
});
|
326
|
+
if (this.is_multiple) {
|
327
|
+
container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
|
328
|
+
} else {
|
329
|
+
container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
|
330
|
+
}
|
331
|
+
this.form_field_jq.hide().after(container_div);
|
332
|
+
this.container = $('#' + this.container_id);
|
333
|
+
this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
|
334
|
+
this.dropdown = this.container.find('div.chzn-drop').first();
|
335
|
+
dd_top = this.container.height();
|
336
|
+
dd_width = this.f_width - get_side_border_padding(this.dropdown);
|
337
|
+
this.dropdown.css({
|
338
|
+
"width": dd_width + "px",
|
339
|
+
"top": dd_top + "px"
|
340
|
+
});
|
341
|
+
this.search_field = this.container.find('input').first();
|
342
|
+
this.search_results = this.container.find('ul.chzn-results').first();
|
343
|
+
this.search_field_scale();
|
344
|
+
this.search_no_results = this.container.find('li.no-results').first();
|
345
|
+
if (this.is_multiple) {
|
346
|
+
this.search_choices = this.container.find('ul.chzn-choices').first();
|
347
|
+
this.search_container = this.container.find('li.search-field').first();
|
348
|
+
} else {
|
349
|
+
this.search_container = this.container.find('div.chzn-search').first();
|
350
|
+
this.selected_item = this.container.find('.chzn-single').first();
|
351
|
+
sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
|
352
|
+
this.search_field.css({
|
353
|
+
"width": sf_width + "px"
|
354
|
+
});
|
355
|
+
}
|
356
|
+
this.results_build();
|
357
|
+
this.set_tab_index();
|
358
|
+
return this.form_field_jq.trigger("liszt:ready", {
|
359
|
+
chosen: this
|
360
|
+
});
|
361
|
+
};
|
362
|
+
|
363
|
+
Chosen.prototype.register_observers = function() {
|
364
|
+
var _this = this;
|
365
|
+
this.container.mousedown(function(evt) {
|
366
|
+
return _this.container_mousedown(evt);
|
367
|
+
});
|
368
|
+
this.container.mouseup(function(evt) {
|
369
|
+
return _this.container_mouseup(evt);
|
370
|
+
});
|
371
|
+
this.container.mouseenter(function(evt) {
|
372
|
+
return _this.mouse_enter(evt);
|
373
|
+
});
|
374
|
+
this.container.mouseleave(function(evt) {
|
375
|
+
return _this.mouse_leave(evt);
|
376
|
+
});
|
377
|
+
this.search_results.mouseup(function(evt) {
|
378
|
+
return _this.search_results_mouseup(evt);
|
379
|
+
});
|
380
|
+
this.search_results.mouseover(function(evt) {
|
381
|
+
return _this.search_results_mouseover(evt);
|
382
|
+
});
|
383
|
+
this.search_results.mouseout(function(evt) {
|
384
|
+
return _this.search_results_mouseout(evt);
|
385
|
+
});
|
386
|
+
this.form_field_jq.bind("liszt:updated", function(evt) {
|
387
|
+
return _this.results_update_field(evt);
|
388
|
+
});
|
389
|
+
this.form_field_jq.bind("liszt:activate", function(evt) {
|
390
|
+
return _this.activate_field(evt);
|
391
|
+
});
|
392
|
+
this.form_field_jq.bind("liszt:open", function(evt) {
|
393
|
+
return _this.container_mousedown(evt);
|
394
|
+
});
|
395
|
+
this.search_field.blur(function(evt) {
|
396
|
+
return _this.input_blur(evt);
|
397
|
+
});
|
398
|
+
this.search_field.keyup(function(evt) {
|
399
|
+
return _this.keyup_checker(evt);
|
400
|
+
});
|
401
|
+
this.search_field.keydown(function(evt) {
|
402
|
+
return _this.keydown_checker(evt);
|
403
|
+
});
|
404
|
+
if (this.is_multiple) {
|
405
|
+
this.search_choices.click(function(evt) {
|
406
|
+
return _this.choices_click(evt);
|
407
|
+
});
|
408
|
+
return this.search_field.focus(function(evt) {
|
409
|
+
return _this.input_focus(evt);
|
410
|
+
});
|
411
|
+
} else {
|
412
|
+
return this.container.click(function(evt) {
|
413
|
+
return evt.preventDefault();
|
414
|
+
});
|
415
|
+
}
|
416
|
+
};
|
417
|
+
|
418
|
+
Chosen.prototype.search_field_disabled = function() {
|
419
|
+
this.is_disabled = this.form_field_jq[0].disabled;
|
420
|
+
if (this.is_disabled) {
|
421
|
+
this.container.addClass('chzn-disabled');
|
422
|
+
this.search_field[0].disabled = true;
|
423
|
+
if (!this.is_multiple) {
|
424
|
+
this.selected_item.unbind("focus", this.activate_action);
|
425
|
+
}
|
426
|
+
return this.close_field();
|
427
|
+
} else {
|
428
|
+
this.container.removeClass('chzn-disabled');
|
429
|
+
this.search_field[0].disabled = false;
|
430
|
+
if (!this.is_multiple) {
|
431
|
+
return this.selected_item.bind("focus", this.activate_action);
|
432
|
+
}
|
433
|
+
}
|
434
|
+
};
|
435
|
+
|
436
|
+
Chosen.prototype.container_mousedown = function(evt) {
|
437
|
+
var target_closelink;
|
438
|
+
if (!this.is_disabled) {
|
439
|
+
target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
|
440
|
+
if (evt && evt.type === "mousedown" && !this.results_showing) {
|
441
|
+
evt.stopPropagation();
|
442
|
+
}
|
443
|
+
if (!this.pending_destroy_click && !target_closelink) {
|
444
|
+
if (!this.active_field) {
|
445
|
+
if (this.is_multiple) this.search_field.val("");
|
446
|
+
$(document).click(this.click_test_action);
|
447
|
+
this.results_show();
|
448
|
+
} else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
|
449
|
+
evt.preventDefault();
|
450
|
+
this.results_toggle();
|
451
|
+
}
|
452
|
+
return this.activate_field();
|
453
|
+
} else {
|
454
|
+
return this.pending_destroy_click = false;
|
455
|
+
}
|
456
|
+
}
|
457
|
+
};
|
458
|
+
|
459
|
+
Chosen.prototype.container_mouseup = function(evt) {
|
460
|
+
if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
|
461
|
+
return this.results_reset(evt);
|
462
|
+
}
|
463
|
+
};
|
464
|
+
|
465
|
+
Chosen.prototype.blur_test = function(evt) {
|
466
|
+
if (!this.active_field && this.container.hasClass("chzn-container-active")) {
|
467
|
+
return this.close_field();
|
468
|
+
}
|
469
|
+
};
|
470
|
+
|
471
|
+
Chosen.prototype.close_field = function() {
|
472
|
+
$(document).unbind("click", this.click_test_action);
|
473
|
+
if (!this.is_multiple) {
|
474
|
+
this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
|
475
|
+
this.search_field.attr("tabindex", -1);
|
476
|
+
}
|
477
|
+
this.active_field = false;
|
478
|
+
this.results_hide();
|
479
|
+
this.container.removeClass("chzn-container-active");
|
480
|
+
this.winnow_results_clear();
|
481
|
+
this.clear_backstroke();
|
482
|
+
this.show_search_field_default();
|
483
|
+
return this.search_field_scale();
|
484
|
+
};
|
485
|
+
|
486
|
+
Chosen.prototype.activate_field = function() {
|
487
|
+
if (!this.is_multiple && !this.active_field) {
|
488
|
+
this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
|
489
|
+
this.selected_item.attr("tabindex", -1);
|
490
|
+
}
|
491
|
+
this.container.addClass("chzn-container-active");
|
492
|
+
this.active_field = true;
|
493
|
+
this.search_field.val(this.search_field.val());
|
494
|
+
return this.search_field.focus();
|
495
|
+
};
|
496
|
+
|
497
|
+
Chosen.prototype.test_active_click = function(evt) {
|
498
|
+
if ($(evt.target).parents('#' + this.container_id).length) {
|
499
|
+
return this.active_field = true;
|
500
|
+
} else {
|
501
|
+
return this.close_field();
|
502
|
+
}
|
503
|
+
};
|
504
|
+
|
505
|
+
Chosen.prototype.results_build = function() {
|
506
|
+
var content, data, _i, _len, _ref;
|
507
|
+
this.parsing = true;
|
508
|
+
this.results_data = root.SelectParser.select_to_array(this.form_field);
|
509
|
+
if (this.is_multiple && this.choices > 0) {
|
510
|
+
this.search_choices.find("li.search-choice").remove();
|
511
|
+
this.choices = 0;
|
512
|
+
} else if (!this.is_multiple) {
|
513
|
+
this.selected_item.addClass("chzn-default").find("span").text(this.default_text);
|
514
|
+
if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
|
515
|
+
this.container.addClass("chzn-container-single-nosearch");
|
516
|
+
} else {
|
517
|
+
this.container.removeClass("chzn-container-single-nosearch");
|
518
|
+
}
|
519
|
+
}
|
520
|
+
content = '';
|
521
|
+
_ref = this.results_data;
|
522
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
523
|
+
data = _ref[_i];
|
524
|
+
if (data.group) {
|
525
|
+
content += this.result_add_group(data);
|
526
|
+
} else if (!data.empty) {
|
527
|
+
content += this.result_add_option(data);
|
528
|
+
if (data.selected && this.is_multiple) {
|
529
|
+
this.choice_build(data);
|
530
|
+
} else if (data.selected && !this.is_multiple) {
|
531
|
+
this.selected_item.removeClass("chzn-default").find("span").text(data.text);
|
532
|
+
if (this.allow_single_deselect) this.single_deselect_control_build();
|
533
|
+
}
|
534
|
+
}
|
535
|
+
}
|
536
|
+
this.search_field_disabled();
|
537
|
+
this.show_search_field_default();
|
538
|
+
this.search_field_scale();
|
539
|
+
this.search_results.html(content);
|
540
|
+
return this.parsing = false;
|
541
|
+
};
|
542
|
+
|
543
|
+
Chosen.prototype.result_add_group = function(group) {
|
544
|
+
if (!group.disabled) {
|
545
|
+
group.dom_id = this.container_id + "_g_" + group.array_index;
|
546
|
+
return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
|
547
|
+
} else {
|
548
|
+
return "";
|
549
|
+
}
|
550
|
+
};
|
551
|
+
|
552
|
+
Chosen.prototype.result_do_highlight = function(el) {
|
553
|
+
var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
|
554
|
+
if (el.length) {
|
555
|
+
this.result_clear_highlight();
|
556
|
+
this.result_highlight = el;
|
557
|
+
this.result_highlight.addClass("highlighted");
|
558
|
+
maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
|
559
|
+
visible_top = this.search_results.scrollTop();
|
560
|
+
visible_bottom = maxHeight + visible_top;
|
561
|
+
high_top = this.result_highlight.position().top + this.search_results.scrollTop();
|
562
|
+
high_bottom = high_top + this.result_highlight.outerHeight();
|
563
|
+
if (high_bottom >= visible_bottom) {
|
564
|
+
return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
|
565
|
+
} else if (high_top < visible_top) {
|
566
|
+
return this.search_results.scrollTop(high_top);
|
567
|
+
}
|
568
|
+
}
|
569
|
+
};
|
570
|
+
|
571
|
+
Chosen.prototype.result_clear_highlight = function() {
|
572
|
+
if (this.result_highlight) this.result_highlight.removeClass("highlighted");
|
573
|
+
return this.result_highlight = null;
|
574
|
+
};
|
575
|
+
|
576
|
+
Chosen.prototype.results_show = function() {
|
577
|
+
var dd_top;
|
578
|
+
if (!this.is_multiple) {
|
579
|
+
this.selected_item.addClass("chzn-single-with-drop");
|
580
|
+
if (this.result_single_selected) {
|
581
|
+
this.result_do_highlight(this.result_single_selected);
|
582
|
+
}
|
583
|
+
} else if (this.max_selected_options <= this.choices) {
|
584
|
+
this.form_field_jq.trigger("liszt:maxselected", {
|
585
|
+
chosen: this
|
586
|
+
});
|
587
|
+
return false;
|
588
|
+
}
|
589
|
+
dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
|
590
|
+
this.form_field_jq.trigger("liszt:showing_dropdown", {
|
591
|
+
chosen: this
|
592
|
+
});
|
593
|
+
this.dropdown.css({
|
594
|
+
"top": dd_top + "px",
|
595
|
+
"left": 0
|
596
|
+
});
|
597
|
+
this.results_showing = true;
|
598
|
+
this.search_field.focus();
|
599
|
+
this.search_field.val(this.search_field.val());
|
600
|
+
return this.winnow_results();
|
601
|
+
};
|
602
|
+
|
603
|
+
Chosen.prototype.results_hide = function() {
|
604
|
+
if (!this.is_multiple) {
|
605
|
+
this.selected_item.removeClass("chzn-single-with-drop");
|
606
|
+
}
|
607
|
+
this.result_clear_highlight();
|
608
|
+
this.form_field_jq.trigger("liszt:hiding_dropdown", {
|
609
|
+
chosen: this
|
610
|
+
});
|
611
|
+
this.dropdown.css({
|
612
|
+
"left": "-9000px"
|
613
|
+
});
|
614
|
+
return this.results_showing = false;
|
615
|
+
};
|
616
|
+
|
617
|
+
Chosen.prototype.set_tab_index = function(el) {
|
618
|
+
var ti;
|
619
|
+
if (this.form_field_jq.attr("tabindex")) {
|
620
|
+
ti = this.form_field_jq.attr("tabindex");
|
621
|
+
this.form_field_jq.attr("tabindex", -1);
|
622
|
+
if (this.is_multiple) {
|
623
|
+
return this.search_field.attr("tabindex", ti);
|
624
|
+
} else {
|
625
|
+
this.selected_item.attr("tabindex", ti);
|
626
|
+
return this.search_field.attr("tabindex", -1);
|
627
|
+
}
|
628
|
+
}
|
629
|
+
};
|
630
|
+
|
631
|
+
Chosen.prototype.show_search_field_default = function() {
|
632
|
+
if (this.is_multiple && this.choices < 1 && !this.active_field) {
|
633
|
+
this.search_field.val(this.default_text);
|
634
|
+
return this.search_field.addClass("default");
|
635
|
+
} else {
|
636
|
+
this.search_field.val("");
|
637
|
+
return this.search_field.removeClass("default");
|
638
|
+
}
|
639
|
+
};
|
640
|
+
|
641
|
+
Chosen.prototype.search_results_mouseup = function(evt) {
|
642
|
+
var target;
|
643
|
+
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
644
|
+
if (target.length) {
|
645
|
+
this.result_highlight = target;
|
646
|
+
return this.result_select(evt);
|
647
|
+
}
|
648
|
+
};
|
649
|
+
|
650
|
+
Chosen.prototype.search_results_mouseover = function(evt) {
|
651
|
+
var target;
|
652
|
+
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
653
|
+
if (target) return this.result_do_highlight(target);
|
654
|
+
};
|
655
|
+
|
656
|
+
Chosen.prototype.search_results_mouseout = function(evt) {
|
657
|
+
if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
|
658
|
+
return this.result_clear_highlight();
|
659
|
+
}
|
660
|
+
};
|
661
|
+
|
662
|
+
Chosen.prototype.choices_click = function(evt) {
|
663
|
+
evt.preventDefault();
|
664
|
+
if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
|
665
|
+
return this.results_show();
|
666
|
+
}
|
667
|
+
};
|
668
|
+
|
669
|
+
Chosen.prototype.choice_build = function(item) {
|
670
|
+
var choice_id, html, link,
|
671
|
+
_this = this;
|
672
|
+
if (this.is_multiple && this.max_selected_options <= this.choices) {
|
673
|
+
this.form_field_jq.trigger("liszt:maxselected", {
|
674
|
+
chosen: this
|
675
|
+
});
|
676
|
+
return false;
|
677
|
+
}
|
678
|
+
choice_id = this.container_id + "_c_" + item.array_index;
|
679
|
+
this.choices += 1;
|
680
|
+
if (item.disabled) {
|
681
|
+
html = '<li class="search-choice search-choice-disabled" id="' + choice_id + '"><span>' + item.html + '</span></li>';
|
682
|
+
} else {
|
683
|
+
html = '<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>';
|
684
|
+
}
|
685
|
+
this.search_container.before(html);
|
686
|
+
link = $('#' + choice_id).find("a").first();
|
687
|
+
return link.click(function(evt) {
|
688
|
+
return _this.choice_destroy_link_click(evt);
|
689
|
+
});
|
690
|
+
};
|
691
|
+
|
692
|
+
Chosen.prototype.choice_destroy_link_click = function(evt) {
|
693
|
+
evt.preventDefault();
|
694
|
+
if (!this.is_disabled) {
|
695
|
+
this.pending_destroy_click = true;
|
696
|
+
return this.choice_destroy($(evt.target));
|
697
|
+
} else {
|
698
|
+
return evt.stopPropagation;
|
699
|
+
}
|
700
|
+
};
|
701
|
+
|
702
|
+
Chosen.prototype.choice_destroy = function(link) {
|
703
|
+
if (this.result_deselect(link.attr("rel"))) {
|
704
|
+
this.choices -= 1;
|
705
|
+
this.show_search_field_default();
|
706
|
+
if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
|
707
|
+
this.results_hide();
|
708
|
+
}
|
709
|
+
return link.parents('li').first().remove();
|
710
|
+
}
|
711
|
+
};
|
712
|
+
|
713
|
+
Chosen.prototype.results_reset = function() {
|
714
|
+
this.form_field.options[0].selected = true;
|
715
|
+
this.selected_item.find("span").text(this.default_text);
|
716
|
+
if (!this.is_multiple) this.selected_item.addClass("chzn-default");
|
717
|
+
this.show_search_field_default();
|
718
|
+
this.results_reset_cleanup();
|
719
|
+
this.form_field_jq.trigger("change");
|
720
|
+
if (this.active_field) return this.results_hide();
|
721
|
+
};
|
722
|
+
|
723
|
+
Chosen.prototype.results_reset_cleanup = function() {
|
724
|
+
this.current_value = this.form_field_jq.val();
|
725
|
+
return this.selected_item.find("abbr").remove();
|
726
|
+
};
|
727
|
+
|
728
|
+
Chosen.prototype.result_select = function(evt) {
|
729
|
+
var high, high_id, item, position;
|
730
|
+
if (this.result_highlight) {
|
731
|
+
high = this.result_highlight;
|
732
|
+
high_id = high.attr("id");
|
733
|
+
this.result_clear_highlight();
|
734
|
+
if (this.is_multiple) {
|
735
|
+
this.result_deactivate(high);
|
736
|
+
} else {
|
737
|
+
this.search_results.find(".result-selected").removeClass("result-selected");
|
738
|
+
this.result_single_selected = high;
|
739
|
+
this.selected_item.removeClass("chzn-default");
|
740
|
+
}
|
741
|
+
high.addClass("result-selected");
|
742
|
+
position = high_id.substr(high_id.lastIndexOf("_") + 1);
|
743
|
+
item = this.results_data[position];
|
744
|
+
item.selected = true;
|
745
|
+
this.form_field.options[item.options_index].selected = true;
|
746
|
+
if (this.is_multiple) {
|
747
|
+
this.choice_build(item);
|
748
|
+
} else {
|
749
|
+
this.selected_item.find("span").first().text(item.text);
|
750
|
+
if (this.allow_single_deselect) this.single_deselect_control_build();
|
751
|
+
}
|
752
|
+
if (!(evt.metaKey && this.is_multiple)) this.results_hide();
|
753
|
+
this.search_field.val("");
|
754
|
+
if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
|
755
|
+
this.form_field_jq.trigger("change", {
|
756
|
+
'selected': this.form_field.options[item.options_index].value
|
757
|
+
});
|
758
|
+
}
|
759
|
+
this.current_value = this.form_field_jq.val();
|
760
|
+
return this.search_field_scale();
|
761
|
+
}
|
762
|
+
};
|
763
|
+
|
764
|
+
Chosen.prototype.result_activate = function(el) {
|
765
|
+
return el.addClass("active-result");
|
766
|
+
};
|
767
|
+
|
768
|
+
Chosen.prototype.result_deactivate = function(el) {
|
769
|
+
return el.removeClass("active-result");
|
770
|
+
};
|
771
|
+
|
772
|
+
Chosen.prototype.result_deselect = function(pos) {
|
773
|
+
var result, result_data;
|
774
|
+
result_data = this.results_data[pos];
|
775
|
+
if (!this.form_field.options[result_data.options_index].disabled) {
|
776
|
+
result_data.selected = false;
|
777
|
+
this.form_field.options[result_data.options_index].selected = false;
|
778
|
+
result = $("#" + this.container_id + "_o_" + pos);
|
779
|
+
result.removeClass("result-selected").addClass("active-result").show();
|
780
|
+
this.result_clear_highlight();
|
781
|
+
this.winnow_results();
|
782
|
+
this.form_field_jq.trigger("change", {
|
783
|
+
deselected: this.form_field.options[result_data.options_index].value
|
784
|
+
});
|
785
|
+
this.search_field_scale();
|
786
|
+
return true;
|
787
|
+
} else {
|
788
|
+
return false;
|
789
|
+
}
|
790
|
+
};
|
791
|
+
|
792
|
+
Chosen.prototype.single_deselect_control_build = function() {
|
793
|
+
if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
|
794
|
+
return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
|
795
|
+
}
|
796
|
+
};
|
797
|
+
|
798
|
+
Chosen.prototype.winnow_results = function() {
|
799
|
+
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
|
800
|
+
this.no_results_clear();
|
801
|
+
results = 0;
|
802
|
+
searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
|
803
|
+
regexAnchor = this.search_contains ? "" : "^";
|
804
|
+
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
805
|
+
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
806
|
+
_ref = this.results_data;
|
807
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
808
|
+
option = _ref[_i];
|
809
|
+
if (!option.disabled && !option.empty) {
|
810
|
+
if (option.group) {
|
811
|
+
$('#' + option.dom_id).css('display', 'none');
|
812
|
+
} else if (!(this.is_multiple && option.selected)) {
|
813
|
+
found = false;
|
814
|
+
result_id = option.dom_id;
|
815
|
+
result = $("#" + result_id);
|
816
|
+
if (regex.test(option.html)) {
|
817
|
+
found = true;
|
818
|
+
results += 1;
|
819
|
+
} else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
|
820
|
+
parts = option.html.replace(/\[|\]/g, "").split(" ");
|
821
|
+
if (parts.length) {
|
822
|
+
for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
|
823
|
+
part = parts[_j];
|
824
|
+
if (regex.test(part)) {
|
825
|
+
found = true;
|
826
|
+
results += 1;
|
827
|
+
}
|
828
|
+
}
|
829
|
+
}
|
830
|
+
}
|
831
|
+
if (found) {
|
832
|
+
if (searchText.length) {
|
833
|
+
startpos = option.html.search(zregex);
|
834
|
+
text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
|
835
|
+
text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
|
836
|
+
} else {
|
837
|
+
text = option.html;
|
838
|
+
}
|
839
|
+
result.html(text);
|
840
|
+
this.result_activate(result);
|
841
|
+
if (option.group_array_index != null) {
|
842
|
+
$("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
|
843
|
+
}
|
844
|
+
} else {
|
845
|
+
if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
|
846
|
+
this.result_clear_highlight();
|
847
|
+
}
|
848
|
+
this.result_deactivate(result);
|
849
|
+
}
|
850
|
+
}
|
851
|
+
}
|
852
|
+
}
|
853
|
+
if (results < 1 && searchText.length) {
|
854
|
+
return this.no_results(searchText);
|
855
|
+
} else {
|
856
|
+
return this.winnow_results_set_highlight();
|
857
|
+
}
|
858
|
+
};
|
859
|
+
|
860
|
+
Chosen.prototype.winnow_results_clear = function() {
|
861
|
+
var li, lis, _i, _len, _results;
|
862
|
+
this.search_field.val("");
|
863
|
+
lis = this.search_results.find("li");
|
864
|
+
_results = [];
|
865
|
+
for (_i = 0, _len = lis.length; _i < _len; _i++) {
|
866
|
+
li = lis[_i];
|
867
|
+
li = $(li);
|
868
|
+
if (li.hasClass("group-result")) {
|
869
|
+
_results.push(li.css('display', 'auto'));
|
870
|
+
} else if (!this.is_multiple || !li.hasClass("result-selected")) {
|
871
|
+
_results.push(this.result_activate(li));
|
872
|
+
} else {
|
873
|
+
_results.push(void 0);
|
874
|
+
}
|
875
|
+
}
|
876
|
+
return _results;
|
877
|
+
};
|
878
|
+
|
879
|
+
Chosen.prototype.winnow_results_set_highlight = function() {
|
880
|
+
var do_high, selected_results;
|
881
|
+
if (!this.result_highlight) {
|
882
|
+
selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
|
883
|
+
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
|
884
|
+
if (do_high != null) return this.result_do_highlight(do_high);
|
885
|
+
}
|
886
|
+
};
|
887
|
+
|
888
|
+
Chosen.prototype.no_results = function(terms) {
|
889
|
+
var no_results_html;
|
890
|
+
no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
|
891
|
+
no_results_html.find("span").first().html(terms);
|
892
|
+
return this.search_results.append(no_results_html);
|
893
|
+
};
|
894
|
+
|
895
|
+
Chosen.prototype.no_results_clear = function() {
|
896
|
+
return this.search_results.find(".no-results").remove();
|
897
|
+
};
|
898
|
+
|
899
|
+
Chosen.prototype.keydown_arrow = function() {
|
900
|
+
var first_active, next_sib;
|
901
|
+
if (!this.result_highlight) {
|
902
|
+
first_active = this.search_results.find("li.active-result").first();
|
903
|
+
if (first_active) this.result_do_highlight($(first_active));
|
904
|
+
} else if (this.results_showing) {
|
905
|
+
next_sib = this.result_highlight.nextAll("li.active-result").first();
|
906
|
+
if (next_sib) this.result_do_highlight(next_sib);
|
907
|
+
}
|
908
|
+
if (!this.results_showing) return this.results_show();
|
909
|
+
};
|
910
|
+
|
911
|
+
Chosen.prototype.keyup_arrow = function() {
|
912
|
+
var prev_sibs;
|
913
|
+
if (!this.results_showing && !this.is_multiple) {
|
914
|
+
return this.results_show();
|
915
|
+
} else if (this.result_highlight) {
|
916
|
+
prev_sibs = this.result_highlight.prevAll("li.active-result");
|
917
|
+
if (prev_sibs.length) {
|
918
|
+
return this.result_do_highlight(prev_sibs.first());
|
919
|
+
} else {
|
920
|
+
if (this.choices > 0) this.results_hide();
|
921
|
+
return this.result_clear_highlight();
|
922
|
+
}
|
923
|
+
}
|
924
|
+
};
|
925
|
+
|
926
|
+
Chosen.prototype.keydown_backstroke = function() {
|
927
|
+
var next_available_destroy;
|
928
|
+
if (this.pending_backstroke) {
|
929
|
+
this.choice_destroy(this.pending_backstroke.find("a").first());
|
930
|
+
return this.clear_backstroke();
|
931
|
+
} else {
|
932
|
+
next_available_destroy = this.search_container.siblings("li.search-choice").last();
|
933
|
+
if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
|
934
|
+
this.pending_backstroke = next_available_destroy;
|
935
|
+
if (this.single_backstroke_delete) {
|
936
|
+
return this.keydown_backstroke();
|
937
|
+
} else {
|
938
|
+
return this.pending_backstroke.addClass("search-choice-focus");
|
939
|
+
}
|
940
|
+
}
|
941
|
+
}
|
942
|
+
};
|
943
|
+
|
944
|
+
Chosen.prototype.clear_backstroke = function() {
|
945
|
+
if (this.pending_backstroke) {
|
946
|
+
this.pending_backstroke.removeClass("search-choice-focus");
|
947
|
+
}
|
948
|
+
return this.pending_backstroke = null;
|
949
|
+
};
|
950
|
+
|
951
|
+
Chosen.prototype.keydown_checker = function(evt) {
|
952
|
+
var stroke, _ref;
|
953
|
+
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
954
|
+
this.search_field_scale();
|
955
|
+
if (stroke !== 8 && this.pending_backstroke) this.clear_backstroke();
|
956
|
+
switch (stroke) {
|
957
|
+
case 8:
|
958
|
+
this.backstroke_length = this.search_field.val().length;
|
959
|
+
break;
|
960
|
+
case 9:
|
961
|
+
if (this.results_showing && !this.is_multiple) this.result_select(evt);
|
962
|
+
this.mouse_on_container = false;
|
963
|
+
break;
|
964
|
+
case 13:
|
965
|
+
evt.preventDefault();
|
966
|
+
break;
|
967
|
+
case 38:
|
968
|
+
evt.preventDefault();
|
969
|
+
this.keyup_arrow();
|
970
|
+
break;
|
971
|
+
case 40:
|
972
|
+
this.keydown_arrow();
|
973
|
+
break;
|
974
|
+
}
|
975
|
+
};
|
976
|
+
|
977
|
+
Chosen.prototype.search_field_scale = function() {
|
978
|
+
var dd_top, div, h, style, style_block, styles, w, _i, _len;
|
979
|
+
if (this.is_multiple) {
|
980
|
+
h = 0;
|
981
|
+
w = 0;
|
982
|
+
style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
|
983
|
+
styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
|
984
|
+
for (_i = 0, _len = styles.length; _i < _len; _i++) {
|
985
|
+
style = styles[_i];
|
986
|
+
style_block += style + ":" + this.search_field.css(style) + ";";
|
987
|
+
}
|
988
|
+
div = $('<div />', {
|
989
|
+
'style': style_block
|
990
|
+
});
|
991
|
+
div.text(this.search_field.val());
|
992
|
+
$('body').append(div);
|
993
|
+
w = div.width() + 25;
|
994
|
+
div.remove();
|
995
|
+
if (w > this.f_width - 10) w = this.f_width - 10;
|
996
|
+
this.search_field.css({
|
997
|
+
'width': w + 'px'
|
998
|
+
});
|
999
|
+
dd_top = this.container.height();
|
1000
|
+
return this.dropdown.css({
|
1001
|
+
"top": dd_top + "px"
|
1002
|
+
});
|
1003
|
+
}
|
1004
|
+
};
|
1005
|
+
|
1006
|
+
Chosen.prototype.generate_random_id = function() {
|
1007
|
+
var string;
|
1008
|
+
string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
|
1009
|
+
while ($("#" + string).length > 0) {
|
1010
|
+
string += this.generate_random_char();
|
1011
|
+
}
|
1012
|
+
return string;
|
1013
|
+
};
|
1014
|
+
|
1015
|
+
return Chosen;
|
1016
|
+
|
1017
|
+
})(AbstractChosen);
|
1018
|
+
|
1019
|
+
get_side_border_padding = function(elmt) {
|
1020
|
+
var side_border_padding;
|
1021
|
+
return side_border_padding = elmt.outerWidth() - elmt.width();
|
1022
|
+
};
|
1023
|
+
|
1024
|
+
root.get_side_border_padding = get_side_border_padding;
|
1025
|
+
|
1026
|
+
}).call(this);
|