Views.Select = Views.Base.extend({ classType: "Views.Select", tagName: "div", listenEvents: function() { //See Views.Base listenDefaultEvents() this.on("oninitialize", this.onInitialize); this.on("onrender", this.onRender); }, triggerEventsOn: function() { //See Views.Base launchDefaultActionsOn() }, triggerAddModelToCollectionOn: function() { var that = this; this.on("onmodelchange", function(event) { that.trigger("onaddmodeltocollection"); }); }, hide: function(callback) { //this.$el.animate({height:'0px'}, 100, callback); var that = this; this.$el.slideUp(100, function() { if (callback) { callback(); } that.trigger("onhide"); }); this.options.isShowed = false; }, show: function(callback) { //this.$el.animate({height:'0px'}, 100, callback); var that = this; this.$el.slideDown(100, function() { if (callback) { callback(); } that.trigger("onshow"); }); this.options.isShowed = true; }, onInitialize: function() { if ((this.options.isrequired == false)) { if (this.options.possiblevalues) { if (!this.options.possiblevalues.getByProperty("value", "")) { var aPossibleValue = new Models.PossibleValue(); aPossibleValue.value = ""; aPossibleValue.label = ""; aPossibleValue.set("label", ""); this.options.possiblevalues.add(aPossibleValue, {at: 0}); } this.options.possiblevalues.setValueSelected(this.model.get("value")); var emptyPossibleValue = this.options.possiblevalues.getByProperty("value", ""); if (emptyPossibleValue) { emptyPossibleValue.label = ""; emptyPossibleValue.set("label", ""); } } } }, onRender: function() { $('option[value="' + this.model.get("value") + '"]', this.$el).attr('selected','selected'); //console.log(this.model); }, resetAddEl: function() { var addAction = this.options.parentview.options.actions.add; var authorizedouble = addAction.authorizedouble; if (!authorizedouble) { this.resetEl(true); var aSelect = this.$el; if (this.options.parentview.model.length >= this.options.possiblevalues.length - 1) { this.hide(); } else { this.show(); } } this.$el.val(""); $('option[value=""]', this.$el).html(edApplication().labels.LABELSELECTAVALUE); }, resetEl: function(isAddEl) { var addAction = this.options.parentview.options.actions.add; var authorizedouble = addAction.authorizedouble; if (!authorizedouble) { var selectedValues = new Array(); this.options.parentview.model.each(function(item) { selectedValues.push(item.get("value")); }); var options = ""; for (var i=0; i" + this.options.possiblevalues.models[i].get("label") + ""; } var aSelect = this.$el; var currentVal = aSelect.val(); $('option', aSelect).remove(); aSelect.append(options); $("option[value='" + currentVal + "']", aSelect).attr('selected','selected'); for (var j=0; j