1 MBX.QueueController = MBX.JsController.create("QueueController", { 2 model: MBX.Queue, 3 4 subscriptions: {}, 5 6 handleTimerComplete: function (evt) { 7 var queue = evt.queue; 8 if (queue.nextFunction()) { 9 var criteria = queue.get("criteria"); 10 if (criteria) { 11 if (criteria()) { 12 queue.fireNextFunction(); 13 } 14 } else { 15 queue.fireNextFunction(); 16 } 17 } 18 }, 19 20 onInstanceCreate: function (queue) { 21 var handler = _(this.handleTimerComplete).bind(this); 22 this.subscriptions[queue.primaryKey()] = handler; 23 queue.on("timer_complete", handler); 24 }, 25 26 onInstanceDestroy: function (queue) { 27 this.renderNothing = true; 28 var subscription = this.subscriptions[queue.primaryKey()]; 29 if (subscription) { 30 queue.removeListener("timer_complete", subscription); 31 delete this.subscriptions[queue.primaryKey()]; 32 } 33 queue.stop(); 34 } 35 36 }); 37