redmine_extensions 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/redmine_extensions/redmine_extensions.js +9 -6
  3. data/app/assets/javascripts/redmine_extensions/redmine_extensions.js.orig +648 -0
  4. data/app/controllers/easy_settings_controller.rb +1 -1
  5. data/app/helpers/redmine_extensions/application_helper.rb +2 -2
  6. data/app/helpers/redmine_extensions/application_helper.rb.orig +189 -0
  7. data/app/views/common/_closing_modal.html.erb +2 -2
  8. data/app/views/common/_collapsible_module_layout.html.erb +1 -1
  9. data/app/views/common/close_modal.js.erb +4 -4
  10. data/app/views/easy_entity_assignments/_query_index.html.erb.orig +16 -0
  11. data/app/views/easy_settings/edit.html.erb +1 -1
  12. data/config/database.yml +15 -0
  13. data/config/routes.rb +7 -3
  14. data/lib/generators/redmine_extensions/entity/templates/_sidebar.html.erb.erb +8 -8
  15. data/lib/generators/redmine_extensions/entity/templates/context_menu.html.erb.erb +7 -7
  16. data/lib/generators/redmine_extensions/entity/templates/custom_field.rb.erb +7 -7
  17. data/lib/generators/redmine_extensions/entity/templates/edit.html.erb.erb +18 -18
  18. data/lib/generators/redmine_extensions/entity/templates/edit.js.erb.erb +16 -16
  19. data/lib/generators/redmine_extensions/entity/templates/index.api.rsb.erb +5 -5
  20. data/lib/generators/redmine_extensions/entity/templates/index.html.erb.erb +4 -4
  21. data/lib/generators/redmine_extensions/entity/templates/index.js.erb.erb +10 -10
  22. data/lib/generators/redmine_extensions/entity/templates/mail_added.html.erb.erb +1 -1
  23. data/lib/generators/redmine_extensions/entity/templates/mail_added.text.erb.erb +2 -2
  24. data/lib/generators/redmine_extensions/entity/templates/mail_updated.text.erb.erb +2 -2
  25. data/lib/generators/redmine_extensions/entity/templates/migration.rb.erb +9 -9
  26. data/lib/generators/redmine_extensions/entity/templates/new.html.erb.erb +18 -18
  27. data/lib/generators/redmine_extensions/entity/templates/new.js.erb.erb +16 -16
  28. data/lib/generators/redmine_extensions/entity/templates/routes.rb.erb +12 -12
  29. data/lib/generators/redmine_extensions/entity/templates/show.html.erb.erb +37 -37
  30. data/lib/generators/redmine_extensions/entity/templates/show.js.erb.erb +10 -10
  31. data/lib/redmine_extensions/engine.rb +0 -9
  32. data/lib/redmine_extensions/redmine_patches/controllers/issues_controller_patch.rb +9 -0
  33. data/lib/redmine_extensions/version.rb +1 -1
  34. data/lib/redmine_extensions/version.rb.orig +7 -0
  35. data/spec/redmine/bin/about +0 -0
  36. data/spec/redmine/bin/bundle +0 -0
  37. data/spec/redmine/bin/rails +0 -0
  38. data/spec/redmine/bin/rake +0 -0
  39. data/spec/redmine/extra/svn/reposman.rb +0 -0
  40. data/spec/redmine/public/dispatch.fcgi.example +0 -0
  41. data/spec/redmine/script/about +0 -0
  42. data/spec/redmine/script/rails +0 -0
  43. data/spec/support/easy_queries_helpers.rb +0 -0
  44. metadata +1933 -1925
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60a98ad433d93c545467113ae031c3af60e8c631
4
- data.tar.gz: b7626b9fd3da9759e1195511dfae242f30142c56
3
+ metadata.gz: 542371605ecd4f76aa7d45ab68a275df6995e882
4
+ data.tar.gz: 7e69634fd35a4005d4e7f1effecfdb621a69ad03
5
5
  SHA512:
