qs.defineNS('app'); app.BenchmarkPlans_Admin = qs.createObject(); app.BenchmarkPlans_Admin.prototype = { options:{ id: null }, initialize: function (options) { this.options = options; var self = this; var yearSelect = $("select#year"); var year = yearSelect.val(); this.doSortList('availableList'); this.doSortList('selectedList'); yearSelect.change(function () { year = yearSelect.val(); if (year) { self.updateCountiesAjax(year, self.options.id); } else { $('.availableList').empty(); } }); }, updateCountiesAjax: function (year, id) { var self = this; var request = { action: 'getCounties', year: year, id: id }; qs.ajax(qs.constant('BASE_URL') + '/' + qs.constant('CURRENT_PAGE'), request).done(function (data) { if (typeof data === 'object') { var avaliable = $('.availableList').empty(); $('.selectedList').empty(); $('.selectedCount').html('0'); $.each(data, function (key, value) { avaliable.append('
  • ' + value + '
  • '); }); self.doSortList('availableList'); MultiDraggableSelect_Counties.initLists(); } }); }, doSortList: function(listClass) { var container = $('.' + listClass); var sortedData = $('ul.' + listClass +' li.item').sort(function (a, b) { return $(a).text() == $(b).text() ? 0 : $(a).text() < $(b).text() ? -1 : 1 }); container.empty(); sortedData.appendTo(container); } };