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 this.subscriptions[queue.primaryKey()] = MBX.EventHandler.subscribe(queue, "timer_complete", this.handleTimerComplete.bind(this), { 22 defer: true 23 }); 24 }, 25 26 onInstanceDestroy: function (queue) { 27 this.renderNothing = true; 28 var subscription = this.subscriptions[queue.primaryKey()]; 29 if (subscription) { 30 MBX.EventHandler.unsubscribe(subscription); 31 delete this.subscriptions[queue.primaryKey()]; 32 } 33 queue.stop(); 34 } 35 36 }); 37