//  @import com.hedgehoglab.application.view.BaseView;
//	@import com.hedgehoglab.solomon.view.TaskListView;
//	@import com.hedgehoglab.solomon.helper.UserHelper;

//	@import com.hedgehoglab.solomon.helper.TaskViewHelper;
//	@import com.hedgehoglab.solomon.helper.NoteViewHelper;
//	@import com.hedgehoglab.solomon.helper.DealsHelper;
					
function ContactNTView(scope){
	BaseView.call(this,scope);
	var _this = this;
	var _helpers=new _this.generate_helpers(this,[ContactViewHelper,TagHelper]);

	ContactViewHelper.call(this,scope);
	UserHelper.call(this,scope);
	
	TaskViewHelper.call(this,scope);
	NoteViewHelper.call(this,scope);
	
	DealsHelper.call(this,scope);
	var _tasks = null;	
	var _users = null;
	var _deals = null;
  

  this.setElement=function(element){
      scope.element=element;
  };
  
  this.get_users=function()
  {
    return _users;
  };
  
  
	//	Delegate methods required by note behaviour
	this.get_note_template_name=function(){
		return 'contact_note';
	};
	
	this.get_note_holder_template_name=function(){
		return 'contact_note_holder';
	};
	
	
	
	
	this.render = function(model,length){
   		var t=scope.element;
		var flag=false;
		var s=null;
		

		// var _view={};
		// var _view2={};

		// ContactViewHelper.call(_view,scope);

		// $.extend(_view,_this);
		// _this.set_users(model.users);
		// _users = model.users;
		_model=$.extend(model,scope.general_types_model.get_types());
		_this.set_users(model.users);
		_this.set_deals(model.deals);
		
		_this.render_template_with_view('contacts/ContactNoteTask',model,_this,function(contacts_nt_markup){
			$(scope.element).html(contacts_nt_markup);

			//Create the tab pane
			new TabPane({
			element:$(scope.element),
			tabs:'div.Tabs ul li',
			pane:'div.contact-tab-panel',
			current:'current',
			hide:'hide'
			});

			//	Show more ?
			// if(model.tasks!=null){
			// 	if(model.tasks.length<_model.pages.tasks){
			// 		$('#show_me_more_notes',ff).parent().parent().parent().hide();
			// 	}
			// }else{
			// 	$('#show_me_more_notes',ff).parent().parent().parent().hide();
			// }
		
			/**
			*	Render Tasks
			*/
			var contact_task_list=$('#contact-tasks-list',scope.element);
			_this.task_behaviour(model,contact_task_list,_this);
			
			//	Overide on_add_note_clicked to add model data for deal and contact
			_this.on_add_task_clicked=function(e){
				e.task.contact=""+model.contact.id;
				e.task.deal=$("#add-task-deal",scope.element).val();
				_this.raise_event('on_add_new_task',e);
			};
			
			var contact_notes_list=$('#contact-notes-list',scope.element);
			_this.note_behaviour(model,contact_notes_list,_this);
			
			//	Overide on_add_note_clicked to add model data for deal and contact
			_this.on_add_note_clicked=function(e){
				e.contact=""+model.contact.id;
				e.deal=$("#add-note-deal",scope.element).val();
				_this.raise_event('on_add_note_clicked',e);
			};
		});
	};
};