<!--
 -
 -  $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>Edit Interests</vm:title>
    </vm:header>
    <vm:pagewrapper banner="no">
      <vm:rawheader caption="Edit Interests"/>
      <v:variable name="res" type="any" default="null"/>
      <v:variable name="dta_mode" type="integer" default="0" param-name="mode" />
      <v:variable name="dta" type="any" default="null" />
      <vm:body>
      <script type="text/javascript">
  <![CDATA[
function retSelected (form)
{
              var i, ret, mode;

              mode = <?V self.dta_mode ?>;
  ret = '';
  for (i = 0; i < form.elements.length; i++)
    {
      var contr = form.elements[i];
      if (contr != null && contr.type == 'text' && (contr.id == 'c1' || contr.id == 'c2'))
        {
	  if (contr.id == 'c2')
	    ret = ret + ';' + contr.value + '\n';
	  else
            ret = ret + contr.value;
        }
    }
              if (mode == 0 && (opener == null || opener.e_int == null))
                return;
              if (mode == 2 && (opener == null || opener.e_int2 == null))
    return;
              if (mode == 0)
              {
  opener.e_int.value = ret;
                opener.interestsPrepare_11 ();
              }
              if (mode == 2)
              {
                opener.e_int2.value = ret;
                opener.interestsPrepare_21 ();
              }
  opener.focus ();
  close ();
}

]]>
</script>
	<vm:login redirect="index.vspx"/>
         <a href="#" style="text-decoration:none;" onclick="if (window.opener != null) { window.opener.focus(); window.close (); } return false;"><img title="Close" alt="Close" src="images/icons/close_16.png" border="0" hspace="3" />Close</a>
	 <v:form type="simple" method="POST" name="f1">
	   <v:on-init>
	     if (not self.vc_event.ve_is_post)
	       {
              declare tmp, params any;

              params := self.vc_event.ve_params;
              tmp := case when get_keyword ('mode', params, '0') = '0' then get_keyword ('e_int', params) else get_keyword ('e_int2', params) end;
              self.dta := (select vector_agg (vector (interest, label)) from DB.DBA.WA_USER_INTERESTS (txt) (interest varchar, label varchar) P where txt = tmp);
	       }
	   </v:on-init>
	   <table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
	     <tr valign='top'>
	       <td>
		 <h2>Interests</h2>
		 <table class="listing">
		   <tr class="listing_header_row">
		     <th>
		       URI
		     </th>
		     <th>
		       Label
		     </th>
		     <th>
		       Action
		     </th>
		   </tr>
		   <v:data-set nrows="-1" name="ds_int" data="--self.dta" meta="--null" scrollable="1" edit="1">
		     <v:column name="URI"/>
		     <v:template name="rt1" type="repeat">
		       <v:template name="ne1" type="if-not-exists">
			 <tr>
			   <td colspan="2">No interests defined</td>
			 </tr>
		       </v:template>
		       <v:template name="br1" type="browse">
			 <tr>
			   <td>
			     <v:text name="tx1" value="--(control.vc_parent as vspx_row_template).te_rowset[0]" xhtml_id="c1" xhtml_size="50">
			       <v:after-data-bind>
				 if (not e.ve_is_post)
				   return;

				 declare val, dta any;
				 val := get_keyword (control.vc_get_name (), e.ve_params, NULL);
				 if (val is null)
				   return;
				 dta := self.dta;
				 dta[(control.vc_parent as vspx_row_template).te_ctr][0] := val;
				 self.dta := dta;
				 control.ufl_value := val;
			       </v:after-data-bind>
			     </v:text>
			   </td>
			   <td>
			     <v:text name="tx2" value="--(control.vc_parent as vspx_row_template).te_rowset[1]" xhtml_id="c2">
			       <v:after-data-bind>
				 if (not e.ve_is_post)
				   return;

				 declare val, dta any;
				 val := get_keyword (control.vc_get_name (), e.ve_params, NULL);
				 if (val is null)
				   return;
				 dta := self.dta;
				 dta[(control.vc_parent as vspx_row_template).te_ctr][1] := val;
				 self.dta := dta;
				 control.ufl_value := val;
			       </v:after-data-bind>
			     </v:text>
			   </td>
			   <td>
			     <v:button action="simple" name="ds_int_delete" value="Remove">
			       <v:on-post><![CDATA[
				 declare tmp, newd any;
				 declare i, ix int;

                                 tmp := self.dta;
				 newd := make_array (length(tmp)-1,'any');
				 i := ix := 0;
				 foreach (any elm in tmp) do
				   {
				     if (i <> (control.vc_parent as vspx_row_template).te_ctr)
				       {
                                         newd[ix] := elm;
					 ix := ix + 1;
				       }
                                     i := i + 1;
				   }
				 self.dta := newd;
                                 self.ds_int.vc_data_bind (e);
				]]></v:on-post>
			     </v:button>
			   </td>
			 </tr>
		       </v:template>
		     </v:template>
		   </v:data-set>
		   <tr>
		     <td>
		       <v:text name="tx3" value="" xhtml_size="50" error-glyph="*">
			 <v:validator test="length" min="1" max="10000" message="URI can not be empty"/>
		       </v:text>
		     </td>
		     <td>
		       <v:text name="tx4" value=""/>
		     </td>
		     <td>
		       <v:button action="simple" name="bt1" value="Add">
			       <v:on-post><![CDATA[
				 declare tmp, newd any;
				 declare i, ix int;

				 if (not self.vc_is_valid)
				   return;

				 tmp := self.dta;
				 tmp := vector_concat (tmp, vector (vector (self.tx3.ufl_value, self.tx4.ufl_value)));
				 self.dta := tmp;
				 self.ds_int.vc_data_bind (e);
				 self.tx3.ufl_value := '';
				 self.tx4.ufl_value := '';
				]]></v:on-post>
		       </v:button>
		     </td>
		   </tr>
		   <tr>
		     <td colspan="3">
		       <input type="button" name="ret_mail" value="Save" onclick="javascript: retSelected (this.form)"/>
		     </td>
		   </tr>
		 </table>
	       </td>
	     </tr>
	   </table>
	 </v:form>
      </vm:body>
    </vm:pagewrapper>
  </vm:page>
</v:page>

