[mhk] r1086 committed - Dynamic selects on create_source page @mhk_families

2 views
Skip to first unread message

codesite...@google.com

unread,
Jun 29, 2013, 12:45:45 PM6/29/13
to mhk-dis...@googlegroups.com
Revision: 1086
Author: tbc...@gmail.com
Date: Sat Jun 29 09:45:30 2013
Log: Dynamic selects on create_source page @mhk_families
http://code.google.com/p/mhk/source/detail?r=1086

Modified:
/branches/mhk_families/idb/etc/template/new/create_source.vm

=======================================
--- /branches/mhk_families/idb/etc/template/new/create_source.vm Sat Jun 29
08:47:29 2013
+++ /branches/mhk_families/idb/etc/template/new/create_source.vm Sat Jun 29
09:45:30 2013
@@ -15,6 +15,28 @@
var relations=new Array();
var attributes=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;
+ 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");
+
+ 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);
+ }
+ }
+
function removePerson(row){

var box=confirm("Deleting this person will remove all attributes and
relations associated! Are you sure you want to continue?");
@@ -71,11 +93,12 @@

##remove attibutes from this person from array
for (var j=0;j<attributes.length;j++){
- if(attributes[j].person_id==id || attributes[j].person_id==id){
+ if(attributes[j].person_id==id){
attributes.splice(j,1);
}
}

+ refreshSelects();
}
function removeRelation(row){
##get relation id
@@ -143,12 +166,18 @@
button.innerHTML="<input type='button' value='Remove Person'
onClick='removePerson(this)'>";

count_persons++;
+ refreshSelects();
}

function printRelationsTable(){
var relation=new Object();
- relation.origin=document.getElementById("origin_id").value;
- relation.destination=document.getElementById("destination_id").value;
+
+ var
origin=document.getElementById("relation_origin_select").selectedIndex;
+ relation.origin=document.getElementsByTagName("option")[origin].value;
+
+ var
destination=document.getElementById("relation_destination_select").selectedIndex;
+
relation.destination=document.getElementsByTagName("option")[destination].value;
+
relation.type=document.getElementById("relation_type").value;
relation.value=document.getElementById("relation_value").value;

relation.observation=document.getElementById("relation_observation").value;
@@ -190,9 +219,12 @@

function printAttributesTable(){
var attribute=new Object();
+
+ var index=document.getElementById("attribute_select").selectedIndex;
+ attribute.person_id=document.getElementsByTagName("option")[index].value;
+
attribute.name=document.getElementById("attribute_name").value;
attribute.value=document.getElementById("attribute_value").value;
- attribute.person_id=document.getElementById("person_id").value;

attribute.observation=document.getElementById("attribute_observation").value;
attribute.id=count_attributes;

@@ -229,14 +261,14 @@
function submitForm() {

source.name=document.getElementById("source_name").value;
+ source.type=document.getElementById("source_type").value;
+ source.observation=document.getElementById("source_observation").value;

if(source.name==""){
alert("You need to define at least the source name to save.");
return;
}

- source.type=document.getElementById("source_type").value;
- source.observation=document.getElementById("source_observation").value;

##IF SOURCE NAME NOT DEFINED RETURN

@@ -298,7 +330,7 @@
<td>Attribute Observation</td>
</tr>
</table>
- Attribute Name*: <input type="text" id="attribute_name">Attribute
Value*: <input type="text" id="attribute_value">Person Id*: <input
type="text" id="person_id">Attribute Observation: <input type="text"
id="attribute_observation"><input type="button" value="Add Attribute"
onClick="printAttributesTable()"><br>
+ Attribute Name*: <input type="text" id="attribute_name">Attribute
Value*: <input type="text" id="attribute_value">Person Id*: <select
id="attribute_select"></select>Attribute Observation: <input type="text"
id="attribute_observation"><input type="button" value="Add Attribute"
onClick="printAttributesTable()"><br>

<h3>Relations &raquo;</h3>
<table id="relations_table">
@@ -311,7 +343,7 @@
<td>Relation Observation</td>
</tr>
</table>
- Relation Type*: <input type="text" id="relation_type">Relation Value*:
<input type="text" id="relation_value">Origin Id*: <input type="text"
id="origin_id">Destination Id*: <input type="text"
id="destination_id">Relation Observation: <input type="text"
id="relation_observation"><input type="button" value="Add Relation"
onClick="printRelationsTable()"><br>
+ 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>

<input type="button" value="Save" onclick="submitForm()">
</form>
Reply all
Reply to author
Forward
0 new messages