Revision: 1285
Author: LudicrousResearcher
Date: Tue Dec 1 23:09:20 2009
Log: Hooked in support for autocomplete to the add inference UI. Not yet
connected to back end for adding rules, but UI is now functional.
http://code.google.com/p/delphi-museum-project/source/detail?r=1285
Modified:
/trunk/modules/ontotools/addInference.php
/trunk/themes/pahma/scripts/addInference.js
/trunk/themes/pahma/templates/addInference.tpl
=======================================
--- /trunk/modules/ontotools/addInference.php Mon Nov 30 10:30:13 2009
+++ /trunk/modules/ontotools/addInference.php Tue Dec 1 23:09:20 2009
@@ -22,7 +22,11 @@
die();
}
-$style_block = "<style>
+$themebase = $CFG->wwwroot.'/themes/'.$CFG->theme;
+
+$style_block = '
+<link rel="stylesheet" href="'.$themebase.'/style/jquery.autocomplete.css"
type="text/css">
+<style>
.nochoice {color:#888; }
.intro {font-size:0.9em; font-weight:bold; margin-bottom:0;}
.up {margin-bottom: 0.1em; }
@@ -32,17 +36,42 @@
#table1 td {padding:4px; }
#table1 .label {font-size:0.9em; }
#table1 input.numeric {text-align:right; }
-</style>";
+</style>';
$t->assign("style_block", $style_block);
-$themebase = $CFG->wwwroot.'/themes/'.$CFG->theme;
-
$script_block = '
<script type="text/javascript">
var _themeroot = "'.$themebase.'";
</script>
-<script type="text/javascript"
src="'.$themebase.'/scripts/addInference.js"></script>';
+<script type="text/javascript"
src="'.$CFG->wwwroot.'/libs/jquery/jquery.autocomplete.pack.js"></script>
+<script type="text/javascript"
src="'.$CFG->wwwroot.'/libs/jquery/jquery.bgiframe.min.js"></script>
+<script type="text/javascript"
src="'.$CFG->wwwroot.'/libs/jquery/jquery.ajaxQueue.js"></script>
+<script type="text/javascript"
src="'.$themebase.'/scripts/addInference.js"></script>
+<script type="text/javascript">
+$().ready(function() {
+
+ $("#InfConcept").autocomplete("'.$CFG->wwwroot.'/api/ac_concepts.php", {
+ minChars: 2,
+ scroll: true,
+ scrollHeight: 180,
+ max: 40,
+ matchSubset: false
+ });
+
+ $("#InfConcept").result(function(event, data, formatted) {
+ if (data)
+ $("#InfConceptID").val(data[1]);
+ });
+
+ //alert("Adding test row: "+newReqRowHTML(getRow_ID(true, 0),
getConcept_ID(true, 0), getConceptID_ID(true, 0)));
+ addReqRow();
+ addReqRow();
+ addExclRow();
+ $("#InfConcept")[0].focus();
+});
+
+</script>';
$t->assign("script_block", $script_block);
=======================================
--- /trunk/themes/pahma/scripts/addInference.js Mon Nov 30 10:30:13 2009
+++ /trunk/themes/pahma/scripts/addInference.js Tue Dec 1 23:09:20 2009
@@ -1,35 +1,57 @@
-$(document).ready(function(){
- //alert("Hi there");
- addReqRow();
- addReqRow();
- addExclRow();
- addExclRow();
- $("#InfConcept")[0].focus();
-});
-
var nReqRows = 0;
var nExclRows = 0;
-function newReqRowHTML( iRow ) {
- var id0 = "ReqRow" + iRow;
- var id2 = "ReqConcept" + iRow;
- var id3 = "ReqConceptID" + iRow;
- var htmlStr = '<tr class="ReqRow" id="' + id0 + '"><td
width="10px"></td>' +
+var REQ = true;
+var EXCL = false;
+
+function getRow_ID(isReq, iRow) {
+ return (isReq?"Req":"Excl")+"Row"+iRow;
+}
+
+function getConcept_ID(isReq, iRow) {
+ return (isReq?"Req":"Excl")+"Concept" + iRow;
+}
+
+function getConceptID_ID(isReq, iRow) {
+ return (isReq?"Req":"Excl")+"ConceptID" + iRow;
+}
+
+function newReqRowHTML(rowID, concID, idID) {
+ var htmlStr = '<tr class="ReqRow" id="' + rowID + '"><td
width="10px"></td>' +
'<td><p class="label" align="right">Concept:</p></td>' +
- '<td><input id="'+id2+'" type="text" maxlength="150" size="40" value=""
/>' +
- '<input id="'+id3+'" type="hidden" value="'+(10001*(iRow+1))+'" /></td>'
+
- '<td><input type="image" src="'+_themeroot+'/images/choose.gif"
onclick="ShowChooser(\''+id2+'\',\''+id3+'\');"/></td>' +
- '<td><input type="image" src="'+_themeroot+'/images/delete.gif"
onclick="DeleteRow(\''+id0+'\',\'Req\');"/></td>' +
+ '<td><input id="'+concID+'" class="ac_concept" type="text"
maxlength="150" size="40" value="" />' +
+ '<input id="'+idID+'" type="hidden" value="-1" /></td>' +
+// '<td><input type="image" src="'+_themeroot+'/images/choose.gif"
onclick="ShowChooser(\''+concID+'\',\''+idID+'\');"/></td>' +
+ '<td colspan="2"><input type="image"
src="'+_themeroot+'/images/delete.gif"
onclick="DeleteRow(\''+rowID+'\',\'Req\');"/></td>' +
'<td width="10px"></td></tr>';
return htmlStr;
}
function addReqRow() {
+ var addAfter;
if( $("tr.ReqRow").length <= 0 ) {
- $("#ReqModeRow").after( newReqRowHTML(0) );
+ nReqRows = 0;
+ addAfter = $("#ReqModeRow");
} else {
- $("tr.ReqRow:last").after( newReqRowHTML(nReqRows) );
- }
+ addAfter = $("tr.ReqRow:last");
+ }
+ var rowID = getRow_ID(REQ,nReqRows);
+ var concID = getConcept_ID(REQ,nReqRows);
+ var idID = getConceptID_ID(REQ,nReqRows);
+ addAfter.after( newReqRowHTML(rowID, concID, idID) );
+ //alert("Setting autocomplete on: " + concID + " with
URL:\n"+wwwroot+"/api/ac_concepts.php");
+ $("#"+concID).autocomplete(wwwroot+"/api/ac_concepts.php", {
+ minChars: 2,
+ scroll: true,
+ scrollHeight: 180,
+ max: 40,
+ matchSubset: false
+ });
+ $("#"+concID).result(function(event, data, formatted) {
+ if (data)
+ $("#"+idID).val(data[1]);
+ });
+
nReqRows += 1;
}
@@ -47,27 +69,40 @@
}
}
-function newExclRowHTML( iRow ) {
- var id0 = "ExclRow" + iRow;
- var id2 = "ExclConcept" + iRow;
- var id3 = "ExclConceptID" + iRow;
- var htmlStr = '<tr class="ExclRow" id="' + id0 + '"><td
width="10px"></td>' +
+function newExclRowHTML(rowID, concID, idID) {
+ var htmlStr = '<tr class="ExclRow" id="' + rowID + '"><td
width="10px"></td>' +
'<td><p class="label" align="right">Concept:</p></td>' +
- '<td><input id="'+id2+'" type="text" maxlength="150" size="40" value=""
/>' +
- //'<input id="'+id3+'" type="hidden" value="'+(10100*(iRow+1))+'"
/></td>' +
- '<input id="'+id3+'" type="hidden" value="" /></td>' +
- '<td><input type="image" src="'+_themeroot+'/images/choose.gif"
onclick="ShowChooser(\''+id2+'\',\''+id3+'\');"/></td>' +
- '<td><input type="image" src="'+_themeroot+'/images/delete.gif"
onclick="DeleteRow(\''+id0+'\',\'Excl\');"/></td>' +
+ '<td><input id="'+concID+'" class="ac_concept" type="text"
maxlength="150" size="40" value="" />' +
+ '<input id="'+idID+'" type="hidden" value="-1" /></td>' +
+// '<td><input type="image" src="'+_themeroot+'/images/choose.gif"
onclick="ShowChooser(\''+concID+'\',\''+idID+'\');"/></td>' +
+ '<td colspan="2"><input type="image"
src="'+_themeroot+'/images/delete.gif"
onclick="DeleteRow(\''+rowID+'\',\'Excl\');"/></td>' +
'<td width="10px"></td></tr>';
return htmlStr;
}
function addExclRow() {
if( $("tr.ExclRow").length <= 0 ) {
- $("#ExclModeRow").after( newExclRowHTML(0) );
+ nExclRows = 0;
+ addAfter = $("#ExclModeRow");
} else {
- $("tr.ExclRow:last").after( newExclRowHTML(nExclRows) );
- }
+ addAfter = $("tr.ExclRow:last");
+ }
+ var rowID = getRow_ID(EXCL,nExclRows);
+ var concID = getConcept_ID(EXCL,nExclRows);
+ var idID = getConceptID_ID(EXCL,nExclRows);
+ addAfter.after( newExclRowHTML(rowID, concID, idID) );
+ $("#"+concID).autocomplete(wwwroot+"/api/ac_concepts.php", {
+ minChars: 2,
+ scroll: true,
+ scrollHeight: 180,
+ max: 40,
+ matchSubset: false
+ });
+ $("#"+concID).result(function(event, data, formatted) {
+ if (data)
+ $("#"+idID).val(data[1]);
+ });
+
nExclRows += 1;
}
@@ -99,7 +134,7 @@
for( var i=0; i < nReqRows; i++ ) {
var idval = "#ReqConceptID" + i;
refidstr = $(idval)[0].value;
- if(( "" + refidstr ) != "" ) {
+ if((( "" + refidstr ) != "" ) && ((0+refidstr)>=1)) {
xmlStr += '\n <concept idref="'+ refidstr + '" />';
nReqFound++;
}
@@ -115,7 +150,7 @@
for( i=0; i < nExclRows; i++ ) {
var idval = "#ExclConceptID" + i;
refidstr = $(idval)[0].value;
- if(( "" + refidstr ) != "" ) {
+ if((( "" + refidstr ) != "" ) && ((0+refidstr)>=1)) {
if( nExclFound == 0 )
xmlStr += '\n <exclude
mode="'+$("#InfExclSel")[0].options[$("#InfExclSel")[0].selectedIndex].text
+'">';
xmlStr += '\n <concept idref="'+ refidstr + '" />';
@@ -128,4 +163,3 @@
alert( "XML for new Rule:\n\n" + xmlStr );
return xmlStr;
}
-
=======================================
--- /trunk/themes/pahma/templates/addInference.tpl Mon Nov 30 10:30:13 2009
+++ /trunk/themes/pahma/templates/addInference.tpl Tue Dec 1 23:09:20 2009
@@ -28,7 +28,7 @@
<tr>
<td width="10px"></td>
<td colspan="4"><p class="intro" align="left">
- Let Delphi infer that an object has</p>
+ Make Delphi infer that an object has</p>
</td>
<td width="10px"></td>
</tr>
@@ -37,22 +37,13 @@
<td><p class="label" align="right">Concept:</p></td>
<td>
<input id="InfConcept" type="text" maxlength="150" size="40" value=""
/>
- <input id="InfConceptID" type="hidden" value="10000" />
+ <input id="InfConceptID" type="hidden" value="-1" />
</td>
- <td><input type="image" src="{$themeroot}/images/choose.gif"
onclick="ShowChooser('InfConcept','InfConceptID');"/></td>
- <td></td>
+ <!-- <td><input type="image" src="{$themeroot}/images/choose.gif"
onclick="ShowChooser('InfConcept','InfConceptID');"/></td> -->
+ <td colspan="2"></td>
<td width="10px"></td>
</tr>
- <tr>
- <td width="10px"></td>
- <td><p class="label" align="right">Notes:</p></td>
- <td colspan="3">
- <textarea rows="2" id="InfNotes" cols="40"></textarea>
- </td>
- <td width="10px"></td>
- </tr>
- <tr><td colspan="6"><hr></td>
- </tr>
+ <tr><td colspan="6" height="15px"></td>
<tr id="ReqModeRow">
<td width="10px"></td>
<td><p class="intro" align="right">When it has:</p></td>
@@ -71,7 +62,7 @@
</td>
<td width="10px"></td>
</tr>
- <tr><td colspan="6" height="15px"></td>
+ <!-- <tr><td colspan="6" height="5px"></td> -->
<tr id="ExclModeRow">
<td width="10px"></td>
<td><p class="intro" align="right">Unless it has:</p></td>
@@ -91,8 +82,18 @@
<td width="10px"></td>
</tr>
<tr><td colspan="6"><hr></td>
+ <tr>
+ <td width="10px"></td>
+ <td><p class="label" align="right">Notes:</p></td>
+ <td colspan="3">
+ <textarea rows="2" id="InfNotes" cols="40"></textarea>
+ </td>
+ <td width="10px"></td>
+ </tr>
+ <tr><td colspan="6"><hr></td>
+ </tr>
<tr><td colspan="6">
- <p align="center"> <input id="CommitBtn" type="button" value="Add this
rule"
+ <p align="center"> <input id="CommitBtn" type="button" value=" Add
this rule "
style="font-size:10pt;font-weight:bold" onclick="prepareAddInfXML();"
/></p>
</td></tr>
<tr><td colspan="6" height="10px"></td></tr>