6
- metadata.gz: 101c58bdb820c4909ecfacb79f3f935a79bd0dccadb5e1ea49da23fb23b3e8d7efd44d867b34c12a868f41d9aac5288b3be5acd401934ae2faf8f3e1c6104a2a
7
- data.tar.gz: 8288dcdbe2f9ca271a3f0ce7c37cf6c16f535b7935428308f17b26383d76f18d8106c1fad7a0b8b4adf518ad923687046cb1db73dd5bde466b0f5d122014ae1a
6
+ metadata.gz: ac2ef6ab15283e5d15d8c2c609d529067d0bee8d32d3ab9c41ef7a055d3b4b20b16be939770d2ff2fb94b1c1103bb7f25fea0b5ee59e1c0e8dadc8dc46986fd5
7
+ data.tar.gz: 1a2a7187ba205860232a8f6eee4c5c1d8973e8d6e66f56fac3b0b52645d012e2266d5e6fbada9528a15be1e6d8734aeb9026fbc3a7aac023a1671cbfe96bfc89
@@ -389,7 +389,7 @@ window.closeFlashMessage = (function($element){
389
389
  select.append(option);
390
390
  });
391
391
  $container = $elem.closest('.easy-multiselect-tag-container');
392
- $container.children(':input').prop('disabled', true);
392
+ $container.find(':input').prop('disabled', true);
393
393
  $container.children().hide();
394
394
  $container.append(select);
395
395
  that.valueElement = select;
