Revision: 1087
Author:
tbc...@gmail.com
Date: Sat Jun 29 13:19:41 2013
Log: Acts and functions on Web page @mhk_families
http://code.google.com/p/mhk/source/detail?r=1087
Modified:
/branches/mhk_families/idb/etc/template/new/create_source.vm
=======================================
--- /branches/mhk_families/idb/etc/template/new/create_source.vm Sat Jun 29
09:45:30 2013
+++ /branches/mhk_families/idb/etc/template/new/create_source.vm Sat Jun 29
13:19:41 2013
@@ -9,37 +9,57 @@
var count_persons=1;
var count_relations=1;
var count_attributes=1;
+ var count_acts=1;
+ var count_functions=1;
var source=new Object();
var persons=new Array();
var relations=new Array();
var attributes=new Array();
+ var acts=new Array();
+ var functions=new Array();
function refreshSelects(){
##actualizar selects
document.getElementById("attribute_select").options.length = 0;
document.getElementById("relation_origin_select").options.length = 0;
document.getElementById("relation_destination_select").options.length =
0;
+ document.getElementById("function_act_select").options.length = 0;
+ document.getElementById("function_origin_select").options.length = 0;
var attribute_select=document.getElementById("attribute_select");
var
relation_origin_select=document.getElementById("relation_origin_select");
var
relation_destination_select=document.getElementById("relation_destination_select");
+ var function_act_select=document.getElementById("function_act_select");
+ var
function_origin_select=document.getElementById("function_origin_select");
for (var i=0;i<persons.length;i++){
var option=document.createElement("option");
option.text=persons[i].id;
attribute_select.add(option,null);
+
option=document.createElement("option");
option.text=persons[i].id;
relation_origin_select.add(option,null);
+
option=document.createElement("option");
option.text=persons[i].id;
relation_destination_select.add(option,null);
+
+ option=document.createElement("option");
+ option.text=persons[i].id;
+ function_origin_select.add(option,null);
+ }
+
+ for (var i=0;i<acts.length;i++){
+ option=document.createElement("option");
+ option.text=acts[i].id;
+ function_act_select.add(option,null);
}
}
function removePerson(row){
- var box=confirm("Deleting this person will remove all attributes and
relations associated! Are you sure you want to continue?");
+ var box=confirm("Deleting this person will remove all attributes,
relations and functions associated. Are you sure you want to continue?");
if (box==false){
return;
@@ -96,6 +116,25 @@
if(attributes[j].person_id==id){
attributes.splice(j,1);
}
+ }
+
+ ##remove functions from table
+ size=document.getElementById('functions_table').rows.length;
+ rows=document.getElementById('functions_table').rows;
+ reduce_lines=0;
+ for (var j=1;j<size-reduce_lines;j++){
+ if(rows[j].cells[4].innerHTML==id){
+ document.getElementById('functions_table').deleteRow(j);
+ reduce_lines++;
+ j--;
+ }
+ }
+
+ ##remove functions from this person from array
+ for (var j=0;j<functions.length;j++){
+ if(functions[j].origin==id){
+ functions.splice(j,1);
+ }
}
refreshSelects();
@@ -130,6 +169,69 @@
attributes.splice(j,1);
break;
}
+ }
+ }
+
+ function removeAct(row){
+
+ var box=confirm("Deleting this act will remove all functions associated.
Are you sure you want to continue?");
+
+ if (box==false){
+ return;
+ }
+
+
+ ##get act id
+ var i=row.parentNode.parentNode.rowIndex;
+ var id=document.getElementById('acts_table').rows[i].cells[0].innerHTML;
+
+ ##remove act from table
+ document.getElementById('acts_table').deleteRow(i);
+
+ ##remove act from array
+ for (var j=0;j<acts.length;j++){
+ if(acts[j].id==id){
+ acts.splice(j,1);
+ break;
+ }
+ }
+
+ ##remove functions from table
+ size=document.getElementById('functions_table').rows.length;
+ rows=document.getElementById('functions_table').rows;
+ reduce_lines=0;
+ for (var j=1;j<size-reduce_lines;j++){
+ if(rows[j].cells[4].innerHTML==id){
+ document.getElementById('functions_table').deleteRow(j);
+ reduce_lines++;
+ j--;
+ }
+ }
+
+ ##remove functions from this person from array
+ for (var j=0;j<functions.length;j++){
+ if(functions[j].act_id==id){
+ functions.splice(j,1);
+ }
+ }
+
+ refreshSelects();
+ }
+
+ function removeFunc(row){
+ ##get function id
+ var i=row.parentNode.parentNode.rowIndex;
+ var
id=document.getElementById('functions_table').rows[i].cells[0].innerHTML;
+
+ ##remove function from table
+ document.getElementById('functions_table').deleteRow(i);
+
+ ##remove attribute from array
+ for (var j=0;j<functions.length;j++){
+ if(functions[j].id==id){
+ functions.splice(j,1);
+ break;
+ }
}
}
@@ -257,6 +359,85 @@
button.innerHTML="<input type='button' value='Remove Attribute'
onClick='removeAttrib(this)'>";
count_attributes++;
}
+
+ function printActsTable(){
+ var act=new Object();
+
+ act.type=document.getElementById("act_type").value;
+ act.localization=document.getElementById("act_localization").value;
+ act.observation=document.getElementById("act_observation").value;
+
act.id=count_acts;
+
+ if(act.type==""){
+ alert("You need to fill in the required fields.");
+ return;
+ }
+
+ acts.push(act);
+
+ var table = document.getElementById("acts_table");
+ var row=table.insertRow(1);
+
+ var id=row.insertCell(0);
+ id.innerHTML=
act.id;
+
+ var type=row.insertCell(1);
+ type.innerHTML=act.type;
+
+ var localization=row.insertCell(2);
+ localization.innerHTML=act.localization;
+
+ var observation=row.insertCell(3);
+ observation.innerHTML=act.observation;
+
+ var button=row.insertCell(4);
+ button.innerHTML="<input type='button' value='Remove Act'
onClick='removeAct(this)'>";
+ count_acts++;
+ refreshSelects();
+ }
+
+ function printFunctionsTable(){
+ var function_obj=new Object();
+
+ var index=document.getElementById("function_act_select").selectedIndex;
+ function_obj.act_id=document.getElementsByTagName("option")[index].value;
+
+ index=document.getElementById("function_origin_select").selectedIndex;
+ function_obj.origin=document.getElementsByTagName("option")[index].value;
+
+ function_obj.value=document.getElementById("function_value").value;
+ function_obj.destname=document.getElementById("function_destname").value;
+
function_obj.id=count_functions;
+
+ if(function_obj.act_id=="" || function_obj.origin=="" ||
function_obj.value==""){
+ alert("You need to fill in the required fields.");
+ return;
+ }
+
+ functions.push(function_obj);
+
+ var table = document.getElementById("functions_table");
+ var row=table.insertRow(1);
+
+ var id=row.insertCell(0);
+ id.innerHTML=
function_obj.id;
+
+ var act_id=row.insertCell(1);
+ act_id.innerHTML=function_obj.act_id;
+
+ var value=row.insertCell(2);
+ value.innerHTML=function_obj.value;
+
+ var destname=row.insertCell(3);
+ destname.innerHTML=function_obj.destname;
+
+ var origin=row.insertCell(4);
+ origin.innerHTML=function_obj.origin;
+
+ var button=row.insertCell(5);
+ button.innerHTML="<input type='button' value='Remove Function'
onClick='removeFunc(this)'>";
+ count_functions++;
+ }
function submitForm() {
@@ -268,9 +449,6 @@
alert("You need to define at least the source name to save.");
return;
}
-
-
- ##IF SOURCE NAME NOT DEFINED RETURN
var jsonDataObject = new Object();
jsonDataObject.source = source;
@@ -345,6 +523,30 @@
</table>
Relation Type*: <input type="text" id="relation_type">Relation Value*:
<input type="text" id="relation_value">Origin Id*: <select
id="relation_origin_select"></select>Destination Id*: <select
id="relation_destination_select"></select>Relation Observation: <input
type="text" id="relation_observation"><input type="button" value="Add
Relation" onClick="printRelationsTable()"><br>
+ <h3>Acts »</h3>
+ <table id="acts_table">
+ <tr>
+ <td>Act Id</td>
+ <td>Act Type</td>
+ <td>Act Localization</td>
+ <td>Act Observation</td>
+ </tr>
+ </table>
+ Act Type*: <input type="text" id="act_type">Act Localization: <input
type="text" id="act_localization">Act Observation: <input type="text"
id="act_observation"><input type="button" value="Add Act"
onClick="printActsTable()"><br>
+
+ <h3>Functions in Act »</h3>
+ <table id="functions_table">
+ <tr>
+ <td>Function Id</td>
+ <td>Act Id</td>
+ <td>Function Value</td>
+ <td>Function Destname</td>
+ <td>Function Origin</td>
+ </tr>
+ </table>
+ Act Id*: <select id="function_act_select"></select>Function Value*:
<input type="text" id="function_value">Function Destname: <input
type="text" id="function_destname">Function Origin*:<select
id="function_origin_select"></select><input type="button" value="Add
Function" onClick="printFunctionsTable()"><br>
+
+
<input type="button" value="Save" onclick="submitForm()">
</form>
</div>