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

/**
 *
 * @param scope
 */
function NewTaskController(scope){
    var _visible=false;
    var _current_user=null;

    scope.title_view.subscribe_to('on_new_task_clicked',function(e){
        if(!_visible){
            _visible=true;
            scope.task_list_service.empty_task(function(e){
                e={task:e,current_user:_current_user};
                scope.new_task_view.render_view(e,function(f){
                    f.show();
                });
            });
        }
        //  Get a new task from the service, then pass it to the view
    });

    scope.new_task_view.subscribe_to('on_task_cancel',function(e){
		//var task = $.extend({},e.task);
        e.event.hide();
        _visible=false;
    });

    scope.new_task_view.subscribe_to('on_task_save',function(e){
        var d=Date.parse(e.task.dueOn).toString("yyyy-MM-ddTHH:mm:ssZ");
        e.task.dueOn=d;
        var task = $.extend({},e.task);
        scope.task_list_service.add_task(task,function(ee){
            e.event.hide();
            scope.task_filter_model.model();
        });


        //TODO Refresh task list model
    });
	
	/** Get IS0 8601 combined date and time from a Date Object */
	function formatDate(date){
//	var year = date.getFullYear(),
//	month = date.getMonth()+1,
//	dayOfMonth = date.getDate(),
//	hrs = date.getHours(),
//	min = date.getMinutes(),
//	sec = date.getSeconds();
	//return year + '-' + month + '-' + dayOfMonth + 'T'+hrs+':'+min+':'+sec+'Z';
      return date;  
    };


    scope.user_service.get_current_user(function(e){
        _current_user=e;
    });

};