src-db/database/model/triggers/AD_WINDOW_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 785 8dba91261590
child 1615 f4373ee564cc
permissions -rw-r--r--
Merge r2.5x intro trunk
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER AD_WINDOW_TRG">
adrian@94
     3
    <trigger name="AD_WINDOW_TRG" table="AD_WINDOW" fires="after" insert="true" update="true" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
juanpablo@771
     5
    /*************************************************************************
juanpablo@771
     6
    * The contents of this file are subject to the Compiere Public
juanpablo@771
     7
    * License 1.1 ("License"); You may not use this file except in
juanpablo@771
     8
    * compliance with the License. You may obtain a copy of the License in
juanpablo@771
     9
    * the legal folder of your Openbravo installation.
adrian@94
    10
    * Software distributed under the License is distributed on an
adrian@94
    11
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
adrian@94
    12
    * implied. See the License for the specific language governing rights
adrian@94
    13
    * and limitations under the License.
juanpablo@778
    14
    * The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    15
    * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
adrian@94
    16
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
adrian@94
    17
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
adrian@94
    18
    * All Rights Reserved.
adrian@94
    19
    * Contributor(s): Openbravo SL
juanpablo@785
    20
    * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@771
    21
    *
juanpablo@771
    22
    * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    23
    * file and version.
adrian@94
    24
    *************************************************************************
adrian@94
    25
    * $Id: AD_Window_Trg.sql,v 1.2 2002/08/26 05:23:32 jjanke Exp $
adrian@94
    26
    ***
adrian@94
    27
    * Title: Window Changes
adrian@94
    28
    * Description:
adrian@94
    29
    *   - Transaltion
adrian@94
    30
    *   - Sync Name (Workflow, Menu)
adrian@94
    31
    *   - Active State (Menu)
adrian@94
    32
    ************************************************************************/
adrian@94
    33
    BEGIN
adrian@94
    34
    -- Insert AD_Window Trigger
adrian@94
    35
    --  for Translation
adrian@94
    36
    --  Access
adrian@94
    37
    IF INSERTING
adrian@94
    38
    THEN
adrian@94
    39
    --  Create Translation Row
adrian@94
    40
  INSERT
adrian@94
    41
  INTO AD_Window_Trl
adrian@94
    42
    (
juanpablo@1605
    43
      AD_Window_Trl_ID, AD_Window_ID, AD_Language, AD_Client_ID,
adrian@94
    44
      AD_Org_ID, IsActive, Created,
adrian@94
    45
      CreatedBy, Updated, UpdatedBy,
adrian@94
    46
      Name, Description, Help,
adrian@94
    47
      IsTranslated
adrian@94
    48
    )
juanpablo@1605
    49
  SELECT get_uuid(), :new.AD_Window_ID,
adrian@94
    50
    AD_Language, :new.AD_Client_ID, :new.AD_Org_ID,
adrian@94
    51
    :new.IsActive, :new.Created, :new.CreatedBy,
adrian@94
    52
    :new.Updated, :new.UpdatedBy, :new.Name,
adrian@94
    53
    :new.Description, :new.Help, 'N'
adrian@94
    54
  FROM AD_Language
adrian@94
    55
  WHERE IsActive='Y'
adrian@94
    56
    AND IsSystemLanguage='Y';
adrian@94
    57
  -- Access for all
adrian@94
    58
  INSERT
adrian@94
    59
  INTO AD_Window_Access
adrian@94
    60
    (
adrian@94
    61
      AD_Window_ID, AD_Role_ID, AD_Client_ID,
adrian@94
    62
      AD_Org_ID, IsActive, Created,
adrian@94
    63
      CreatedBy, Updated, UpdatedBy,
adrian@94
    64
      IsReadWrite
adrian@94
    65
    )
adrian@94
    66
  SELECT DISTINCT :new.AD_Window_ID,
adrian@94
    67
    r.AD_Role_ID, r.AD_CLIENT_ID, r.AD_ORG_ID,
juanpablo@1605
    68
     'Y', now(), '0',
juanpablo@1605
    69
    now(), '0',  'Y'
adrian@94
    70
  FROM AD_Role r
adrian@94
    71
   WHERE isManual='N';
adrian@94
    72
 END IF;
adrian@94
    73
 -- Inserting
adrian@94
    74
 -- AD_Window update trigger
adrian@94
    75
 --  synchronize name,...
adrian@94
    76
 IF UPDATING THEN
gorkaion@239
    77
  IF(COALESCE(:old.Name, '.') <> COALESCE(:NEW.Name, '.')
gorkaion@239
    78
  OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')
gorka@367
    79
  OR COALESCE(:old.Help, '.') <> COALESCE(:NEW.Help, '.'))
adrian@94
    80
 THEN
gorka@367
    81
    IF (COALESCE(:old.IsActive, '.') <> COALESCE(:NEW.IsActive, '.')) THEN
gorka@367
    82
        -- Update Menu
gorka@367
    83
        UPDATE AD_Menu
gorka@367
    84
          SET IsActive=:new.IsActive,
gorka@367
    85
          Name=:new.Name,
gorka@367
    86
          Description=:new.Description
gorka@367
    87
        WHERE AD_Window_ID=:new.AD_Window_ID;
gorka@367
    88
        -- Update Workflow
gorka@367
    89
        UPDATE AD_WF_Node
gorka@367
    90
          SET IsActive=:new.IsActive
gorka@367
    91
        WHERE AD_Window_ID=:new.AD_Window_ID;
gorka@367
    92
        UPDATE AD_WF_Node
gorka@367
    93
          SET Name=:new.Name,
gorka@367
    94
          Description=:new.Description,
gorka@367
    95
          Help=:new.Help
gorka@367
    96
        WHERE AD_Window_ID=:new.AD_Window_ID
gorka@367
    97
          AND IsCentrallyMaintained='Y';
gorka@367
    98
    END IF;
antonio@737
    99
adrian@94
   100
    -- Translation
adrian@94
   101
    UPDATE AD_Window_Trl
adrian@94
   102
      SET IsTranslated='N',
antonio@735
   103
      Updated=now()
adrian@94
   104
    WHERE AD_Window_ID=:new.AD_Window_ID;
adrian@94
   105
  END IF;
adrian@94
   106
 END IF;
adrian@94
   107
-- Updating
antonio@735
   108
END AD_WINDOW_TRG
gorkaion@239
   109
]]></body>
adrian@94
   110
    </trigger>
adrian@94
   111
  </database>