//  @import com.hedgehoglab.application.BaseApplication;

//  @import com.hedgehoglab.solomon.model.ContactsModel;
//  @import com.hedgehoglab.solomon.model.ResultsModel;
//	@import com.hedgehoglab.solomon.model.TaskTypeModel;
//  @import com.hedgehoglab.solomon.model.UsersModel;
//  @import com.hedgehoglab.solomon.model.StateMachineModel;
//  @import com.hedgehoglab.solomon.model.GenericTypesModel;

//  @import com.hedgehoglab.solomon.view.SearchContactsView;
//  @import com.hedgehoglab.solomon.view.TagFilterContactsView;
//  @import com.hedgehoglab.solomon.view.ContactsListView;
//  @import com.hedgehoglab.solomon.view.ContactsView;

//  @import com.hedgehoglab.solomon.view.ContactImportView;
//  @import com.hedgehoglab.solomon.view.ContactNewView;

//  @import com.hedgehoglab.solomon.view.DeleteDialogView;

//  @import com.hedgehoglab.solomon.view.ExportDialogView;
//  @import com.hedgehoglab.solomon.view.ContactDetailView;
//  @import com.hedgehoglab.solomon.view.ContactEditView;

//  @import com.hedgehoglab.solomon.view.ContactVEView;
//  @import com.hedgehoglab.solomon.view.ContactsSearchResultView;
//  @import com.hedgehoglab.solomon.view.ContactNTView;

//  @import com.hedgehoglab.solomon.service.ContactsService;
//  @import com.hedgehoglab.solomon.service.TagsService;
//  @import com.hedgehoglab.solomon.service.NotesService;
//  @import com.hedgehoglab.solomon.service.TasksService;
//  @import com.hedgehoglab.solomon.service.UsersService;
//	@import com.hedgehoglab.solomon.service.LicenceService;
	
//  @import com.hedgehoglab.solomon.controller.SearchContactsController;

//  @import com.hedgehoglab.solomon.controller.ContactsNewController;
//  @import com.hedgehoglab.solomon.controller.ContactsImportController;
//  @import com.hedgehoglab.solomon.controller.ContactsExportController;
//  @import com.hedgehoglab.solomon.controller.TagDialogController;
//  @import com.hedgehoglab.solomon.controller.DeleteDialogController;

//  @import com.hedgehoglab.solomon.controller.ContactDetailController;
//  @import com.hedgehoglab.solomon.controller.ContactEditController;

//  @import com.hedgehoglab.solomon.controller.ContactNTController;
//  @import com.hedgehoglab.solomon.controller.ContactVEController;


