//  @import com.hedgehoglab.application.controller.BaseController;
//  @import com.hedgehoglab.events.Thread;

/**
 *
 * @param scope
 */
function TaskFilterController(scope){
	var _this=this;
	var _update_task_list_thread=null;
  var _task_list_copy={task:[]};
    
  scope.task_filter_model.subscribe_to('user_changed',function(e){
    _this.update_task_list_model(e);
  });
	
	scope.task_filter_model.subscribe_to('category_changed',function(e){
		_this.update_task_list_model(e);
	});
	
	scope.task_filter_model.subscribe_to('date_changed',function(e){
		_this.update_task_list_model(e);
	});

  scope.task_filter_model.subscribe_to('model_changed',function(e){
		_this.update_task_list_model(e);
	});

  this.update_task_list_model=function(e){
    if(_update_task_list_thread) _update_task_list_thread.update(e);
    update_tasks(e);
	};

  function update_tasks(f){

    scope.task_list_service.get_tasks_for_user_with_filter(f.user,f.category,f.dateFrom,f.dateTo,false,function(data){
      scope.task_list_model.model(data);
    },true);
    
    scope.task_list_service.get_tasks_for_user_with_filter(f.user,f.category,f.dateFrom,f.dateTo,true,function(data){
      scope.completed_task_list_model.model(data);
    },true);
  };

//  _update_task_list_thread=new Thread(function(f){
//        //update_tasks(f);
//  });

//  _update_task_list_thread.start(3000);

};