Created
March 25, 2011 18:57
-
-
Save rauhryan/887385 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(["./views/appView" ,"./collections/jobList","./models/job"], | |
function(app, Jobs, Job) { | |
var mainView = { | |
toggleButtons : function (){ | |
if(this.employee && this.task && this.equipment){ | |
$('#create-job').removeAttr('disabled').focus(); | |
return; | |
} | |
$('#create-job').attr('disabled',true); | |
} | |
,addEmployee : function(ev, ui){ | |
if(this.employee){ | |
$(ui.sender).sortable('cancel'); | |
this.toggleButtons(); | |
return; | |
} | |
this.employee = $(ui.item).data('backbone-view'); | |
this.toggleButtons(); | |
} | |
,removeEmployee : function(ev, ui) { | |
this.employee = undefined; | |
this.toggleButtons(); | |
} | |
,addEquipment : function(ev, ui){ | |
if(this.equipment){ | |
$(ui.sender).sortable('cancel'); | |
this.toggleButtons(); | |
return; | |
} | |
this.equipment = $(ui.item).data('backbone-view'); | |
this.toggleButtons(); | |
} | |
,removeEquipment : function(ev, ui) { | |
this.equipment = undefined; | |
this.toggleButtons(); | |
} | |
,addTask : function(ev, ui){ | |
if(this.task){ | |
$(ui.sender).sortable('cancel'); | |
this.toggleButtons(); | |
return; | |
} | |
this.task = $(ui.item).data('backbone-view'); | |
this.toggleButtons(); | |
} | |
,removeTask : function(ev, ui) { | |
this.task = undefined; | |
this.toggleButtons(); | |
} | |
,createJob : function (){ | |
var job = new Job({ | |
employee : this.employee.model.toJSON(), | |
task : this.task.model.toJSON(), | |
equipment: this.equipment.model.toJSON(), | |
order: Jobs.nextOrder() | |
}) | |
Jobs.add(job); | |
job.save(); | |
this.employee.remove(); | |
this.task.remove(); | |
this.equipment.remove(); | |
this.employee = undefined; | |
this.task = undefined; | |
this.equipment = undefined; | |
this.toggleButtons(); | |
} | |
} | |
return { | |
init: function () { | |
//wire up all the events | |
$('#create-job').click($.proxy(mainView.createJob, mainView)); | |
$('#task-drop-table tbody').sortable({ | |
placeholder: "task-placeholder", | |
//stop is fired when the element leaves | |
stop : $.proxy(mainView.removeTask, mainView), | |
//receive is fired when an element is drop in | |
receive : $.proxy(mainView.addTask, mainView), | |
items: 'tr', | |
connectWith:'.task-sortables' | |
}); | |
$('#equipment-drop-table tbody').sortable({ | |
placeholder: "equipment-placeholder", | |
//stop is fired when the element leaves | |
stop : $.proxy(mainView.removeEquipment, mainView), | |
//receive is fired when an element is drop in | |
receive : $.proxy(mainView.addEquipment, mainView), | |
items: 'tr', | |
connectWith:'.equipment-sortables' | |
}); | |
$('#employee-drop-table tbody').sortable({ | |
placeholder: "employee-placeholder", | |
//stop is fired when the element leaves | |
stop : $.proxy(mainView.removeEmployee, mainView), | |
//receive is fired when an element is drop in | |
receive : $.proxy(mainView.addEmployee, mainView), | |
items: 'tr', | |
connectWith:'.employee-sortables' | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment