Thursday 13 December 2012

Seperating transaction with :

Instead of eval( ) transactions can also separated with the help of sign ;

This has various advantages:

1. We can separate transactions in a simple way without using eval()

2. Separating operation transactions on same page before submit and after submit

3. Can set and get session on same page by separating operation transactions.


2. Separating transaction of form before submit and form after submit (operation transactions)

If form redirects to same page and further requires some processing.Then this post processing (i.e. further call to  some other module function,or setting some session value or any other calculation) can be simply carried out to same page by separating transaction of page before submit and page after submit is with the help of ;

Ex-  The page code "ShowChunkList" is something as:


import module namespace CHUNKS = "http://tbc.com/ManageChunks" at "ManageChunks.xqy";
import module namespace USERS = "http://tbc.com/ManageUsers" at "ManageUsers.xqy";
import module namespace BATCHES = "http://tbc.com/ManageBatches" at "ManageBatches.xqy";

declare variable $_User     := xdmp:get-current-user();
declare variable $_UserName := if (starts-with($_User, "COLOSSUS-")) then substring($_User,  10) else $_User;
declare variable $_UserType  := USERS:GetUserTypeByName($_UserName);

declare variable $_UserIsInTraining := USERS:GetIsUserInTraining( USERS:GetUserRecordFromName($_UserName) );
declare variable $_UserIsAnExpert := USERS:GetIsUserAnExpert( USERS:GetUserRecordFromName($_UserName) );
declare variable $_Mode := xdmp:get-request-field("MODE");
declare variable $_DarkBand := "#F1F0F5";
declare variable $_LightBand := "#E9F3F6";
declare variable $_RelatedDocumentColor := "#FFE4E1";

declare variable $_ChunkID := fn:normalize-space(if(xdmp:get-request-field("FindChunk", "")!="") then xdmp:get-request-field("FindChunk", "") else xdmp:get-request-field("ChunkID",""));


declare variable $_BatchFilename := xdmp:get-request-field("BatchFilename");

xdmp:set-response-content-type("text/html")

,



"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>"
,


<html>

<head>
</head>
<body>



          <form  action="ShowChunkList.xqy" method="post">
              <input type="hidden" id="EditedDivID" value="" name="EditedDiv"/>
              <input type="hidden" name="MODE" value="FindChunkList"/>
              <input type="hidden" name="FindChunk" value="{xdmp:get-request-field("FindChunk")}"/>
              <input type="hidden" name="Operation" value="EditDataBlock"/>
           
              <table style="margin:5px" border="0" cellpadding="5" cellspacing="3" width="99%">
               <tr valign="top">
                 <td width="50%">
                 {
                    CHUNKS:LOOP( $DivisionText )
                 }                  
                 </td>
                 <td width="50%">
                   <div id="DataDisplay_1" style="margin:5px;padding:4px;overflow:auto; height:800px">
                   {
                    (
                      $DataDisplayTable
                    ,
                      <input type="submit" value="Edit DataBlock"/>
                    )
                   }
                   </div>
                 </td>
             
               </tr>
       
             </table>
           
            </form>


/body>

</html>


******************************************************************************************
Now i would like to do some function call after submit .Therefore separate operation transaction in same page like this:

xquery version "1.0-ml";

(: ***** OPERATION TRANSACTIONS ***** :)

----------------------------------------------------------------operation after page submit
import module namespace CHUNKS = "http://tbc.com/ManageChunks" at "ManageChunks.xqy";
declare variable $_ID := xdmp:get-request-field("ID", "NONE");
declare variable $_Operation := xdmp:get-request-field("Operation", "NONE");

declare variable $_EditedData :=  xdmp:get-request-field("EditedDiv");

declare variable $_ExistingChunkID := fn:normalize-space(if(xdmp:get-request-field("FindChunk", "")!="") then xdmp:get-request-field("FindChunk", "") else ( ));

if ( $_Operation = "EditDataBlock")
then
  (
  CHUNKS:ChangeDataBlockAndDisplayTable($_ExistingChunkID, $_EditedData)
  ,
  xdmp:add-response-header("X-XSS-Protection", "0")
  )
else ( )

;
----------------------------------------------------------------operations before page submit
import module namespace CHUNKS = "http://tbc.com/ManageChunks" at "ManageChunks.xqy";
import module namespace USERS = "http://tbc.com/ManageUsers" at "ManageUsers.xqy";
import module namespace BATCHES = "http://tbc.com/ManageBatches" at "ManageBatches.xqy";

declare variable $_User     := xdmp:get-current-user();
declare variable $_UserName := if (starts-with($_User, "COLOSSUS-")) then substring($_User,  10) else $_User;
declare variable $_UserType  := USERS:GetUserTypeByName($_UserName);

declare variable $_UserIsInTraining := USERS:GetIsUserInTraining( USERS:GetUserRecordFromName($_UserName) );
declare variable $_UserIsAnExpert := USERS:GetIsUserAnExpert( USERS:GetUserRecordFromName($_UserName) );
declare variable $_Mode := xdmp:get-request-field("MODE");
declare variable $_DarkBand := "#F1F0F5";
declare variable $_LightBand := "#E9F3F6";
declare variable $_RelatedDocumentColor := "#FFE4E1";

declare variable $_ChunkID := fn:normalize-space(if(xdmp:get-request-field("FindChunk", "")!="") then xdmp:get-request-field("FindChunk", "") else xdmp:get-request-field("ChunkID",""));


declare variable $_BatchFilename := xdmp:get-request-field("BatchFilename");

xdmp:set-response-content-type("text/html")

,



"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>"
,
3. Set form request parameters on same page and then get anywhere on same page or another page within application.
 Bu using above approach let say we have a form that has input type="text".After submitting form  is redirecting to same page.Therefore we can set the session for the field value within same page by seperating ;. Therefore we can set and get session value for request parameters on same page with the help of ;

Note: We can set and get session value (i.e. not request parameters)at same page but to set and get the session for request parameter at same page,we have to set the session after submit (if redirects to same page) in separate transaction.

Ex- 

(: ***** PRESERVE SCROLL-TO VALUE ***** :)
try
{
let $ScrollTo := xdmp:get-request-field("ScrollTo", "NONE")
let $Dummy := xdmp:set-session-field("ScrollTo", $ScrollTo )
return
  ( )
}
catch($error)
{
  (: This will happen if the session has timed-out while the page is on-screen,
     taking the user back to the login screen :)
  xdmp:redirect-response( "Default.xqy" )
}


;

(: ***** REGISTER ADMIN USER (create user entry for administrator)  ***** :)

import module namespace USERS = "http://tbc.com/ManageUsers" at "ManageUsers.xqy";

let $User := xdmp:get-current-user()
return
  if ($User = "admin" or $User = "Admin" or $User = "administrator" or $User = "Administrator")
  then
    let $UserID := USERS:GetUserIDByName($User)
    return
      if ($UserID)
      then
        ( )
      else
        USERS:AddAdminUserRecord($User)
  else
    ( )


;
............................................


Here the ScrollTo value is passed by form from same page.








No comments:

Post a Comment