database/model/triggers/AD_WINDOW_TRG.xml
author Antonio Moreno <antonio.moreno@openbravo.com>
Tue, 22 Apr 2008 13:22:11 +0000
changeset 735 daced7e311c9
parent 367 b3c089243e73
child 737 935386ff0f30
permissions -rw-r--r--
Structure after exporting from PostgreSQL with new dbsourcemanager
<?xml version="1.0"?>
  <database name="TRIGGER AD_WINDOW_TRG">
    <trigger name="AD_WINDOW_TRG" table="AD_WINDOW" fires="after" insert="true" update="true" delete="false" foreach="row">
      <body><![CDATA[





    /*************************************************************************
    * The contents of this file are subject to the Compiere License
    * Version 2.5.0 ("License"); You may not use this file except in
    * compliance with the License. You may obtain a copy of the License at
    * http://www.compiere.org/license.html
    * Software distributed under the License is distributed on an
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
    * implied. See the License for the specific language governing rights
    * and limitations under the License.
    * The Original Code is  Compiere  ERP &  Business Solution
    * The Initial Developer of the Original Code is Jorg Janke  and ComPiere,
    Inc.
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
    * All Rights Reserved.
    * Contributor(s): Openbravo SL
    * Contributions are Copyright (C) 1999-2005 Openbravo, S.L
    *************************************************************************
    * $Id: AD_Window_Trg.sql,v 1.2 2002/08/26 05:23:32 jjanke Exp $
    ***
    * Title: Window Changes
    * Description:
    *   - Transaltion
    *   - Sync Name (Workflow, Menu)
    *   - Active State (Menu)
    ************************************************************************/
    BEGIN
    -- Insert AD_Window Trigger
    --  for Translation
    --  Access
    IF INSERTING
    THEN
    --  Create Translation Row
  INSERT
  INTO AD_Window_Trl
    (
      AD_Window_ID, AD_Language, AD_Client_ID,
      AD_Org_ID, IsActive, Created,
      CreatedBy, Updated, UpdatedBy,
      Name, Description, Help,
      IsTranslated
    )
  SELECT :new.AD_Window_ID,
    AD_Language, :new.AD_Client_ID, :new.AD_Org_ID,
    :new.IsActive, :new.Created, :new.CreatedBy,
    :new.Updated, :new.UpdatedBy, :new.Name,
    :new.Description, :new.Help, 'N'
  FROM AD_Language
  WHERE IsActive='Y'
    AND IsSystemLanguage='Y';
  -- Access for all
  INSERT
  INTO AD_Window_Access
    (
      AD_Window_ID, AD_Role_ID, AD_Client_ID,
      AD_Org_ID, IsActive, Created,
      CreatedBy, Updated, UpdatedBy,
      IsReadWrite
    )
  SELECT DISTINCT :new.AD_Window_ID,
    r.AD_Role_ID, r.AD_CLIENT_ID, r.AD_ORG_ID,
     'Y', now(), 0,
    now(), 0,  'Y'
  FROM AD_Role r
   WHERE isManual='N';
 END IF;
 -- Inserting
 -- AD_Window update trigger
 --  synchronize name,...
 IF UPDATING THEN
  IF(COALESCE(:old.Name, '.') <> COALESCE(:NEW.Name, '.')
  OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')
  OR COALESCE(:old.Help, '.') <> COALESCE(:NEW.Help, '.'))
 THEN
    IF (COALESCE(:old.IsActive, '.') <> COALESCE(:NEW.IsActive, '.')) THEN
        -- Update Menu
        UPDATE AD_Menu
          SET IsActive=:new.IsActive,
          Name=:new.Name,
          Description=:new.Description
        WHERE AD_Window_ID=:new.AD_Window_ID;
        -- Update Workflow
        UPDATE AD_WF_Node
          SET IsActive=:new.IsActive
        WHERE AD_Window_ID=:new.AD_Window_ID;
        UPDATE AD_WF_Node
          SET Name=:new.Name,
          Description=:new.Description,
          Help=:new.Help
        WHERE AD_Window_ID=:new.AD_Window_ID
          AND IsCentrallyMaintained='Y';
    END IF;
    
    -- Translation
    UPDATE AD_Window_Trl
      SET IsTranslated='N',
      Updated=now()
    WHERE AD_Window_ID=:new.AD_Window_ID;
  END IF;
 END IF;
-- Updating
END AD_WINDOW_TRG
]]></body>
    </trigger>
  </database>