//-- copyright
// Copyright (C)2013-2014 the OpenProject Foundation (OPF)
// Copyright (C)2011 Stephan Eckardt, Tim Felgentreff, Marnen Laibow-Koser, Sandro Munda
// Copyright (C)2010-2011 friflaj
// Copyright (C)2010 Maxime Guilbot, Andrew Vit, Joakim Kolsjö, ibussieres, Daniel Passos, Jason Vasquez, jpic, Emiliano Heyns
// Copyright (C)2009-2010 Mark Maglana
// Copyright (C)2009 Joe Heck, Nate Lowrie
// The copyright follows:
// Copyright (C) 2010-2011 - Emiliano Heyns, Mark Maglana, friflaj
// Copyright (C) 2011 - Jens Ulferts, Gregor Schmidt - Finn GmbH - Berlin, Germany
// See doc/COPYRIGHT.rdoc for more details.
RB.Taskboard=function(e){return RB.Object.create(RB.Model,{initialize:function(t){var i=this;this.$=e(t),this.el=t,this.$.data("this",this),this.colWidthUnit=e(".swimlane").width(),this.defaultColWidth=1,this.loadColWidthPreference(),this.updateColWidths(),e("#col_width input").keyup(function(e){13===e.which&&i.updateColWidths()}),this.initializeTasks(),this.initializeImpediments(),this.initializeNewButtons(),this.initializeSortables()},initializeNewButtons:function(){this.$.find("#tasks .add_new.clickable").click(this.handleAddNewTaskClick),this.$.find("#impediments .add_new.clickable").click(this.handleAddNewImpedimentClick)},initializeSortables:function(){this.$.find("#impediments .list").sortable({placeholder:"placeholder",start:this.dragStart,stop:this.dragStop,update:this.dragComplete,cancel:".prevent_edit"}).sortable("option","connectWith","#impediments .list"),e("#impediments .list").disableSelection();var t,i,n=this;t=this.$.find("#tasks .list"),i=function(){e(t.splice(0,50)).sortable({placeholder:"placeholder",start:n.dragStart,stop:n.dragStop,update:n.dragComplete,cancel:".prevent_edit"}).sortable("option","connectWith","#tasks .list"),e("#tasks .list").disableSelection(),t.length>0&&setTimeout(i,10)},i()},initializeTasks:function(){this.$.find(".task").each(function(){RB.Factory.initialize(RB.Task,this)})},initializeImpediments:function(){this.$.find(".impediment").each(function(){RB.Factory.initialize(RB.Impediment,this)})},dragComplete:function(e,t){var i=null===t.sender;i&&t.item.data("this").saveDragResult()},dragStart:function(e,t){t.item.addClass("dragging")},dragStop:function(t,i){i.item.removeClass("dragging"),e.browser.msie&&e.browser.version<=7&&i.item.css("z-index",0)},handleAddNewImpedimentClick:function(){var t=e(this).parents("tr").first();e("#taskboard").data("this").newImpediment(t)},handleAddNewTaskClick:function(){var t=e(this).parents("tr").first();e("#taskboard").data("this").newTask(t)},loadColWidthPreference:function(){var t=RB.UserPreferences.get("taskboardColWidth");(null===t||void 0===t)&&(t=this.defaultColWidth,RB.UserPreferences.set("taskboardColWidth",t)),e("#col_width input").val(t)},newImpediment:function(t){var i,n;i=e("#impediment_template").children().first().clone(),t.find(".list").first().prepend(i),n=RB.Factory.initialize(RB.Impediment,i),n.edit()},newTask:function(t){var i,n;i=e("#task_template").children().first().clone(),t.find(".list").first().prepend(i),n=RB.Factory.initialize(RB.Task,i),n.edit()},updateColWidths:function(){var t=parseInt(e("#col_width input").val(),10);(isNaN(t)||0>=t)&&(t=this.defaultColWidth),e("#col_width input").val(t),RB.UserPreferences.set("taskboardColWidth",t),e(".swimlane").width(this.colWidthUnit*t).css("min-width",this.colWidthUnit*t)}})}(jQuery);