<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
		<record id="view_phase_project_form1" model="ir.ui.view">
            <field name="name">phase.project.form1</field>
            <field name="model">project.project</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="project.edit_project"/>
            <field name="arch" type="xml">
               	<xpath expr="//page[@string='Tasks Stages']" position="after">
                   	<page string="Messages" groups="base.group_extended">
                   		<field name="message_ids" nolabel="1" colspan="4">
                   			<tree editable="1" string="Messages">
		                     	<field name="message" attrs="{'readonly':[('from_id', '!=', uid)]}"/>
		                     	<field name="from_id"/>
		                     	<field name="to_id" attrs="{'readonly':[('from_id', '!=', uid)]}"/>
                   			</tree>
                   			<form>
                   				<group attrs="{'readonly':[('from_id', '!=', uid)]}">
	                   				<field name="from_id"/>
			                        <field name="to_id"/>
			                        <newline/>
			                        <separator colspan="4" string="Message"/>
			                     	<field nolabel="1" name="message" colspan="4"/>
		                     	</group>
                   			</form>
                   		</field>
                   	</page>
               	</xpath>
            </field>
       	</record>

       	 <record id="view_project_message_form" model="ir.ui.view">
            <field name="name">project.messages.form</field>
            <field name="model">project.messages</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Messages">
                	<group attrs="{'readonly':[('from_id', '!=', uid)]}">
                        <field name="project_id" select="1" domain="[('user_id','=',uid)]"/>
                        <newline/>
                        <field name="from_id" select="1"/>
                        <field name="to_id" select="1"/>
                        <newline/>
                        <separator colspan="4" string="Message"/>
                     	<field name="message" colspan="4" nolabel="1"/>
                     </group>
                </form>
            </field>
       </record>

		<record id="view_project_message_tree" model="ir.ui.view">
            <field name="name">project.messages.tree</field>
            <field name="model">project.messages</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Messages">
                        <field name="project_id"/>
                        <field name="from_id"/>
                        <field name="to_id"/>
                </tree>
            </field>
       	</record>

       	<record id="view_project_messages_search" model="ir.ui.view">
           <field name="name">project.messages.search</field>
           <field name="model">project.messages</field>
           <field name="type">search</field>
           <field name="arch" type="xml">
               <search string="Communication Messages">
               		<group>
               			<field name="project_id"/>
                        <field name="from_id"/>
                        <field name="to_id"/>
                        <field name="message"/>
               		</group>
               		<newline/>
                    <group expand="0" string="Group By..." colspan="4" col="20">
                        <filter string="Message To" icon="terp-personal" domain="[]" context="{'group_by':'to_id'}"/>
                        <filter string="Message From" icon="terp-personal" domain="[]" context="{'group_by':'from_id'}"/>
                        <separator orientation="vertical"/>
                    	<filter string="Project" icon="terp-folder-blue" domain="[]" context="{'group_by':'project_id'}"/>
                    </group>
               </search>
           </field>
        </record>

       	<record id="messages_form" model="ir.actions.act_window">
            <field name="name">Communication Messages</field>
            <field name="res_model">project.messages</field>
            <field name="view_type">form</field>
            <field name="search_view_id" ref="view_project_messages_search"/>
            <field name="context">{"search_default_to_id":uid}</field>
            <field name="view_id" ref="view_project_message_tree"/>
			<field name="help">An in-project messagery system permits an efficient and trackable communication between project members. The messages are kept in the system and can then be used for post-analysis.</field>
        </record>

        <act_window context="{'search_default_project_id': [active_id]}" id="act_project_messages" name="Messages" res_model="project.messages" src_model="project.project"/>

         <!--Actions for deshboard -->

        <record id="action_view_project_editable_messages_tree" model="ir.actions.act_window">
            <field name="name">Messages</field>
            <field name="res_model">project.messages</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="project_messages.view_project_message_tree"/>
       </record>
       <menuitem action="messages_form" id="menu_messages_form" parent="project.menu_project_management"/>
     </data>
</openerp>