@@ -566,17 +566,20 @@ window.closeFlashMessage = (function($element){
566
566
 
567
567
  setValue: function(values) {
568
568
  var that = this;
569
- if( typeof values == 'undefined' || !values )
569
+ if( typeof values === 'undefined' || !values )
570
570
  return false;
571
571
 
572
- if( that.options.multiple ) {
573
- that.valueElement.entityArray('clear');
574
- }
575
572
  if( this.options.preload ) {
576
573
  this.load(function(){
577
- that._setValues(values)
574
+ if( that.options.multiple ) {
575
+ that.valueElement.entityArray('clear');
576
+ }
577
+ that._setValues(values);
578
578
  });
579
579
  } else {
580
+ if( that.options.multiple ) {
581
+ that.valueElement.entityArray('clear');
582
+ }
580
583
  that._setValues(values);
581
584
  }
582
585
  },
@@ -0,0 +1,648 @@
1
+ REDMINE_EXTENSIONS = {
2
+
3
+ toggleDiv: function(el_or_id) {
4
+ var el;
5
+ if (typeof(el_or_id) === 'string') {
6
+ el = $('#' + el_or_id);
7
+ } else {
8
+ el = el_or_id;
9
+ }
10
+
11
+ el.toggleClass('collapsed').slideToggle('fast');
12
+ },
13
+
14
+ toggleDivAndChangeOpen: function(toggleElementId, changeOpenElement) {
15
+ REDMINE_EXTENSIONS.toggleDiv(toggleElementId);
16
+ $(changeOpenElement).toggleClass('open');
17
+ },
18
+
19
+ toggleFilterButtons: function(elButtonsID, elFilter1ID, elFilter2ID)
20
+ {
21
+ var elButtons = $('#' + elButtonsID);
22
+ var elFilter1 = $('#' + elFilter1ID);
23
+ var elFilter2 = $('#' + elFilter2ID);
24
+
25
+ if (elFilter1.hasClass('collapsed') && elFilter2.hasClass('collapsed')) {
26
+ elButtons.slideUp('slow');
27
+ } else {
28
+ elButtons.slideDown('slow');
29
+ }
30
+ }
31
+
32
+ };
33
+
34
+
35
+ // TODO delete - it will be added to extensions
36
+ (function($, undefined) {
37
+
38
+ var plugin = 'easygrouploader';
39
+ if( $.fn[plugin] )
40
+ return;
41
+ var defaults = {
42
+ next_button_cols: 1,
43
+ load_opened: false,
44
+ load_limit: 25,
45
+ texts: {
46
+ 'next': 'Next',
47
+ }
48
+ };
49
+
50
+ $.fn[plugin] = function(options, methodParams) {
51
+ $.each($(this), function(idx) {
52
+ var instance = $(this).data('plugin_' + plugin);
53
+ if (!instance) {
54
+ instance = new EasyGroupLoader(this, options);
55
+ $(this).data('plugin_' + plugin, instance);
56
+ } else if (typeof options === 'string') {
57
+ switch (options) {
58
+ case 'load_groups':
59
+ if (instance.options.load_opened)
60
+ instance.load_all_groups();
61
+ }
62
+ }
63
+ });
64
+ return $(this);
65
+ };
66
+
67
+
68
+ function EasyGroupLoader(elem, options) {
69
+ this.groupsContainer = $(elem);
70
+ this.options = $.extend({}, defaults, options);
71
+ this.loadUrl = options.loadUrl || elem.data('url');
72
+ this.callback = options.callback;
73
+ this.texts = this.options.texts;
74
+
75
+ this.init();
76
+ }
77
+
78
+ EasyGroupLoader.prototype.init = function()
79
+ {
80
+ var self = this;
81
+ this.groupsContainer.on('click', '.group .expander', function(evt) {
82
+ var $row = $(this).closest('tr.group');
83
+ var group = $row.data('group') || new Group(self, $row);
84
+
85
+ if (!group.loaded) {
86
+ if (!group.header.hasClass('group-loaded')) {
87
+ group.load();
88
+ group.toggle();
89
+ }
90
+ } else {
91
+ group.toggle();
92
+ if(typeof(self.callback) === 'function')
93
+ self.callback();
94
+ }
95
+
96
+ });
97
+ if (this.options.load_opened)
98
+ this.load_all_groups();
99
+ };
100
+
101
+ EasyGroupLoader.prototype.initInlineEdit = function()
102
+ {
103
+ $('.multieditable-container:not(.multieditable-initialized)', this.groupsContainer).each(function() {
104
+ initInlineEditForContainer(this);
105
+ });
106
+ initProjectEdit();
107
+ initEasyAutocomplete();
108
+ };
109
+
110
+ EasyGroupLoader.prototype.load_all_groups = function()
111
+ {
112
+ var group;
113
+ var self = this;
114
+ var groups_to_load = [];
115
+ var entity_count = 0;
116
+ $('.group', this.groupsContainer).not('.group-loaded').each(function() {
117
+ group = $(this).data('group') || new Group(self, $(this));
118
+ if (!group.loaded) {
119
+ groups_to_load.push(group);
120
+ entity_count += group.count;
121
+ }
122
+ if (entity_count >= self.options.load_limit) {
123
+ self.load_groups(groups_to_load);
124
+ entity_count = 0;
125
+ groups_to_load = [];
126
+ }
127
+ });
128
+ if (groups_to_load.length > 0) {
129
+ this.load_groups(groups_to_load);
130
+ }
131
+ };
132
+
133
+ EasyGroupLoader.prototype.load_groups = function(groups_to_load) {
134
+ var self = this;
135
+ var group_names = groups_to_load.map(function(group) {
136
+ return group.group_value;
137
+ });
138
+ // var url = EPExtensions.setAttrToUrl(, 'group_to_load', group_names);
139
+ $.ajax(this.loadUrl, {
140
+ method: 'GET',
141
+ data: { group_to_load: group_names },
142
+ success: function(data, textStatus, request) {
143
+ var parsed = (typeof data === 'object') ? data : $.parseJSON(data);
144
+
145
+ $.each(groups_to_load, function(idx, group) {
146
+ group.parseData(parsed[group.group_name]);
147
+ group.toggle();
148
+ });
149
+ self.initInlineEdit();
150
+ }
151
+ });
152
+ };
153
+
154
+ function Group(loader, header)
155
+ {
156
+ this.loader = loader;
157
+ this.header = header;
158
+ this.header.data('group', this);
159
+ this.group_name = this.header.data('group-name');
160
+ this.group_value = this.group_name;
161
+ if( $.isArray(this.group_name) ) {
162
+ // potencialne nebezpecne - TODO: vymyslet spravny oddelovac
163
+ this.group_name = '["' + this.group_name.join('", "') + '"]';
164
+ }
165
+ this.count = parseInt(this.header.data('entity-count'));
166
+ this.pages = this.header.data('pages') || 1;
167
+ this.loaded = this.header.hasClass('preloaded');
168
+ }
169
+
170
+ Group.prototype.toggle = function() {
171
+ EPExtensions.issuesToggleRowGroup(this.header);
172
+ };
173
+
174
+ Group.prototype.load = function() {
175
+ var $hrow = this.header;
176
+ var self = this;
177
+
178
+ if (!$hrow.hasClass('group-loaded')) {
179
+ $hrow.addClass('group-loaded');
180
+ $.ajax(this.loader.loadUrl, {
181
+ method: 'GET',
182
+ data: {
183
+ group_to_load: this.group_value
184
+ },
185
+ success: function(data, textStatus, request) {
186
+ self.parseData(data);
187
+ self.loader.initInlineEdit();
188
+ if(typeof(self.loader.callback) === 'function')
189
+ self.loader.callback();
190
+ }
191
+ });
192
+ }
193
+ };
194
+
195
+ Group.prototype.parseData = function(data) {
196
+ var $hrow = this.header;
197
+
198
+ this.rows = $(data);
199
+ $hrow.after(this.rows);
200
+ $hrow.data('group-page', 1);
201
+ this.loaded = true;
202
+ if (this.pages > 1) {
203
+ this.createNextButton();
204
+ // .find doesn't work on this set
205
+ this.rows.filter("tr:last").after(this.next_button);
206
+ }
207
+ };
208
+
209
+ Group.prototype.loadNext = function() {
210
+ var $hrow = this.header;
211
+ var page = $hrow.data('group-page') + 1;
212
+ var self = this;
213
+
214
+ if (page <= this.pages) {
215
+ $.ajax(this.loader.loadUrl, {
216
+ method: 'GET',
217
+ data: {
218
+ page: page,
219
+ group_to_load: this.group_value
220
+ },
221
+ success: function(data, textStatus, request) {
222
+ self.next_button.before(data);
223
+
224
+ self.loader.initInlineEdit();
225
+ $hrow.data('group-page', page);
226
+ if (self.pages === page) {
227
+ self.next_button.remove();
228
+ }
229
+ }
230
+ });
231
+ }
232
+ };
233
+
234
+ Group.prototype.createNextButton = function() {
235
+ //var next_link_url = EPExtensions.setAttrToUrl(this.loader.loadUrl, 'group_to_load', this.group_value);
236
+ var next_link_url = this.loader.loadUrl + ( this.loader.loadUrl.indexOf('?') >= 0 ? '&' : '?' ) + $.param({group_to_load: this.group_value});
237
+ this.next_link = $('<a>', {href: next_link_url, 'class': 'button'}).text(this.loader.texts['next']).append($("<i>", {"class": "icon-arrow"}));
238
+ this.next_button = $('<tr/>', {'class': 'easy-next-button'}).html($('<td>', {colspan: this.loader.options.next_button_cols, "class": "text-center"}).html(this.next_link));
239
+
240
+ var self = this;
241
+
242
+ this.next_link.click(function(evt) {
243
+ evt.preventDefault();
244
+ self.loadNext();
245
+ });
246
+ };
247
+
248
+ })(jQuery);
249
+
250
+ window.cancelAnimFrame = ( function() {
251
+ return window.cancelAnimationFrame ||
252
+ window.webkitCancelRequestAnimationFrame ||
253
+ window.mozCancelRequestAnimationFrame ||
254
+ window.oCancelRequestAnimationFrame ||
255
+ window.msCancelRequestAnimationFrame ||
256
+ clearTimeout;
257
+ } )();
258
+
259
+ window.requestAnimFrame = (function(){
260
+ return window.requestAnimationFrame ||
261
+ window.webkitRequestAnimationFrame ||
262
+ window.mozRequestAnimationFrame ||
263
+ window.oRequestAnimationFrame ||
264
+ window.msRequestAnimationFrame ||
265
+ function(callback){
266
+ return window.setTimeout(callback, 1000 / 60);
267
+ };
268
+ })();
269
+
270
+ window.showFlashMessage = (function(type, message, delay){
271
+ var $content = $("#content");
272
+ $content.find(".flash").remove();
273
+ var element = document.createElement("div");
274
+ element.className = 'fixed flash ' + type;
275
+ element.style.position = 'fixed';
276
+ element.style.zIndex = '10001';
277
+ element.style.right = '5px';
278
+ element.style.top = '5px';
279
+ element.setAttribute("onclick", "closeFlashMessage($(this))");
280
+ var close = document.createElement("a");
281
+ close.className = 'icon-close close-icon';
282
+ close.setAttribute("href", "javascript:void(0)");
283
+ close.style.float = 'right';
284
+ close.style.marginLeft = '5px';
285
+ // close.setAttribute("onclick", "closeFlashMessage($(this))");
286
+ var span = document.createElement("span");
287
+ span.innerHTML = message;
288
+ element.appendChild(close);
289
+ element.appendChild(span);
290
+ $content.prepend(element);
291
+ var $element = $(element);
292
+ if(delay){
293
+ setTimeout(function(){
294
+ requestAnimFrame(function(){
295
+ closeFlashMessage($element);
296
+ });
297
+ }, delay);
298
+ }
299
+ return $element;
300
+ });
301
+
302
+ window.closeFlashMessage = (function($element){
303
+ $element.closest('.flash').fadeOut(500, function(){$element.remove();});
304
+ });
305
+
306
+
307
+ (function($, undefined) {
308
+
309
+ $.widget('easy.easymultiselect', {
310
+ options: {
311
+ source: null,
312
+ rootElement: null, // rootElement in the response from source
313
+ selected: null,
314
+ multiple: true, // multiple values can be selected
315
+ preload: true, // load all possible values
316
+ position: {collision: 'flip'},
317
+ autofocus: false,
318
+ inputName: null, // defaults to element prop name
319
+ render_item: function(ul, item) {
320
+ return $("<li>")
321
+ .data("item.autocomplete", item)
322
+ .append(item.label)
323
+ .appendTo(ul);
324
+ },
325
+ activate_on_input_click: true,
326
+ load_immediately: false,
327
+ show_toggle_button: true,
328
+ select_first_value: true,
329
+ autocomplete_options: {}
330
+ },
331
+
332
+ _create: function() {
333
+ this.selectedValues = this.options.selected;
334
+ this._createUI();
335
+ this.expanded = false;
336
+ this.valuesLoaded = false;
337
+ this.afterLoaded = [];
338
+ if ( Array.isArray(this.options.source) ) {
339
+ this.options.preload = true;
340
+ this._initData(this.options.source);
341
+ } else if ( this.options.preload && this.options.load_immediately) {
342
+ this.load();
343
+ } else if ( this.selectedValues ) {
344
+ this.setValue( this.selectedValues );
345
+ }
346
+ },
347
+
348
+ _createUI: function() {
349
+ var that = this;
350
+ this.element.wrap('<span class="easy-autocomplete-tag"></span>');
351
+ this.tag = this.element.parent();
352
+ this.inputName = this.options.inputName || this.element.prop('name');
353
+
354
+ if( this.options.multiple ) { // multiple values
355
+ this.valueElement = $('<span></span>');
356
+ this.tag.after(this.valueElement);
357
+
358
+ if (this.options.show_toggle_button)
359
+ this._createToggleButton();
360
+
361
+ this.valueElement.entityArray({
362
+ inputNames: this.inputName,
363
+ afterRemove: function (entity) {
364
+ that.element.trigger('change');
365
+ }
366
+ });
367
+ } else { //single value
368
+ this.valueElement = $('<input>', {type: 'hidden', name: this.inputName});
369
+ this.element.after(this.valueElement);
370
+ }
371
+
372
+ this._createAutocomplete();
373
+ if( !this.options.multiple ) {
374
+ this.element.css('margin-right', 0);
375
+ }
376
+ },
377
+
378
+ _createToggleButton: function() {
379
+ var that = this;
380
+ this.link_ac_toggle = $('<a>').attr('class', 'icon icon-add clear-link');
381
+ this.link_ac_toggle.click(function(evt) {
382
+ var $elem = $(this);
383
+ evt.preventDefault();
384
+ that.load(function(){
385
+ select = $('<select>').prop('multiple', true).prop('size', 5).prop('name', that.inputName);
386
+ $.each(that.possibleValues, function(i, v) {
387
+ option = $('<option>').prop('value', v.id).text(v.value);
388
+ option.prop('selected', that.getValue().indexOf(v.id) > -1);
389
+ select.append(option);
390
+ });
391
+ $container = $elem.closest('.easy-multiselect-tag-container');
392
+ $container.find(':input').prop('disabled', true);
393
+ $container.children().hide();
394
+ $container.append(select);
395
+ that.valueElement = select;
396
+ that.expanded = true;
397
+ });
398
+ });
399
+ this.element.parent().addClass('input-append');
400
+ this.element.after(this.link_ac_toggle);
401
+ },
402
+
403
+ _createAutocomplete: function() {
404
+ var that = this;
405
+
406
+ that.element.autocomplete($.extend({
407
+ source: function(request, response) {
408
+ if( that.options.preload ) {
409
+ that.load(function(){
410
+ var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
411
+ response($.grep(that.possibleValues, function(val, i) {
412
+ return ( !that.options.multiple || !request.term || matcher.test(val.value));
413
+ }));
414
+ }, function(){
415
+ response();
416
+ });
417
+ } else { // asking server everytime
418
+ $.getJSON(that.options.source, {
419
+ term: request.term
420
+ }, function(json) {
421
+ response(that.options.rootElement ? json[that.options.rootElement] : json);
422
+ });
423
+ }
424
+ },
425
+ minLength: 0,
426
+ select: function(event, ui) {
427
+ that.selectValue(ui.item)
428
+ return false;
429
+ },
430
+ change: function(event, ui) {
431
+ if (!ui.item) {
432
+ $(this).val('');
433
+ if( !that.options.multiple ) {
434
+ that.valueElement.val('');
435
+ that.valueElement.change();
436
+ }
437
+ }
438
+ },
439
+ position: this.options.position,
440
+ autoFocus: this.options.autofocus
441
+ }, this.options.autocomplete_options)).data("ui-autocomplete")._renderItem = this.options.render_item;
442
+
443
+ this.element.click(function() {
444
+ $(this).select();
445
+ });
446
+ if( this.options.activate_on_input_click ) {
447
+ this.element.on('click', function() {
448
+ if(!that.options.preload)
449
+ that.element.focus().val('');
450
+ that.element.trigger('keydown');
451
+ that.element.autocomplete("search", that.element.val());
452
+ });
453
+ }
454
+
455
+ $("<button type='button'>&nbsp;</button>")
456
+ .attr("tabIndex", -1)
457
+ .insertAfter(that.element)
458
+ .button({
459
+ icons: {
460
+ primary: "ui-icon-triangle-1-s"
461
+ },
462
+ text: false
463
+ })
464
+ .removeClass("ui-corner-all")
465
+ .addClass("ui-corner-right ui-button-icon")
466
+ .css('font-size', '10px')
467
+ .css('margin-left', -1)
468
+ .click(function() {
469
+ if (that.element.autocomplete("widget").is(":visible")) {
470
+ that.element.autocomplete("close");
471
+ that.element.blur();
472
+ return;
473
+ }
474
+ $(this).blur();
475
+ if(!that.options.preload)
476
+ that.element.focus().val('');
477
+ that.element.trigger('keydown');
478
+ that.element.autocomplete("search", that.element.val());
479
+ });
480
+ },
481
+
482
+ _formatData: function(data) {
483
+ return $.map(data, function(elem, i){
484
+ var id, value;
485
+ if (elem instanceof Array) {
486
+ value = elem[0];
487
+ id = elem[1];
488
+ } else if (elem instanceof Object) {
489
+ value = elem.value;
490
+ id = elem.id;
491
+ } else {
492
+ id = value = elem;
493
+ }
494
+ return {value: value, id: id};
495
+ });
496
+ },
497
+
498
+ _initData: function(data) {
499
+ this.possibleValues = this._formatData(data);
500
+ this.valuesLoaded = true;
501
+
502
+ this.selectedValues = this.selectedValues ? this.selectedValues : [];
503
+ if( this.selectedValues.length == 0 && this.options.preload && this.options.select_first_value && this.possibleValues.length > 0 ) {
504
+ this.selectedValues.push(this.possibleValues[0]['id'])
505
+ }
506
+
507
+ this.setValue(this.selectedValues);
508
+ },
509
+
510
+ load: function(success, fail) {
511
+ var that = this;
512
+ if( this.valuesLoaded ) {
513
+ if( typeof success === 'function' )
514
+ success();
515
+ return;
516
+ }
517
+
518
+ if( typeof success === 'function' )
519
+ this.afterLoaded.push(success);
520
+
521
+ if( this.loading )
522
+ return;
523
+
524
+ this.loading = true;
525
+ $.ajax(this.options.source, {
526
+ dataType: 'json',
527
+ success: function(json, status, xhr) {
528
+ data = that.options.rootElement ? json[that.options.rootElement] : json
529
+ that._initData(data);
530
+ for (var i = that.afterLoaded.length - 1; i >= 0; i--) {
531
+ that.afterLoaded[i].call();
532
+ }
533
+ },
534
+ error: fail
535
+ }).always(function(){
536
+ that.loading = false;
537
+ });
538
+ },
539
+
540
+ selectValue: function(value) {
541
+ if( this.options.multiple ) {
542
+ this.valueElement.entityArray('add', {
543
+ id: value.id,
544
+ name: value.value
545
+ });
546
+ this.element.trigger('change');
547
+ this.element.val('');
548
+ } else {
549
+ this.element.val(value.value);
550
+ this.valueElement.val(value.id);
551
+ this.valueElement.change();
552
+ }
553
+ },
554
+
555
+ setValue: function(values) {
556
+ var that = this;
557
+ if( typeof values === 'undefined' || !values )
558
+ return false;
559
+
560
+ if( that.options.multiple ) {
561
+ that.valueElement.entityArray('clear');
562
+ }
563
+ if( this.options.preload ) {
564
+ this.load(function(){
565
+ <<<<<<< HEAD
566
+ that._setValues(values)
567
+ });
568
+ } else {
569
+ =======
570
+ if( that.options.multiple ) {
571
+ that.valueElement.entityArray('clear');
572
+ }
573
+ that._setValues(values);
574
+ });
575
+ } else {
576
+ if( that.options.multiple ) {
577
+ that.valueElement.entityArray('clear');
578
+ }
579
+ >>>>>>> stable
580
+ that._setValues(values);
581
+ }
582
+ },
583
+
584
+ _setValues: function(values) {
585
+ var selected = [];
586
+
587
+ if( values.length == 0 )
588
+ return false;
589
+
590
+ // allows the combination of only id values and values with label
591
+ for (var i = values.length - 1; i >= 0; i--) {
592
+ var identifier, label;
593
+ if( values[i] instanceof Object && !Array.isArray(values[i]) && values[i] !== null ) {
594
+ selected.push( values[i] );
595
+ } else if( this.options.preload && Array.isArray(this.possibleValues) ) {
596
+ for(var j = this.possibleValues.length - 1; j >= 0; j-- ) {
597
+ if ( values[i] == this.possibleValues[j].id || values[i] == this.possibleValues[j].id.toString() ) {
598
+ selected.push(this.possibleValues[j]);
599
+ break;
600
+ }
601
+ }
602
+ } else {
603
+ selected.push( {id: values[i], value: values[i]} );
604
+ }
605
+ }
606
+ for (var i = selected.length - 1; i >= 0; i--) {
607
+ if(this.options.multiple) {
608
+ this.valueElement.entityArray('add', { id: selected[i].id, name: selected[i].value });
609
+ } else {
610
+ this.element.val(selected[i].value);
611
+ this.valueElement.val(selected[i].id);
612
+ }
613
+ }
614
+ },
615
+
616
+ getValue: function(with_label) {
617
+ var result;
618
+ if ( this.options.multiple && !this.expanded ) {
619
+ <<<<<<< HEAD
620
+ result = this.valueElement.entityArray('getValue'); // entityArray
621
+ } else if ( this.options.multiple ) {
622
+ result = this.valueElement.val(); // select multiple=true
623
+ } else {
624
+ result = [this.valueElement.val()]; // hidden field
625
+ }
626
+ if( with_label ) {
627
+ result = this.possibleValues.filter(function(el) {
628
+ return result.indexOf( el.id ) >= 0;
629
+ });
630
+ =======
631
+ result = this.valueElement.entityArray('getValue'); // entityArray
632
+ } else if ( this.options.multiple ) {
633
+ result = this.valueElement.val(); // select multiple=true
634
+ } else {
635
+ result = [this.valueElement.val()]; // hidden field
636
+ }
637
+ if( with_label ) {
638
+ result = this.possibleValues.filter(function(el) {
639
+ return result.indexOf( el.id ) >= 0;
640
+ });
641
+ >>>>>>> stable
642
+ }
643
+ return result;
644
+ }
645
+
646
+ });
647
+
648
+ })(jQuery);