Si.views.management = function () { var tpl = Si.loadTemplate(Routes.management_tpl_path()), slider_tpl = Si.loadTemplate(Routes.slider_tpl_path()), switch_tpl = Si.loadTemplate(Routes.switch_tpl_path()), controllers = Si.collections.Controller, roomStay = Si.collections.RoomStay.first(); var temps = '', lights = ''; controllers.each(function(controller) { if(controller.get('type') == 'temperature') { temps += _.template(slider_tpl, controller.toJSON()); } else if (controller.get('type') == 'light') { lights += _.template(switch_tpl, controller.toJSON()); } }); var fulfilled = _.template(tpl, { status: roomStay.get('status'), temperatures: temps, lights: lights }); return { el: $(fulfilled), init: function(urlObj, options) { this.el.bind("pageshow", function() { $("input[name='service-status']").bind( "change", function(event, ui) { $("input[name='service-status']").checkboxradio('disable'); Si.socket.emit('roomStatusUpdate', { _id: roomStay.get('_id'), status: $(event.target).val() }, function (data) { if(data) { roomStay.set('status', $(event.target).val()); roomStay.save(); $("input[name='service-status']").checkboxradio('enable'); } else { console.log('failed'); } }); }); $(".slider").bind("change", function(event) { $(this).slider('disable'); var that = this; Si.socket.emit('controllerStateUpdate', { _id: this.id, state: $(event.target).val() }, function (data) { if(data) { var controller = controllers.where({'_id': this.id})[0]; controller.set('state', $(event.target).val()); controller.save(); } else { console.log('failed'); } $(that).slider('enable'); }); console.log($(event.target).val()); }); }); } } };