<?xml version="1.0" encoding="UTF-8"?>
<!--
 -
 -  $Id$
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2018 OpenLink Software
 -
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -
-->
<v:page name="blog-home-page"
        xmlns:vm="http://www.openlinksw.com/vspx/ods/"
        xmlns:v="http://www.openlinksw.com/vspx/"
        style="index.xsl"
        doctype="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <vm:page>
    <vm:header>
      <vm:title>Related Applications</vm:title>
    </vm:header>
    <vm:pagewrapper>
      <v:variable name="wai_id" type="int" default="null" param-name="wai_id"/>

      <v:variable name="rel_mode" type="varchar" default="'REL/browse'"/>
    	<v:variable name="rel_id" type="any" default="null" />

      <vm:navigation on="settings"/>
      <vm:navigation1 on="services"/>
      <vm:rawheader caption="Related Applications"/>
      <vm:body>
	<vm:login redirect="index.vspx"/>
        <div class="box">
          <h3>Applications related to "<?V (select WAI_NAME from WA_INSTANCE where WAI_ID = self.wai_id) ?>"</h3>
          <vm:if test="self.rel_mode = 'REL/browse'">
            <?vsp
              if (0)
              {
            ?>
              <v:button name="rel_dButton" action="simple" value="Delete">
                <v:on-post>
                  <![CDATA[
                    delete from DB.DBA.WA_RELATED_APPS where RA_ID = get_keyword ('rel_id', self.vc_page.vc_event.ve_params) and RA_WAI_ID = self.wai_id;
                    self.vc_data_bind(e);
                  ]]>
                </v:on-post>
              </v:button>
            <?vsp
              }
            ?>
            <input type="hidden" name="rel_id" id="rel_id" value="" />
            <div style="padding: 0 0 0.5em 0;">
        		  <v:button name="rel_Back" value="''" action="simple" style="url" xhtml_class="img_button">
                <v:before-render>
                  <![CDATA[
                    control.ufl_value := '<img src="images/icons/go_16.png" border="0" /> Back to Applications';
                  ]]>
                </v:before-render>
       		      <v:on-post>
           			  self.vc_redirect ('services.vspx');
       		      </v:on-post>
        		  </v:button>
              <v:button name="rel_aButton" action="simple" style="url" value="''" xhtml_class="img_button">
                <v:before-render>
                  <![CDATA[
                    control.ufl_value := '<img src="images/icons/add_16.png" border="0" /> Add';
                  ]]>
                </v:before-render>
                <v:on-post>
                  <![CDATA[
                    self.rel_mode := 'REL/add';
                    self.rel_uri.ufl_value := null;
                    self.rel_label.ufl_value := null;

                    self.vc_data_bind(e);
                  ]]>
                </v:on-post>
              </v:button>
            </div>

      	    <v:data-set name="rel_ds"
      	                sql="select RA_ID, RA_URI, RA_LABEL from DB.DBA.WA_RELATED_APPS where RA_WAI_ID = :self.wai_id"
      		              scrollable="1"
      		              editable="1"
      		              nrows="0">

              <v:template name="rel_ds_header" type="simple" name-to-remove="table" set-to-remove="bottom">
	  <table class="listing" rules="groups">
	      <tr class="listing_header_row">
		  <th>Description</th>
		  <th>URI</th>
            		    <th width="50px">Action</th>
	      </tr>
                </table>
              </v:template>

              <v:template name="rel_ds_repeat" type="repeat" name-to-remove="" set-to-remove="">

                <v:template name="rel_ds_empty" type="if-not-exists" name-to-remove="table" set-to-remove="both">
                  <table>
                    <tr align="center">
                      <td colspan="3">No Related Applications</td>
                    </tr>
                  </table>
                </v:template>

                <v:template name="rel_ds_browse" type="browse" name-to-remove="table" set-to-remove="both">
                  <table>
        			      <tr class="<?V case when mod(control.te_ctr, 2) then 'listing_row_odd' else 'listing_row_even' end ?>">
                      <td nowrap="nowrap" width="50%">
                        <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('RA_LABEL')" format="%s" name="rel_ds_browse_l1"/>
			      </td>
                      <td nowrap="nowrap" width="50%">
                        <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('RA_URI')" format="%s" name="rel_ds_browse_l2"/>
			      </td>
                      <td nowrap="nowrap">
                        <v:button name="rel_eButton" action="simple" style="url" value="''" xhtml_class="img_button">
                          <v:before-render>
                            <![CDATA[
                              control.ufl_value := '<img src="images/icons/edit_16.png" border="0" alt="Edit Seek" title="Edit Seek"/> Edit';
                            ]]>
                          </v:before-render>
                          <v:on-post>
                            <![CDATA[
                              self.rel_mode := 'REL/edit';
                              self.rel_id := (control.vc_parent as vspx_row_template).te_column_value('RA_ID');
                              select RA_URI,
                                     RA_LABEL
                                into self.rel_uri.ufl_value,
                                     self.rel_label.ufl_value
                                from DB.DBA.WA_RELATED_APPS
                               where RA_ID = self.rel_id;

                              self.vc_data_bind(e);
                            ]]>
                          </v:on-post>
                        </v:button>
                        <span class="button pointer" onclick="javascript: if (confirm('Are you sure you want to delete this record?')) {$('rel_id').value = <?V (control as vspx_row_template).te_column_value('RA_ID') ?>; doPost('page_form', 'rel_dButton');}">
                          <img class="button" src="/ods/images/icons/trash_16.png"/> Delete
                        </span>
			      </td>
			  </tr>
                  </table>
		      </v:template>

		  </v:template>

      		    <v:template name="rel_ds_footer" type="simple" name-to-remove="table" set-to-remove="top">
                <table>
                </table>
		  </v:template>
	      </v:data-set>

          </vm:if>

          <vm:if test="self.rel_mode <> 'REL/browse'">
	  <div class="fm">
      				<table>
      				  <tr>
      				    <th width="100px">
      		          Description
      		        </th>
      		        <td>
                    <v:text name="rel_label" value="" xhtml_id="rel_label" xhtml_size="100" xhtml_class="_validate_" />
                  </td>
                </tr>
      				  <tr>
      				    <th>
      		          URI
      		        </th>
      		        <td>
                    <v:text name="rel_uri" value="" xhtml_id="rel_uri" xhtml_size="100" xhtml_class="_validate_" />
                  </td>
                </tr>
                <tr>
                  <td></td>
                  <td>
		  <br />
          		      <v:button name="rel_Cancel" value="Cancel" action="simple">
		      <v:on-post>
                        self.rel_mode := 'REL/browse';
                        self.vc_data_bind (e);
		      </v:on-post>
		  </v:button>
          		      <v:button name="rel_Save" value="--case when self.rel_mode = 'REL/add' then 'Add' else 'Update' end" action="simple" xhtml_onclick="return validateInputs(this);">
		      <v:on-post><![CDATA[
                        if (self.vc_is_valid = 0)
  return;

                        if (self.rel_mode = 'REL/add')
  {
                          insert into DB.DBA.WA_RELATED_APPS (RA_URI, RA_LABEL, RA_WAI_ID)
                            values (self.rel_uri.ufl_value, self.rel_label.ufl_value, self.wai_id);
  }
else
                        {
                          update DB.DBA.WA_RELATED_APPS
                             set RA_URI = self.rel_uri.ufl_value,
                                 RA_LABEL = self.rel_label.ufl_value
                           where RA_WAI_ID = self.wai_id
                             and RA_ID = self.rel_id;
                        }

                        self.rel_mode := 'REL/browse';
                        self.vc_data_bind (e);
]]></v:on-post>
		  </v:button>
                  </td>
                </tr>
              </table>
          </div>
          </vm:if>
        </div>
      </vm:body>
    </vm:pagewrapper>
  </vm:page>
</v:page>