function ContactsIndexApplication(scope) {

    BaseApplication.call(this, scope);

    this.main = function(resource) {
		//  Services
		var _licence_service = new LicenceService({interval:10});
		
		var _contacts_service = new ContactsService({});
		var _tag_service = new TagsService({});
		var _notes_service = new NotesService({});
		var _tasks_service = new TasksService({});
		var _user_service = new UsersService({});
		
       //  Models
        var _current_contact = new ContactModel();

        var _contact_model = new ContactsModel();
        var _contacts_model = new ContactsModel();
        var _selected_contacts_model = new ContactsModel();
        var _results_model = new ResultsModel();
        var _users_model = new UsersModel();
        var _task_type_model = new TaskTypeModel();
        var _general_types_model=new GenericTypesModel();

        var _state_machine_model=new StateMachineModel();

        //  Views
        var _search_contacts_view = new SearchContactsView({element:$('.FindPanel')});
        var _tag_filter_view = new TagFilterContactsView({element:$('.FindPanel')});


        var _contacts_list_view = new ContactsListView({
            contacts_model:_contacts_model
            ,selected_contacts_model:_selected_contacts_model
            ,element:$('.contacts-pane')
            ,state_machine_model:_state_machine_model
        });

        var _ve_view=new ContactVEView({general_types_model:_general_types_model});
        var _nt_view=new ContactNTView({general_types_model:_general_types_model});

        var _contact_edit_view=new ContactEditView({element:$('.editing-pane'),
          general_types_model:_general_types_model});


        var _delete_dialog_view = new DeleteDialogView({element:null});

//        var _export_dialog_view = new ExportDialogView({element:null});



        var _contact_detail_view = new ContactDetailView({
          element:$('.editing-pane'),
          contact_model:_contacts_model,
          ve_view:_ve_view,
          nt_view:_nt_view,
          general_types_model:_general_types_model
        });
		
       var _search_result_view = new ContactsSearchResultView({element:$('.results-pane'),results_model:_results_model});

        var _contacts_import_view = new ContactImportView({element:$('.editing-pane'),action:$('#import_contacts_action')});

        var _contacts_new_view = new ContactNewView({element:$('.editing-pane'),action:$('#new-contact-action')});

        


        //  Controllers
        var _search_contacts_controller = new SearchContactsController({
            view:_search_contacts_view,
            tag_view:_tag_filter_view
           ,results_view:_search_result_view
            ,contacts_service:_contacts_service
            ,tag_service:_tag_service
			,licence_service:_licence_service
			
            ,contacts_model:_contacts_model
            ,results_model:_results_model
			,selected_contacts_model:_selected_contacts_model

            ,state_machine_model:_state_machine_model
            ,message_service:resource.message_service
        });

        var _delete_dialog_controller = new DeleteDialogController({
            delete_dialog_view:_delete_dialog_view
        });


        var _contact_VE_controller=new ContactVEController({
            model:_current_contact,
            view:_ve_view,
            general_types_model:_general_types_model,
            contacts_service:_contacts_service,
            user_service:_user_service,
            users_model:_users_model,
            notes_service:_notes_service,
            tag_service:_tag_service
        });

        var _contact_edit_controller=new ContactEditController({
            model:_current_contact,
            view:_contact_edit_view,
            general_types_model:_general_types_model,
            contacts_service:_contacts_service,
            user_service:_user_service,
            users_model:_users_model,
            notes_service:_notes_service
			,licence_service:_licence_service
        });


        var _contact_NT_controller=new ContactNTController({
            model:_current_contact,
            view:_nt_view,
            contacts_service:_contacts_service,
            user_service:_user_service,
            users_model:_users_model,
            notes_service:_notes_service,
            tasks_service:_tasks_service
        });

        var _contact_detail_controller = new ContactDetailController({
            contacts_list_view:_contacts_list_view,
            contact_detail_view:_contact_detail_view,
            contact_edit_view:_contact_edit_view,
            delete_dialog_view:_delete_dialog_view,
            contact_model:_contacts_model,
            contacts_model:_contacts_model,
            current_contact:_current_contact,
            users_model:_users_model,
            selected_contacts_model:_selected_contacts_model,
            task_type_model:_task_type_model,
            general_types_model:_general_types_model,
            notes_service:_notes_service,
            tasks_service:_tasks_service,
            user_service:_user_service,
			licence_service:_licence_service,
            tag_service:_tag_service,
            contacts_service:_contacts_service,
            contact_VE_controller:_contact_VE_controller,
            contact_NT_controller:_contact_NT_controller,
            contact_edit_controller:_contact_edit_controller,
            message_service:resource.message_service,
            delete_dialog_controller:_delete_dialog_controller,
			search_view:_search_contacts_view
			// search_contacts_view:_search_contacts_view
        });

        var _contacts_new_controller = new ContactsNewController({
            contact_new_view:_contacts_new_view,
            model:_current_contact,
            selected_contacts_model:_selected_contacts_model,
            contacts_service:_contacts_service
			,message_service:resource.message_service
			,licence_service:_licence_service
        });

		// //	FIXX!!!!!!
		//         var _export_dialog_controller = new ContactsExportController({
		//             // contacts_model:_contacts_model,
		//             //             selected_contacts_model:_selected_contacts_model,
		//             //             export_dialog_view:_export_dialog_view
		//         });
		var _contacts_import_controller = new ContactsImportController({
			contacts_model:_contacts_model,
            //selected_contacts_model:_selected_contacts_model,
            import_view:_contacts_import_view,
			message_service:resource.message_service,
			search_view:_search_contacts_view
			,licence_service:_licence_service
		});
    };
};

new ContactsIndexApplication({});
