<?xml version="1.0"?>
<!DOCTYPE ofscript SYSTEM "http://www.safedataco.com/dtd/webflow/ofscript.dtd">
<ofscript version="1.0" id="com.safedataco.Blog" name="Blog">
  
  <mapping>
    
    <svar name="subject" />
    
    <svar name="content" />
        
    <lvar name="postingdate" converter="com.safedataco.officeflow.client.custom.converters.DateTimeConverter" />
    
    <lvar name="modifieddate" converter="com.safedataco.officeflow.client.custom.converters.DateTimeConverter" />
    
    <ivar name="posteduser" />
    
    <svar name="comment" />
    
    <lvar name="commentdate" converter="com.safedataco.officeflow.client.custom.converters.DateTimeConverter" />
    
    <ivar name="datatype" />
    
    <svar name="posteduserfullname" />
    
  </mapping>

  <backup fragment="{subject}" />
  
  <menus>
  
    <menu name="Blog" rwreq="true">
      <item name="New post" action="newpost" />
    </menu>
  
  </menus>
  
  <actions>
  
    <action name="newpost">
    
      <clear variables="subject, content" />
    
      <form title="NEW POST">
      
        <input name="subject" label="Subject" />

        <textbox name="content" label="Content" />        
                        
      </form>

      <set name="datatype" value="0" />
      
      <set name="posteduser" operation="currentuserid" />
      
      <set name="posteduserfullname" operation="currentuserfullname" />
      
      <set name="postingdate" operation="todaydatetime" />
      
      <set name="modifieddate" value="{postingdate}" />
        
      <add>
        <field name="subject" />
        <field name="content" />
        <field name="datatype" />
        <field name="posteduser" />
        <field name="posteduserfullname" />
        <field name="postingdate" />
        <field name="modifieddate" />
      </add>
                
    </action>

    <action name="default">
      
      <form okbutton="false" cancelbutton="false">
        
        <set name="currentuser" operation="currentuserid" />
        
        <batch name="blogposts" defaultcolumnvar="postingdate" defaultsortdirection="descending" visiblerows="25" showpagebuttons="true">
          
          <column var="subject" />
          
          <column var="content" />
          
          <column var="postingdate" />
                                      
          <column var="posteduser" />
          
          <column var="posteduserfullname" />
          
          <query filter="(datatype=$1)">
            <param val="0"/>
          </query>          
          
          <label text="{subject}" />
          
          <separator />
          
          <label text="{content}" />
                              
          <separator />
          
          <align alignments="left, left, right, right" widths="200, *, 40, 40">
          
            <label text="{postingdate}" rendererclass="com.safedataco.officeflow.client.custom.columnrenderers.DateTimeColumnRenderer" />

            <label text="Posted by: {posteduserfullname}." />
            
            <button text="Edit" condition="{posteduser}=={currentuser}" action="editpost?postpk={blogposts}" />
            
            <button text="Reply" action="replypost?postpk={blogposts}" />
            
          </align>
                        
          <separator showline="true" />
          
        </batch>
        
      </form>

    </action>
    
    <action name="editpost">
    
      <retrieve pk="{postpk}">
        <field name="subject" />
        <field name="content" />
      </retrieve>
    
      <form title="EDIT POST">
      
        <input name="subject" label="Subject" />

        <textbox name="content" label="Content" />        
                        
      </form>
      
      <set name="modifieddate" operation="todaydatetime" />
      
      <change pk="{postpk}">
        <field name="subject" />
        <field name="content" />
        <field name="modifieddate" />
      </change>
                
    </action>
    
    <action name="replypost">
      
      <retrieve pk="{postpk}">
        <field name="subject" />
      </retrieve>    
      
      <clear variables="content" />
      
      <set name="subject" value="Re: {subject}" />
      
      <form title="REPLY TO POST">
      
        <input name="subject" label="Subject" />
        
        <textbox name="content" label="Content" />        
      
      </form>
      
      <set name="datatype" value="0" />
      
      <set name="posteduser" operation="currentuserid" />
      
      <set name="postingdate" operation="todaydatetime" />
      
      <set name="modifieddate" value="{postingdate}" />
      
      <add>
        <field name="subject" />
        <field name="content" />
        <field name="datatype" />
        <field name="posteduser" />
        <field name="postingdate" />
        <field name="modifieddate" />
      </add>
      
    </action>
  
  </actions>

</ofscript>