PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions.ext/dllearner/dllearner-module.js

https://code.google.com/p/ontowiki/
JavaScript | 198 lines | 127 code | 29 blank | 42 comment | 14 complexity | b1ed2fac31812beab459a38bb18b8b6f MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. // Dllearner Action URI and SideWindow
  2. var dlActionURI = owUriBase + "service/dllearner/";
  3. var dlSideWindowID = "#Dllearner";
  4. // container manager specific ready statements
  5. $jq(document).ready(function() {
  6. /* initial refresh */
  7. /*
  8. if($jq('div.section-mainwindows').children('div.window').eq(0).length != 0){
  9. dlRefreshDllearner();
  10. }
  11. */
  12. /* Internal CM Link Handling (with livequery events) */
  13. $jq("a.tab")
  14. .livequery('click', function(event) { dlChangeGUI(event); });
  15. // open DL-Learner GUI from the extras menu of the ontoWiki
  16. $jq("a.dllOpen")
  17. .livequery('click', function(event) { dlChangeGUI(event); });
  18. $jq("a.dlRes")
  19. .livequery('mouseover', function(event) {
  20. hideHref($jq(this).parent());
  21. $jq(".contextmenu-enhanced .contextmenu").remove(); // remove all other menus
  22. })
  23. .livequery('click', function(event) { dlShowListMenu(event);} )
  24. .livequery('mouseout', function(event) {
  25. showHref($jq(this).parent());
  26. });
  27. $jq("a.addToLearner")
  28. .livequery('click', function(event) { dlMakeAction(event); });
  29. $jq("a.addToModelDef")
  30. .livequery('click', function(event) { dlMakeModelDef(event); });
  31. $jq("a.addToModelSub")
  32. .livequery('click', function(event) { dlMakeModelSub(event); });
  33. $jq("a.remove")
  34. .livequery('click', function(event) { dlMakeAction(event); });
  35. $jq("a.learnThis")
  36. .livequery('click', function(event) { dlLearn(event); });
  37. $jq("a.delProcess")
  38. .livequery('click', function(event) { dlDelProcess(event); });
  39. $jq('.property-add').click(function(event) {
  40. var table = $jq('#table' + $jq(this).attr('id').replace('property-add', '')).get(0);
  41. var row = table.insertRow(table.rows.length);
  42. $jq(row).addClass('editing');
  43. var c1 = row.insertCell(0);
  44. var c2 = row.insertCell(1);
  45. // c1.style.verticalAlign = 'top';
  46. $jq(c1).mouseover(function(event) {
  47. $jq(this).children('img').eq(0).css('visibility', '');
  48. });
  49. $jq(c1).mouseout(function(event) {
  50. $jq(this).children('img').eq(0).css('visibility', 'hidden');
  51. });
  52. // new Ajax.Updater(c1, owUriBase + 'service/getPropertySelector/?property=', {evalScripts: true});
  53. $jq(c1).load(owUriBase + 'service/getPropertySelector/');
  54. });
  55. /*$jq("a.formbutton")
  56. .livequery('click', function(event) { dlShowGUI (event); });*/
  57. });
  58. //on pressing the New-Process-Button the action learn this is called
  59. function dlLearn ( event ) {
  60. var options = '';
  61. var p = '';
  62. var n = '';
  63. i=0;
  64. options += $jq("#reasoner").val()+"/";
  65. options += $jq("#lerningProblem").val()+"/";
  66. options += $jq("#lerningAlgorithm").val();
  67. while(i < $jq("#radio"+i).attr("size")*2){
  68. //alert($jq("#radio"+i).attr("value"));
  69. if($jq("#radio"+i).attr("checked") && $jq("#radio"+i).attr("value") == 1){
  70. //alert($jq("#radio"+i).attr("name"));
  71. //pos[i] = encodeURIComponent ($jq("#radio"+i).attr("name"));
  72. p += encodeURIComponent ($jq("#radio"+i).attr("name"))+"/";
  73. }
  74. else if ($jq("#radio"+i).attr("checked") && $jq("#radio"+i).attr("value") == 0){
  75. //alert($jq("#radio"+i).attr("name"));
  76. //neg[i] = encodeURIComponent ($jq("#radio"+i).attr("name"));
  77. n += encodeURIComponent ($jq("#radio"+i).attr("name"))+"/";
  78. }
  79. i++;
  80. }
  81. action = encodeURIComponent ($jq(event.currentTarget).attr("name"));
  82. // refresh the main
  83. replaceWindow(dlActionURI, "act="+action+"&neg="+n+"&pos="+p+"&opt="+options);
  84. }
  85. // called if changing tabs or open from the extras menu
  86. function dlChangeGUI ( event ) {
  87. // look for the name and encode it for uri
  88. action = encodeURIComponent ($jq(event.currentTarget).attr("name"));
  89. // refresh the main
  90. replaceWindow(dlActionURI, "act="+action);
  91. //dlRefreshDllearner();
  92. }
  93. function dlMakeModelDef( event ) {
  94. var s='';
  95. //i=1;
  96. for(i =1; i<=6;i++){
  97. if ($jq("#radio"+i).attr("checked")){
  98. s += encodeURIComponent ($jq("#radio"+i).attr("value"));
  99. //alert(s);
  100. //i++;
  101. }
  102. }
  103. action = encodeURIComponent ($jq(event.currentTarget).attr("name"));
  104. replaceWindow(dlActionURI, "act="+action+"&s="+s);
  105. }
  106. function dlMakeModelSub( event ) {
  107. var s='';
  108. //i=1;
  109. for(i =1; i<=6;i++){
  110. if ($jq("#radio"+i).attr("checked")){
  111. s += encodeURIComponent ($jq("#radio"+i).attr("value"));
  112. //alert(s);
  113. //i++;
  114. }
  115. }
  116. action = encodeURIComponent ($jq(event.currentTarget).attr("name"));
  117. replaceWindow(dlActionURI, "act="+action+"&s="+s);
  118. }
  119. function dlRefreshDllearner ( parameters ) {
  120. if (typeof parameters == 'undefined') {
  121. parameters = "";
  122. }
  123. replaceWindow(dlActionURI, parameters);
  124. }
  125. // deleting the selected Process
  126. function dlDelProcess ( event ) {
  127. action = encodeURIComponent ($jq(event.currentTarget).attr("name"));
  128. id = encodeURIComponent ($jq(event.currentTarget).attr("id"));
  129. replaceWindow(dlActionURI, "act="+action+"&id="+id);
  130. }
  131. // makes the usual actions with action name and container name
  132. function dlMakeAction ( event ) {
  133. $jq(".contextmenu-enhanced .contextmenu").remove();
  134. // look for the name and encode it for uri
  135. action = encodeURIComponent ($jq(event.currentTarget).attr("name"));
  136. if($jq(event.currentTarget).attr("id")){
  137. name = encodeURIComponent ($jq(event.currentTarget).attr("id"));
  138. }
  139. else{
  140. name = $jq("#sel").val();
  141. }
  142. // refresh the main
  143. replaceWindow(dlActionURI, "act="+action+"&name="+name);
  144. }
  145. function dlShowListMenu(event) {
  146. // remove all other menus
  147. $jq(".contextmenu-enhanced .contextmenu").remove();
  148. // generate coordinates for context menu
  149. menuX = event.pageX - 30;
  150. menuY = event.pageY - 20;
  151. menuId = "windowmenu-"+menuX+"-"+menuY;
  152. //encodedName = encodeURIComponent( $jq(event.target).parent().children("a.cmResName").html() );
  153. encodedName = $jq(event.currentTarget).attr("name");
  154. //encodedId = encodeURIComponent( $jq(event.currentTarget).attr("id"));
  155. // create the plain menu with correct style and position
  156. $jq(".contextmenu-enhanced").append("<div class='contextmenu' id='"+menuId+"'></div>");
  157. $jq("#"+menuId)
  158. .attr({ style: "z-index: "+menuZIndex+"; top: "+menuY+"px; left: "+menuX+"px;" })
  159. .click( function(ev){ ev.stopPropagation(); });
  160. // create the menu content
  161. $jq('#'+menuId).append(
  162. "<ul>"+
  163. "<b>Positive Examples:</b><br> "+encodedName+
  164. "For more Information please visit <a href='http://dl-learner.org/Projects/DLLearner'><b>DL-Learner Homepage</b></a>"+
  165. "</ul>");
  166. // fade in the menu and stop the even propagation)
  167. $jq('#'+menuId).show();
  168. event.stopPropagation();
  169. }