PageRenderTime 50ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/SoftWiki/SoftWiki.js

https://bitbucket.org/aksw/softwikiv10
JavaScript | 2333 lines | 1584 code | 314 blank | 435 comment | 286 complexity | fa80b8ec91a4fe643fc49d0427873422 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * SoftWiki Plugin Javascript Component(s)
  3. * Version: $Id: SoftWiki.js 2768 2010-03-12 17:35:32Z triechert $
  4. */
  5. // pseudo constants
  6. var SWORE_REQUIREMENT = 'http://ns.softwiki.de/req/Requirement';
  7. var SWORE_ABSTRACT_REQUIREMENT = 'http://ns.softwiki.de/req/AbstractRequirement';
  8. var SWORE_MODEL = 'http://ns.softwiki.de/req/';
  9. var SWORE_FILE_PROPERTY = 'http://ns.softwiki.de/req/hasLinkedFile';
  10. // softwiki specific ready statements
  11. $jq(document).ready(function() {
  12. $jq(".replace-inline").livequery("click", function() {
  13. hideHref($jq(this));
  14. backParameter="";
  15. $jq("#backToRequirements > input").each(function(){
  16. backParameter+=$jq(this).val()+'&';
  17. });
  18. if (backParameter.length>0) backParameter=backParameter.substr(0,backParameter.length-1);
  19. replaceWindow(
  20. owUriBase + "softwiki/view/",
  21. "r="+encodeURIComponent($jq(this).attr("about")),
  22. null,
  23. function() { showComments(); })
  24. });
  25. $jq("#quicksearch").livequery("keypress", function(event) { swQuickSearch(event); });
  26. $jq("#swEdit").livequery("click", function(event) { swEdit(event); });
  27. $jq("#swLinkproject").livequery("click", function(event) { swLinkproject(event); });
  28. $jq("#swUnlinkproject").livequery("click", function(event) { swUnlinkproject(event); });
  29. $jq(".swRelationEdit").livequery("click", function(event) { swRelationEdit(event); });
  30. $jq("#swCancel").livequery("click", function(event) { swCancel(event); });
  31. $jq("#swSubmit").livequery("click", function(event) { swSubmit(event); });
  32. $jq("#swDelete").livequery("click", function(event) { swDelete(event); });
  33. $jq("#swAddExistingFile").livequery("click", function(event) { swAddExistingFile(event); });
  34. $jq("#swAddNewFile").livequery("click", function(event) { swAddNewFile(event); });
  35. $jq(".swFile").livequery("click", function(event) { swFile(event); });
  36. $jq("#swSubmitFile").livequery("click", function(event) { swSubmitFile(event); });
  37. $jq(".swFileUnlink").livequery("click",function(event) { swFileUnlink(event); });
  38. $jq("#swFileInput").livequery("change",function(event) {
  39. var label = $jq("#swFileInput").attr("value");
  40. var lastpos = label.search(/([^\/\\]+)$/);
  41. var filename = label.substr(lastpos,label.length);
  42. $jq("#swLabelInput").attr("value",filename);
  43. event.stopPropagation();
  44. });
  45. $jq("#swAddExistingDec").livequery("click", function(event) { swAddExistingDec(event); });
  46. $jq("#swAddNewDec").livequery("click", function(event) { swAddNewDec(event); });
  47. $jq(".swDec").livequery("click", function(event) { swDec(event); });
  48. $jq("#swSubmitDec").livequery("click", function(event) { swSubmitDec(event); });
  49. $jq(".swDecUnlink").livequery("click",function(event) { swDecUnlink(event); });
  50. $jq(".swDecTop").livequery("click",function(event) { swDecTop(event); });
  51. $jq(".swDecDown").livequery("click",function(event) { swDecDown(event); });
  52. $jq(".swDecUnTop").livequery("click",function(event) { swDecUnTop(event); });
  53. $jq(".swDecUnDown").livequery("click",function(event) { swDecUnDown(event); });
  54. $jq(".swDecLink").livequery("click",function(event) { swDecLink(event); });
  55. $jq("#swDecInput").livequery("change",function(event) {
  56. var label = $jq("#swDecInput").attr("value");
  57. var lastpos = label.search(/([^\/\\]+)$/);
  58. var filename = label.substr(lastpos,label.length);
  59. $jq("#swLabelInput").attr("value",filename);
  60. event.stopPropagation();
  61. });
  62. // opendirect links via
  63. // http://localhost/ontowiki/softwiki/open/?requirement=...&m=...
  64. var opendirect = $jq("div#opendirect").text();
  65. if (opendirect != "") {
  66. selectedResource = SWORE_REQUIREMENT;
  67. replaceWindow(
  68. owUriBase + "softwiki/view/",
  69. "r="+encodeURIComponent(opendirect),
  70. null,
  71. function() {
  72. showComments();
  73. // set link to standard url to do full request
  74. $jq("a.requirement-back").attr(
  75. 'href',
  76. owUriBase + "resource/list/?r=" + selectedResource
  77. ).removeAttr('class');
  78. });
  79. }
  80. // BEGIN livequeries for the editing of requirement-relations inside a 2nd window BEGIN
  81. $jq("a.input-reqRelation-ok").livequery("click",function(event) {
  82. var queryString = $jq("div.window form#input-reqRelation").serialize();
  83. var targetwin = $jq("#overlays").next();
  84. $jq("#overlays").removeAttr("style");
  85. targetwin.fadeOut("normal");
  86. $jq.get(owUriBase + "softwiki/relationsservice/",queryString,function(data, textStatus) {
  87. if (data.search(/warning:no operations performed/) > -1) {
  88. // do nothing
  89. } else {
  90. var showRelated = $jq('input.toggleReqRelatedCheckbox').attr('checked');
  91. var showSimilar = $jq('input.toggleReqSimilarCheckbox').attr('checked');
  92. var showAll = $jq('input.toggleReqUnrelatedCheckbox').attr('checked');
  93. showRelations(showRelated,showSimilar,showAll);
  94. }
  95. });
  96. event.stopPropagation();
  97. });
  98. $jq("a.input-reqRelation-cancel").livequery("click",function(event) {
  99. var targetwin = $jq("#overlays").next();
  100. $jq("#overlays").removeAttr("style");
  101. targetwin.fadeOut("normal");
  102. event.stopPropagation();
  103. });
  104. // END livequeries for the editing of requirement-relations inside a 2nd window END
  105. $jq(".wrapme").livequery("click", function(event) { swToggleWrap(event); });
  106. $jq(".wrapme").livequery("mouseover", function(event) { $jq(event.target).css("cursor", "pointer"); });
  107. // show default reqlist / and Add Requirement Button
  108. if(typeof(selectedResource)!= "undefined" && opendirect == "") {
  109. replaceWindow(owUriBase + "softwiki/reqlist/", "all=true&resource=" + getSoftWikiFrickelJson(false));
  110. $jq("#swNew").show();
  111. $jq("#swNew").click( function(event) {
  112. // reload main window and remove all other windows
  113. replaceWindow(owUriBase + "softwiki/view/", "new&resources=" + getSoftWikiFrickelJson(false), $jq("div.section-mainwindows").children("div.window").eq(0), function() {newRequirement=event; });
  114. $jq("div.section-mainwindows").children("div.window").slice(1).remove();
  115. //swEdit(window.event);
  116. });
  117. }
  118. // add comment (depends on requirement form now)
  119. $jq("#softwiki-add-comment").livequery("click", function(event) {
  120. if ($jq("#softwiki-comment").val().length==0) alert("You must not post an empty comment.");
  121. else {
  122. var url = owUriBase + 'service/comments/?' + $jq("form.softwiki-comment").serialize() + "&prefix=softwiki";
  123. $jq.get(url,'',function() {
  124. showComments();
  125. });
  126. }
  127. })
  128. // add valuation
  129. $jq("#softwiki-add-valuation").livequery("click", function(event) {
  130. if ($jq("#valuation").val()==0) alert("You have to choose the number of stars.");
  131. else{
  132. var url = owUriBase + 'service/comments/?' + $jq("form.softwiki-valuation").serialize() + "&prefix=softwiki";
  133. $jq.get(url,'',function() {
  134. showComments();
  135. });
  136. }
  137. })
  138. // edit valuation
  139. $jq("#softwiki-edit-valuation").livequery("click", function() {
  140. $jq(".softwiki-valuation .disabled").removeClass("disabled").addClass("wasDisabled");
  141. $jq(".softwiki-valuation :disabled").removeAttr("disabled");
  142. $jq("#softwiki-cancel-valuation").show();
  143. $jq("#softwiki-submit-edit-valuation").show();
  144. $jq("#softwiki-edit-valuation").hide();
  145. })
  146. // cancel valuation
  147. $jq("#softwiki-cancel-valuation").livequery("click", function() {
  148. $jq(".softwiki-valuation .wasDisabled").addClass("disabled").removeClass("wasDisabled").attr("disabled", "disabled");
  149. $jq(".softwiki-valuation").resetForm();
  150. var oldvalue=$jq("#valuation").attr("oldvalue");
  151. $jq("#valuation").attr("value",$jq("#valuation").attr("oldvalue"));
  152. for (var i=1;i<=5;i++)
  153. if (i<=oldvalue) $jq('#valuationStar'+i).attr('src',$jq('#valuationStar'+i).attr('src').replace('icon_star_empty.jpg','icon_star_full.png'));
  154. else $jq('#valuationStar'+i).attr('src',$jq('#valuationStar'+i).attr('src').replace('icon_star_full.png','icon_star_empty.jpg'));
  155. $jq("#softwiki-cancel-valuation").hide();
  156. $jq("#softwiki-submit-edit-valuation").hide();
  157. $jq("#softwiki-edit-valuation").show();
  158. })
  159. // submit edit valuation
  160. $jq("#softwiki-submit-edit-valuation").livequery("click", function() {
  161. if ($jq("#valuation").val()==0) alert("You have to choose the number of stars.");
  162. else{
  163. var url = owUriBase + 'service/comments/?' + $jq("form.softwiki-valuation").serialize()
  164. + "&edit=" + $jq("#valuation").attr("edit") + "&prefix=softwiki";
  165. replaceWindow(url, '', $jq("div.section-mainwindows").children("div.window").eq(1));
  166. }
  167. })
  168. // add tag-description
  169. $jq("#softwiki-add-tag-description").livequery("click", function() {
  170. if ($jq("#tag-description").val().length==0) alert("You must not post an empty tag description.");
  171. else {
  172. loadTags(true, $jq("form.softwiki-tag").serialize());
  173. }
  174. })
  175. // toggle defined tags
  176. $jq(".toggleDefinedTags").livequery("click", function() {
  177. filterTags();
  178. })
  179. //toggle undefined tags
  180. $jq(".toggleUndefinedTags").livequery("click", function() {
  181. filterTags();
  182. })
  183. $jq('.requirement-back').livequery('click', function() {
  184. // reload main window
  185. if (backParameter.length=="") backParameter="all=true&resources="+getSoftWikiFrickelJson(false);
  186. replaceWindow(owUriBase + "softwiki/reqlist/", backParameter);
  187. // remove all other windows
  188. $jq("div.section-mainwindows").children("div.window").slice(1).remove();
  189. });
  190. // assign search function to tag search field
  191. $jq('input#tag-search-input').livequery('keyup', function() {
  192. // using timeout here because tag search via regexp isn't as fast as (case-sensitive) jq contains function
  193. if (typeof(to) != "undefined") {
  194. window.clearTimeout(tagtimeout);
  195. var tagtimeout = window.setTimeout("filterTags()","750");
  196. } else {
  197. var tagtimeout = window.setTimeout("filterTags()","750");
  198. }
  199. });
  200. // req Relations Checkboxes
  201. $jq('.toggleReqSimilarCheckbox').livequery('click', function(event) {
  202. $jq(event.target).parents('div.window').eq(0).addClass('is-processing');
  203. //alert("related: " + $jq('input.toggleReqRelatedCheckbox').attr('checked'));
  204. var showRelated = $jq('input.toggleReqRelatedCheckbox').attr('checked');
  205. //alert("similar: " + $jq('input.toggleReqSimilarCheckbox').attr('checked'));
  206. var showSimilar = $jq('input.toggleReqSimilarCheckbox').attr('checked');
  207. //alert("all: " + $jq('input.toggleReqUnrelatedCheckbox').attr('checked'));
  208. var showAll = $jq('input.toggleReqUnrelatedCheckbox').attr('checked')
  209. showRelations(showRelated,showSimilar,showAll);
  210. });
  211. $jq('.toggleReqRelatedCheckbox').livequery('click', function(event) {
  212. $jq(event.target).parents('div.window').eq(0).addClass('is-processing');
  213. //alert("related: " + $jq('input.toggleReqRelatedCheckbox').attr('checked'));
  214. var showRelated = $jq('input.toggleReqRelatedCheckbox').attr('checked');
  215. //alert("similar: " + $jq('input.toggleReqSimilarCheckbox').attr('checked'));
  216. var showSimilar = $jq('input.toggleReqSimilarCheckbox').attr('checked');
  217. //alert("all: " + $jq('input.toggleReqUnrelatedCheckbox').attr('checked'));
  218. var showAll = $jq('input.toggleReqUnrelatedCheckbox').attr('checked')
  219. showRelations(showRelated,showSimilar,showAll);
  220. });
  221. $jq('.toggleReqUnrelatedCheckbox').livequery('click', function(event) {
  222. $jq(event.target).parents('div.window').eq(0).addClass('is-processing');
  223. //alert("related: " + $jq('input.toggleReqRelatedCheckbox').attr('checked'));
  224. var showRelated = $jq('input.toggleReqRelatedCheckbox').attr('checked');
  225. //alert("similar: " + $jq('input.toggleReqSimilarCheckbox').attr('checked'));
  226. var showSimilar = $jq('input.toggleReqSimilarCheckbox').attr('checked');
  227. //alert("all: " + $jq('input.toggleReqUnrelatedCheckbox').attr('checked'));
  228. var showAll = $jq('input.toggleReqUnrelatedCheckbox').attr('checked')
  229. showRelations(showRelated,showSimilar,showAll);
  230. });
  231. // pager links handle
  232. $jq('a.pager').livequery('click', function() {
  233. page($jq(this));
  234. });
  235. // auto resize for the req description
  236. //$jq("#rdescription").livequery("keyup", function(event) { swReqDescAutoResize(event); });
  237. $jq("span.removetag").livequery('click', function() { if (!$jq(this).parent().hasClass('disabled')) $jq(this).parent().remove(); });
  238. $jq('#rtagsButton').livequery('click', function(event) { addTagWithButton(event); });
  239. $jq('#rVersionButton').livequery('click', function(event) { changeVersionButton(event); });
  240. $jq('#rtagsNew').livequery('keyup', function(event) { suggestTags(event) });
  241. $jq("#rtagsNew").livequery('keyup', function(event) { addTag(event); });
  242. $jq('#rtagsNew-overlay > ul.tag_suggest > li').livequery('click', function(event) { addTagWithClickOnSuggestion($jq(this)); event.stopPropagation(); });
  243. $jq('html').click(function(event) { $jq('#rtagsNew-overlay').remove() });
  244. //$jq('#rtagsNew').livequery('blur', function() { $jq('#rtagsNew-overlay').remove() });
  245. });
  246. // toggles the wrap of req descriptions
  247. function swToggleWrap (event) {
  248. target = $jq(event.target);
  249. if (target.hasClass("nowrap")) {
  250. target.prev().hide();
  251. target.hide();
  252. target.next().show();
  253. target.next().next().show();
  254. } else {
  255. target.hide();
  256. target.prev().hide();
  257. target.prev().prev().show();
  258. target.prev().prev().prev().show();
  259. }
  260. /* content = target.html();
  261. target.toggleClass("nowrap");
  262. target.after("<div style='white-space:normal;'>"+content+"</div>");
  263. target.remove();
  264. */
  265. // todo: hier weitermachen seebi!
  266. }
  267. // pager
  268. function page(button) {
  269. // load vars (JSON doesn't work :\)
  270. var count = parseInt($jq('input#count').attr('value'));
  271. var limit = parseInt($jq('input#limit').attr('value'));
  272. var offset = parseInt($jq('input#offset').attr('value'));
  273. // TODO nheino ;)
  274. var pageUrl = $jq('input#page-url').attr('value').replace(/[\?&]limit=[\d]+/, '').replace(/[\?&]offset=[\d]+/, '');
  275. // which button was clicked
  276. if (button.hasClass('first-page')) {
  277. offset = 0;
  278. } else if (button.hasClass('previous-page')) {
  279. offset -= limit;
  280. } else if (button.hasClass('next-page')) {
  281. offset += limit;
  282. } else if (button.hasClass('last-page')) {
  283. offset = count - (count % limit);
  284. } else {
  285. var page = parseInt(button.attr('id').replace(/page-/, ''));
  286. offset = page * limit - limit;
  287. }
  288. // construct new url
  289. var newPageUrl = pageUrl + '&limit=' + limit + '&offset=' + offset;
  290. // load new page
  291. var view_win = button.parents('div.content').eq(0);
  292. view_win.addClass('is-processing');
  293. $jq.get(owUriBase + 'softwiki/reqlist/', newPageUrl,
  294. function (data, textStatus) {
  295. // only replace window content (keeps tabs 'activetabconent' and title of window)
  296. view_win.replaceWith($jq(data).children('.content').addClass('activetabcontent'));
  297. }
  298. );
  299. }
  300. // quicksearch in the reqlist
  301. function swQuickSearch (event) {
  302. if (event.which == 13) { // do only search if user pressed enter
  303. var searchString = event.target.value;
  304. // TODO nheino
  305. var pageUrl = $jq('input#page-url').attr('value').replace(/[\?&]search=[a-zA-Z0-9]+/, '');
  306. var newPageUrl = pageUrl + '&search=' + searchString;
  307. // load new page
  308. var view_win = $jq(event.target).parents('div.window').eq(0);
  309. view_win.addClass('is-processing');
  310. $jq.get(owUriBase + 'softwiki/reqlist/', newPageUrl,
  311. function (data, textStatus) {
  312. // only replace window content (keeps tabs 'activetabconent' and title of window)
  313. $jq(data).children('.content').addClass('activetabcontent');
  314. view_win.replaceWith($jq(data));
  315. }
  316. );
  317. }
  318. }
  319. // show similar requirements in the second window
  320. function showSimilars () {
  321. var oFCKeditor = FCKeditorAPI.GetInstance('rdescription');
  322. var queryString = "similar=" + encodeURIComponent($jq("#rtitle").val() + " " + stripTags(oFCKeditor.GetXHTML(false))/*$jq("#rdescription").val()*/);
  323. if ($jq("#requirement").attr("about") == "") {
  324. // do nothing
  325. } else {
  326. queryString += "&r=" + $jq("#requirement").attr("about");
  327. }
  328. if ($jq("div.section-mainwindows").children("div.window").size() == 1) {
  329. $jq("div.section-mainwindows").append("<div class='window'></div>");
  330. }
  331. var targetwin = $jq("div.section-mainwindows").children("div.window").eq(1);
  332. if (targetwin) {
  333. replaceWindow(owUriBase + "softwiki/reqlist/", queryString, targetwin);
  334. }
  335. }
  336. // show comments of requirements in the second window
  337. function showComments (showValuations, showComments) {
  338. if (arguments.length==0){
  339. showValuations=true;
  340. showComments=true;
  341. }
  342. else if (arguments.length==1){
  343. showComments=true;
  344. }
  345. if (typeof($jq("#requirement").attr("about")) != 'undefined') {
  346. var queryString = "list&r=" + encodeURIComponent($jq("#requirement").attr("about"))
  347. + "&val="+showValuations+"&com="+showComments
  348. + "&prefix=softwiki";
  349. if ($jq("div.section-mainwindows").children("div.window").size() == 1) {
  350. $jq("div.section-mainwindows").append("<div class='window'></div>");
  351. }
  352. var targetwin = $jq("div.section-mainwindows").children("div.window").eq(1);
  353. targetwin.addClass('is-processing');
  354. if (targetwin) {
  355. taboptionsString = "tab[0][string]=comments.title&tab[0][link]=javascript:showComments();&" +
  356. "tab[1][string]=sw.reqlist.listrelated&tab[1][link]=javascript:showRelations();&" +
  357. "active=0";
  358. $jq.get(owUriBase + "softwiki/extratab/", taboptionsString, function (data, textStatus) {
  359. replaceWindow(owUriBase + "service/comments/", queryString, targetwin, function() {
  360. $jq("div.section-mainwindows").children("div.window").eq(1).children("h1.title").after(data);
  361. $jq("div.section-mainwindows").children("div.window").eq(1).children("div.content").addClass("activetabcontent");
  362. });
  363. });
  364. }
  365. }
  366. }
  367. // show relations of requirements in the second window
  368. function showRelations (showRelated, showSimilar,showAll) {
  369. try{
  370. var oFCKeditor = FCKeditorAPI.GetInstance('rdescription');
  371. showSimilar = (showSimilar == null) ? false : showSimilar;
  372. showRelated = (showRelated == null) ? true : showRelated;
  373. showAll = (showAll == null) ? false : showAll;
  374. //alert(showRelated + ' # ' + showSimilar + ' # ' + showAll);
  375. if (showSimilar) {
  376. var queryString = "similar="+encodeURIComponent($jq("#rtitle").val()) + "%20"
  377. + encodeURIComponent(stripTags(oFCKeditor.GetXHTML(false))/*$jq("#rdescription").val()*/);
  378. } else {
  379. var queryString = "";
  380. }
  381. if (typeof($jq("#requirement").attr("about")) != 'undefined') {
  382. queryString += "&advancedConfig=true&r=" + encodeURIComponent($jq("#requirement").attr("about"))
  383. + "&all=" + showAll + "&relations=" + showRelated;
  384. if ($jq("div.section-mainwindows").children("div.window").size() == 1) {
  385. $jq("div.section-mainwindows").append("<div class='window'></div>");
  386. }
  387. var targetwin = $jq("div.section-mainwindows").children("div.window").eq(1);
  388. if (targetwin) {
  389. taboptionsString = "tab[0][string]=comments.title&tab[0][link]=javascript:showComments();&" +
  390. "tab[1][string]=sw.reqlist.listrelated&tab[1][link]=javascript:showRelations();&" +
  391. "active=1";
  392. $jq.get(owUriBase + "softwiki/extratab/", taboptionsString, function (data, textStatus) {
  393. replaceWindow(owUriBase + "softwiki/reqlist/", queryString, targetwin, function() {
  394. $jq("div.section-mainwindows").children("div.window").eq(1).children("h1.title").after(data);
  395. $jq("div.section-mainwindows").children("div.window").eq(1).children("div.content").addClass("activetabcontent");
  396. });
  397. });
  398. }
  399. }
  400. } catch(e) {}
  401. }
  402. // the requirement form edit button action
  403. function swEdit (event) {
  404. try{
  405. //get instance of the fckeditor
  406. var oFCKeditor = FCKeditorAPI.GetInstance('rdescription');
  407. //show editable title and description
  408. $jq("#noneditDescription").hide();
  409. $jq("#editDescription").show();
  410. $jq("#requirement").ajaxForm();
  411. // show similars of current content
  412. showSimilars();
  413. $jq("#rtitle").change( function() { showSimilars(); } );
  414. // show delete button not for "new requirements"
  415. if ( typeof( $jq("#requirement").attr('about') ) != 'undefined' && $jq("#requirement").attr('about').length!=0
  416. && !( $jq("#requirement").attr('userUri') != $jq("#requirement").attr('Creator') && $jq("#requirement").attr('userUri') != 'http://localhost/OntoWiki/Config/Admin') ) {
  417. $jq("#swDelete").show();
  418. }
  419. $jq("#swSubmit").show();
  420. $jq("#swCancel").show();
  421. $jq("#swEdit").hide();
  422. $jq("#swLinkproject").hide();
  423. $jq("#swUnlinkproject").hide();
  424. $jq(".disabled").removeClass("disabled").addClass("wasDisabled");
  425. $jq(":disabled").removeAttr("disabled");
  426. // show topic selector
  427. $jq('#rtopic-input').hide();
  428. $jq('#rtopic-select').show();
  429. // disable tag submit button by default (no empty tags)
  430. $jq('#rtagsButton').addClass('disabled').removeClass('wasDisabled');
  431. // store suggestable tags
  432. var url = owUriBase + 'service/tagsuggestion';
  433. jQuery.data($jq('#rtagsNew').get(0), 'suggestTags', new Array());
  434. $jq.getJSON(url, function(data) { jQuery.data($jq('#rtagsNew').get(0), 'suggestTags', data); });
  435. jQuery.data($jq('#rtags').get(0), 'rtagsOrig', $jq('#rtags').children('span'));
  436. event.stopPropagation();
  437. } catch(e){}
  438. }
  439. // the requirement form cancel button action
  440. function swCancel (event) {
  441. //hide editable title and description
  442. $jq("#editDescription").hide();
  443. $jq("#noneditDescription").show();
  444. // rebuild second view
  445. showComments();
  446. // rebuild the original tags
  447. $jq('#rtags').children('span').remove();
  448. $jq('#rtagsButton').after(jQuery.data($jq('#rtags').get(0), 'rtagsOrig'));
  449. $jq("#swDelete").hide();
  450. $jq("#swSubmit").hide();
  451. $jq("#swCancel").hide();
  452. $jq("#swEdit").show();
  453. $jq("#swLinkproject").show();
  454. $jq("#swUnlinkproject").show();
  455. $jq(".wasDisabled").addClass("disabled").removeClass("wasDisabled").attr("disabled", "disabled");
  456. $jq("#requirement").resetForm();
  457. //get instance of the fckeditor
  458. var oFCKeditor = FCKeditorAPI.GetInstance('rdescription');
  459. //restore Content
  460. oFCKeditor.SetHTML(oldFCKcontent);
  461. /*$jq('#rdescription').autoResizeTextArea();*/
  462. event.stopPropagation();
  463. }
  464. // the requirement form submit button action
  465. function swSubmit(event) {
  466. //get instance of the fckeditor
  467. var oFCKeditor = FCKeditorAPI.GetInstance('rdescription');
  468. if ($jq('#rtitle').val() == '' ||
  469. stripTags(oFCKeditor.GetXHTML(false)) == '' ||
  470. $jq('#rtopic-select').attr('value') == '' )
  471. {
  472. alert(allFields);
  473. return;
  474. }
  475. // submit data and reload windows to match default requirement view
  476. var targetwin = $jq("div.section-mainwindows").children("div.window").eq(1);
  477. var reqFormElem = $jq("#requirement");
  478. // Tags serialisieren (als JSON)
  479. var tagsJson = '[';
  480. var tags = $jq('#rtags').children('span');
  481. for (var i=0; i<tags.length; ++i) {
  482. tagsJson += '"' + tags.children('span.tag').eq(i).text() + '"';
  483. if (i < (tags.length-1)) {
  484. tagsJson += ','
  485. }
  486. }
  487. tagsJson += ']';
  488. // Buttons und Eingaben deaktivieren
  489. $jq("#swSubmit").hide();
  490. $jq("#swCancel").hide();
  491. $jq("#swDelete").hide();
  492. $jq("#swEdit").hide();
  493. $jq("#swLinkproject").hide();
  494. $jq("#swUnlinkproject").hide();
  495. $jq(".wasDisabled").addClass("disabled").removeClass("wasDisabled").attr("disabled", "disabled");
  496. // Hauptfenster auf is-processing stellen
  497. $jq("div.section-mainwindows div.window div.content").addClass("is-processing");
  498. // query string bauen
  499. var queryString = 'rtitle=' + encodeURIComponent($jq('#rtitle').attr('value')) + '&' +
  500. 'rdescription=' + encodeURIComponent(stripGreenTags(oFCKeditor.GetXHTML( false )).replace(/&nbsp;/g,' ')/*$jq('#rdescription').val()*/) + '&' +
  501. 'rtopic=' + encodeURIComponent($jq('#rtopic-select').attr('value')) + '&' +
  502. 'rtags=' + encodeURIComponent(tagsJson) + '&' +
  503. 'r=' + $jq("#requirement").attr("about");
  504. $jq.get(owUriBase + "softwiki/update/", queryString , function(data, textStatus) {
  505. if ($jq("#requirement").attr("about") == "") {
  506. var response = data.split(":");
  507. $jq("#requirement").attr("about",decodeURIComponent(response[1]));
  508. }
  509. var queryString = "r=" + $jq("#requirement").attr("about");
  510. // reload resource in first window
  511. var targetwin = $jq("div.section-mainwindows").children("div.window").eq(0);
  512. if (targetwin) {
  513. replaceWindow(owUriBase + "softwiki/view/", queryString, targetwin,function() {
  514. });
  515. }
  516. // Show default view (comments)
  517. showComments();
  518. // reload tags
  519. loadTags();
  520. // reload hierarchy
  521. $jq('div.hierarchy').livequery(function() {
  522. var id = $jq(this).attr('id');
  523. loadHierarchy(id, $jq('#' + id).find('ol').eq(0));
  524. });
  525. });
  526. event.stopPropagation();
  527. }
  528. // Delete Requirement
  529. function swDelete(event) {
  530. $jq("div.section-mainwindows").children("div.window").eq(0).toggleClass("is-processing");
  531. $jq("div.section-mainwindows").children("div.window").eq(1).remove();
  532. var queryString = "r=" + $jq("#requirement").attr("about");
  533. $jq.get(owUriBase + "resource/delete", queryString, function (data, textStatus) {
  534. location.reload();
  535. });
  536. }
  537. // link Requirement
  538. function swLinkproject(event) {
  539. try{
  540. $jq("#swLinkproject").hide();
  541. $jq("#swUnlinkproject").show();
  542. var queryString = "r=" + $jq("#requirement").attr("about");
  543. $jq.get(owUriBase + "softwiki/linkproject/", queryString, function (data, textStatus) { });
  544. } catch(e){}
  545. }
  546. // unlink Requirement
  547. function swUnlinkproject(event) {
  548. try{
  549. $jq("#swLinkproject").show();
  550. $jq("#swUnlinkproject").hide();
  551. var queryString = "r=" + $jq("#requirement").attr("about");
  552. $jq.get(owUriBase + "softwiki/unlinkproject/", queryString, function (data, textStatus) { });
  553. } catch(e){}
  554. }
  555. function go(select) {
  556. var wert = select.options[select.options.selectedIndex].value;
  557. if ( wert != "Select") {
  558. window.location.href = wert;
  559. }
  560. }
  561. /* ------------------------- Tags ---------------------------- */
  562. // tagbox-specific load actions
  563. var selectedTags = new Array();
  564. var tempTags = new Array();
  565. // load tags from service
  566. function loadTags(renewTags,queryParameters) {
  567. $jq('.window#tags').livequery(function() {
  568. if (renewTags) {
  569. selectedTags = new Array();
  570. }
  571. var url = owUriBase + 'service/tags/';//'?tags=' + getSoftWikiFrickelJson(true);
  572. if (queryParameters)
  573. queryParameters+='&tags='+getSoftWikiFrickelJson(true);
  574. else
  575. queryParameters='tags='+getSoftWikiFrickelJson(true);
  576. if (selectedResource) {
  577. url += '?r=' + selectedResource;
  578. if (queryParameters){
  579. url += '&' + queryParameters;
  580. }
  581. }
  582. else if (queryParameters){
  583. url += '?' + queryParameters;
  584. }
  585. $jq.ajax({
  586. url: url,
  587. dataType: 'html',
  588. data: tagParams,
  589. success: function(content) {
  590. $jq('.window#tags').contents('.content').children('ol').remove();
  591. $jq('.window#tags').contents('.content').children('div').remove();
  592. $jq('.window#tags').contents('.content').append(content);
  593. tempTags = selectedTags;
  594. selectedTags = new Array();
  595. }
  596. });
  597. });
  598. }
  599. $jq(document).ready(function() {
  600. // load json params from dom tree
  601. eval($jq('.window#tags').find('script').html());
  602. $jq('#tag-search-input').livequery(function() {
  603. $jq.each($jq('#tag-search-input'), function(id, input) {
  604. enhanceInput(input);
  605. })
  606. $jq('#tag-search-input').clearTagSearchInput();
  607. });
  608. $jq('.tag.javascript-on').livequery(function() {
  609. if (tempTags && jQuery.inArray($jq(this).attr('about'), tempTags) > -1) {
  610. $jq(this).addClass('selected');
  611. selectedTags.push($jq(this).attr('about'));
  612. }
  613. });
  614. $jq('.tag.javascript-on').livequery('click', function() {
  615. var tagA = $jq(this);
  616. var tagUri = tagA.attr('about');
  617. // insert clicked tag into tags array if it isn't
  618. // already there, else remove it
  619. var pos = jQuery.inArray(tagUri, selectedTags);
  620. if (pos > -1) {
  621. tags = selectedTags.splice(pos, 1);
  622. } else {
  623. selectedTags.push(tagUri);
  624. }
  625. // toggle tag selection
  626. tagA.toggleClass('selected');
  627. // reload main window
  628. // selectedTags = new Array();
  629. replaceWindow(owUriBase + "softwiki/reqlist/", "all=true&resources=" + getSoftWikiFrickelJson(false));
  630. $jq("div.section-mainwindows").children("div.window").slice(1).remove();
  631. loadTags(false,'tagUri='+tagUri);
  632. // alert('Reloading page: ' + owUriBase + 'softwiki/reqlist/...');
  633. });
  634. });
  635. /* ---------------------- Hierarchy -------------------------- */
  636. // hierarchy-specific load actions
  637. $jq(document).ready(function() {
  638. loadTags();
  639. // load hierarchy for each hierarchy box
  640. $jq('div.hierarchy').livequery(function() {
  641. var id = $jq(this).attr('id');
  642. loadHierarchy(id, $jq('#' + id).find('ol').eq(0));
  643. if (selectedResource == 'http://ns.softwiki.de/req/Requirement') {
  644. $jq('.resource-select.root').addClass('selected');
  645. }
  646. });
  647. // assign search function to hierarchy search field
  648. $jq('input.hierarchy-search-input').livequery('keyup', function() {
  649. filterHierarchy($jq(this).attr('id').replace('-search-input', ''));
  650. });
  651. $jq('.tree-node-toggle').livequery('click', function() {
  652. toggleTree($jq(this).attr('id'));
  653. });
  654. $jq('.tree-open').livequery(function() {
  655. if (!$jq(this).nextAll('ol').children().length) {
  656. var rootId = $jq(this).parents('div.window').attr('id');
  657. var targetOl = $jq(this).nextAll('ol');
  658. var entryUri = $jq(this).next('a').attr('about');
  659. targetOl.show();
  660. loadHierarchy(rootId, targetOl, entryUri);
  661. }
  662. });
  663. $jq('.resource-select').livequery('click', function() {
  664. // store new resource
  665. /*if (selectedResource == $jq(this).attr('about')) {
  666. selectedResource = 'http://ns.softwiki.de/req/Requirement';
  667. $jq('.resource-select.root').addClass('selected');
  668. $jq(this).removeClass('selected');
  669. } else {*/
  670. selectedResource = $jq(this).attr('about');
  671. $jq(".resource-select[@about="+$jq(this).attr('about')+"]").addClass('selected');
  672. //}
  673. // clear tags
  674. selectedTags = new Array();
  675. // update tags
  676. loadTags();
  677. // deselect all others
  678. $jq('.resource-select').each(function(i) {
  679. if ($jq(this).attr('about') != selectedResource) {
  680. $jq(this).removeClass('selected');
  681. }
  682. })
  683. // remove topic selector and container
  684. $jq('#rtopic-select-overlay').remove();
  685. $jq('#rtopic-tree-container').remove();
  686. // reload main window
  687. replaceWindow(owUriBase + "softwiki/reqlist/", "all=true&resources=" + getSoftWikiFrickelJson(false));
  688. // remove all other windows
  689. $jq("div.section-mainwindows").children("div.window").slice(1).remove();
  690. // alert('Reloading page: ' + owUriBase + 'softwiki/reqlist/...');
  691. selectedTags = new Array();
  692. });
  693. });
  694. function toggleTree(id) {
  695. var elem = $jq('#' + id);
  696. var entryUri = elem.next('a').attr('about');
  697. if (elem.is('.tree-open')) {
  698. elem.removeClass('tree-open').addClass('tree-closed');
  699. elem.nextAll('ol').slideUp('fast', function() {
  700. elem.nextAll('ol').children().remove();
  701. });
  702. // save node state in session
  703. setSessionVar('name=nodeState&nodeState[' + encodeURIComponent(entryUri) + ']=closed');
  704. } else {
  705. elem.removeClass('tree-closed').addClass('tree-open');
  706. // save node state in session
  707. setSessionVar('name=nodeState&nodeState[' + encodeURIComponent(entryUri) + ']=open');
  708. }
  709. }
  710. function loadHierarchy(id, target, entryUri) {
  711. target.addClass('is-processing');
  712. $jq('.resource-select.root').show();
  713. // load json params from dom tree
  714. eval($jq('#' + id).find('script').text());
  715. var url = owUriBase + 'service/gettreenodecontent/';
  716. if (typeof(entryUri) != 'undefined') {
  717. // url += '?r=' + encodeURIComponent(entryUri);
  718. hierarchyParams.r = entryUri;
  719. }
  720. if ($jq('#' + id).hasClass('javascript-on')) {
  721. hierarchyParams.javascript = true;
  722. }
  723. $jq.ajax({
  724. url: url,
  725. dataType: 'html',
  726. data: hierarchyParams,
  727. success: function(content) {
  728. if (target.children().length) {
  729. target.children().fadeOut(effectTime, function() {
  730. target.children().remove();
  731. target.prepend(content);
  732. target.removeClass('is-processing');
  733. });
  734. } else {
  735. target.prepend(content);
  736. target.removeClass('is-processing');
  737. }
  738. }
  739. });
  740. }
  741. // store the text length for the next round
  742. var lastLength = 0;
  743. var count = 0;
  744. function filterHierarchy(id) {
  745. var text = jQuery.trim($jq('#' + id + '-search-input').val());
  746. var localCount = ++count;
  747. // load json params from dom tree
  748. eval($jq('#' + id).find('script').text());
  749. window.setTimeout(function() {
  750. // count has not been changed by another call, i.e. no more text entered
  751. if (count == localCount) {
  752. if ((text.length >= autoCompleteMinChars)) {
  753. // enable javascript-only links
  754. if ($jq('#' + id).hasClass('javascript-on')) {
  755. hierarchyParams.javascript = true;
  756. }
  757. $jq('.resource-select.root').hide();
  758. var input = $jq('#' + id + '-search-input');
  759. var target = input.parents('.window').find('ol').eq(0);
  760. target.addClass('is-processing');
  761. $jq.ajax({
  762. url: owUriBase + 'service/gettreenodecontent/?s=' + text,
  763. dataType: 'html',
  764. data: hierarchyParams,
  765. success: function(content) {
  766. target.children().fadeOut(effectTime, function() {
  767. target.children().remove();
  768. target.removeClass('is-processing');
  769. if (jQuery.trim(content) != '') {
  770. target.prepend(content);
  771. } else {
  772. target.prepend('<p class="messagebox info">No matches!</p>');
  773. }
  774. });
  775. }
  776. });
  777. lastLength = text.length;
  778. } else if ((text.length < autoCompleteMinChars) && lastLength >= autoCompleteMinChars) {
  779. loadHierarchy(id, $jq('#' + id).find('ol').eq(0));
  780. $jq('.resource-select.root').show();
  781. lastLength = 0;
  782. }
  783. }
  784. }, autoCompleteDelay);
  785. }
  786. /* ------------------- SoftWiki-Frickel-Funktion -------------------- */
  787. // prepare json string
  788. function getSoftWikiFrickelJson(tagsOnly) {
  789. var json = '[';
  790. for (var i = 0; i < selectedTags.length; ++i) {
  791. json += '"' + encodeURIComponent(selectedTags[i]) + '",';
  792. }
  793. if (tagsOnly) {
  794. if (json.length==1) json+=']';
  795. else json = json.substr(0,json.length - 1)+']';
  796. } else {
  797. json += '"' + encodeURIComponent(selectedResource) + '"]';
  798. }
  799. return json;
  800. }
  801. /* ------------------- SoftWiki-File Management Functions -------------------- */
  802. // add existing file
  803. function swAddExistingFile(event) {
  804. if (typeof($jq("#requirement").attr("about")) != 'undefined') {
  805. if ($jq("div.section-mainwindows").children("div.window").size() == 1) {
  806. $jq("div.section-mainwindows").append("<div class='window'></div>");
  807. }
  808. var targetwin = $jq("div.section-mainwindows").children("div.window").eq(1);
  809. if (targetwin) {
  810. replaceWindow(owUriBase + "softwiki/file/", "type=exist", targetwin);
  811. }
  812. }
  813. event.stopPropagation();
  814. }
  815. // add new file
  816. function swAddNewFile(event) {
  817. if (typeof($jq("#requirement").attr("about")) != 'undefined') {
  818. if ($jq("div.section-mainwindows").children("div.window").size() == 1) {
  819. $jq("div.section-mainwindows").append("<div class='window is-processing'></div>");
  820. }
  821. var instance = $jq("#requirement").attr("about");
  822. targetwin = $jq("div.section-mainwindows").children("div.window").eq(1);
  823. $jq.get(owUriBase + "softwiki/file/?type=new", '' , function(data, textStatus) {
  824. targetwin.replaceWith(data);
  825. $jq("#swFileForm").submit( function () {
  826. var options = {
  827. url: owUriBase + 'resource/file/?r=' + instance ,
  828. success: swUploadFile ,
  829. type: 'post'
  830. };
  831. $jq(this).ajaxSubmit(options);
  832. return false;
  833. });
  834. });
  835. }
  836. event.stopPropagation();
  837. }
  838. // add file with about
  839. function swFile(event) {
  840. var $target = $jq(event.target);
  841. $target.toggleClass('selected');
  842. event.stopPropagation();
  843. }
  844. // On Submit of file dialogs
  845. function swSubmitFile(event) {
  846. var $target = $jq(event.target);
  847. var resources = new Array();
  848. $jq('.swFile').each(function () {
  849. if ($jq(this).hasClass('selected')) {
  850. //alert('File' + $jq(this).attr('about'));
  851. resources.push($jq(this).attr('about'));
  852. }
  853. });
  854. if ($jq('.swFile.selected').size() != 0 && typeof($jq("#requirement").attr("about")) != 'undefined') {
  855. var resourcesjson = "[";
  856. for (var i = 0; i<resources.length ;i++) {
  857. resourcesjson = resourcesjson + "\"" + resources[i] + "\" , ";
  858. }
  859. resourcesjson = resourcesjson.substr(0,(resourcesjson.length) - 3);
  860. resourcesjson += "]";
  861. var instance = $jq("#requirement").attr("about");
  862. $jq("div.section-mainwindows").children('div.window').eq(0).addClass('is-processing');
  863. //replaceWindow(owUriBase + "softwiki/view/","r=" + instance);
  864. $jq.get(owUriBase + "softwiki/file/", "type=add&resources=" + resourcesjson,
  865. function(data) {
  866. var msg = data;
  867. $jq.get(owUriBase + "softwiki/view/?r=" + instance,
  868. function (data) {
  869. $jq("div.section-mainwindows").html(data);
  870. $jq("div.section-mainwindows").children("div.window").
  871. children(".content").prepend(msg);
  872. showComments();
  873. });
  874. });
  875. } else {
  876. showComments();
  877. }
  878. event.stopPropagation();
  879. }
  880. //On new file upload
  881. function swUploadFile(responseText, statusText) {
  882. if (typeof($jq("#requirement").attr("about")) != 'undefined') {
  883. var instance = $jq("#requirement").attr("about");
  884. $jq("div.section-mainwindows").children('div.window').eq(0).addClass('is-processing');
  885. $jq.get(
  886. owUriBase + "softwiki/view/?r=" + instance,
  887. function (data) {
  888. $jq("div.section-mainwindows").html(data);
  889. $jq("div.section-mainwindows > div.window:first > div.content")
  890. .prepend(responseText);
  891. }
  892. );
  893. }
  894. }
  895. // Unlink event (delete relation from req to file)
  896. function swFileUnlink (event) {
  897. $jq("div.section-mainwindows").children("div.window").toggleClass("is-processing");
  898. var resourcesjson = "[ \"" + $jq(event.target).parent().children().attr("about") + "\" ]";
  899. var instance = $jq("#requirement").attr("about");
  900. $jq.get(
  901. owUriBase + "softwiki/file/","type=unlink&resources=" + resourcesjson,
  902. function(data) {
  903. var msg = data;
  904. $jq.get(owUriBase + "softwiki/view/?r=" + instance,
  905. function (data) {
  906. $jq("div.section-mainwindows").html(data);
  907. $jq("div.section-mainwindows").children("div.window").
  908. children(".content").prepend(msg);
  909. });
  910. });
  911. event.stopPropagation();
  912. }
  913. /* ------------------- SoftWiki-Decision Management Functions -------------------- */
  914. // add existing Decision
  915. function swAddExistingDec(event) {
  916. if (typeof($jq("#requirement").attr("about")) != 'undefined') {
  917. if ($jq("div.section-mainwindows").children("div.window").size() == 1) {
  918. $jq("div.section-mainwindows").append("<div class='window'></div>");
  919. }
  920. var targetwin = $jq("div.section-mainwindows").children("div.window").eq(1);
  921. if (targetwin) {
  922. replaceWindow(owUriBase + "softwiki/dec/", "type=exist", targetwin);
  923. }
  924. }
  925. event.stopPropagation();
  926. }
  927. // add new Decision
  928. function swAddNewDec(event) {
  929. if (typeof($jq("#requirement").attr("about")) != 'undefined') {
  930. if ($jq("div.section-mainwindows").children("div.window").size() == 1) {
  931. $jq("div.section-mainwindows").append("<div class='window is-processing'></div>");
  932. }
  933. var instance = $jq("#requirement").attr("about");
  934. targetwin = $jq("div.section-mainwindows").children("div.window").eq(1);
  935. $jq.get(owUriBase + "softwiki/dec/?type=new", '' , function(data, textStatus) {
  936. targetwin.replaceWith(data);
  937. $jq("#swDecForm").submit( function () {
  938. var options = {
  939. url: owUriBase + 'resource/dec/?r=' + instance ,
  940. success: swUploadDec ,
  941. type: 'post'
  942. };
  943. $jq(this).ajaxSubmit(options);
  944. return false;
  945. });
  946. });
  947. }
  948. event.stopPropagation();
  949. }
  950. // add decision with about
  951. function swDec(event) {
  952. var $target = $jq(event.target);
  953. $target.toggleClass('selected');
  954. event.stopPropagation();
  955. }
  956. // On Submit of decision dialogs
  957. function swSubmitDec(event) {
  958. var $target = $jq(event.target);
  959. var resources = new Array();
  960. $jq('.swDec').each(function () {
  961. if ($jq(this).hasClass('selected')) {
  962. //alert('Dec' + $jq(this).attr('about'));
  963. resources.push($jq(this).attr('about'));
  964. }
  965. });
  966. if ($jq('.swDec.selected').size() != 0 && typeof($jq("#requirement").attr("about")) != 'undefined') {
  967. var resourcesjson = "[";
  968. for (var i = 0; i<resources.length ;i++) {
  969. resourcesjson = resourcesjson + "\"" + resources[i] + "\" , ";
  970. }
  971. resourcesjson = resourcesjson.substr(0,(resourcesjson.length) - 3);
  972. resourcesjson += "]";
  973. var instance = $jq("#requirement").attr("about");
  974. $jq("div.section-mainwindows").children('div.window').eq(0).addClass('is-processing');
  975. //replaceWindow(owUriBase + "softwiki/view/","r=" + instance);
  976. $jq.get(owUriBase + "softwiki/dec/", "type=add&resources=" + resourcesjson,
  977. function(data) {
  978. var msg = data;
  979. $jq.get(owUriBase + "softwiki/view/?r=" + instance,
  980. function (data) {
  981. $jq("div.section-mainwindows").html(data);
  982. $jq("div.section-mainwindows").children("div.window").
  983. children(".content").prepend(msg);
  984. showComments();
  985. });
  986. });
  987. } else {
  988. showComments();
  989. }
  990. event.stopPropagation();
  991. }
  992. //On new decision upload
  993. function swUploadDec(responseText, statusText) {
  994. if (typeof($jq("#requirement").attr("about")) != 'undefined') {
  995. var instance = $jq("#requirement").attr("about");
  996. $jq("div.section-mainwindows").children('div.window').eq(0).addClass('is-processing');
  997. $jq.get(
  998. owUriBase + "softwiki/view/?r=" + instance,
  999. function (data) {
  1000. $jq("div.section-mainwindows").html(data);
  1001. $jq("div.section-mainwindows > div.window:first > div.content")
  1002. .prepend(responseText);
  1003. }
  1004. );
  1005. }
  1006. }
  1007. // Unlink event (delete relation from req to decision)
  1008. function swDecUnlink (event) {
  1009. $jq("div.section-mainwindows").children("div.window").toggleClass("is-processing");
  1010. var resourcesjson = "[ \"" + $jq(event.target).attr("about") + "\" ]";
  1011. var instance = $jq("#requirement").attr("about");
  1012. $jq.get(
  1013. owUriBase + "softwiki/dec/","type=unlink&resources=" + resourcesjson,
  1014. function(data) {
  1015. var msg = data;
  1016. $jq.get(owUriBase + "softwiki/view/?r=" + instance,
  1017. function (data) {
  1018. $jq("div.section-mainwindows").html(data);
  1019. $jq("div.section-mainwindows").children("div.window").
  1020. children(".content").prepend(msg);
  1021. });
  1022. });
  1023. event.stopPropagation();
  1024. }
  1025. // Top link event (top relation from req to decision)
  1026. function swDecTop (event) {
  1027. $jq("div.section-mainwindows").children("div.window").toggleClass("is-processing");
  1028. var resourcesjson = "[ \"" + $jq(event.target).attr("about") + "\" ]";
  1029. var instance = $jq("#requirement").attr("about");
  1030. $jq.get(
  1031. owUriBase + "softwiki/dec/","type=top&resources=" + resourcesjson,
  1032. function(data) {
  1033. var msg = data;
  1034. $jq.get(owUriBase + "softwiki/view/?r=" + instance,
  1035. function (data) {
  1036. $jq("div.section-mainwindows").html(data);
  1037. $jq("div.section-mainwindows").children("div.window").
  1038. children(".content").prepend(msg);
  1039. });
  1040. });
  1041. event.stopPropagation();
  1042. }
  1043. // Down link event (delete relation from req to decision)
  1044. function swDecDown (event) {
  1045. $jq("div.section-mainwindows").children("div.window").toggleClass("is-processing");
  1046. var resourcesjson = "[ \"" + $jq(event.target).attr("about") + "\" ]";
  1047. var instance = $jq("#requirement").attr("about");
  1048. $jq.get(
  1049. owUriBase + "softwiki/dec/","type=down&resources=" + resourcesjson,
  1050. function(data) {
  1051. var msg = data;
  1052. $jq.get(owUriBase + "softwiki/view/?r=" + instance,
  1053. function (data) {
  1054. $jq("div.section-mainwindows").html(data);
  1055. $jq("div.section-mainwindows").children("div.window").
  1056. children(".content").prepend(msg);
  1057. });
  1058. });
  1059. event.stopPropagation();
  1060. }
  1061. // Un-Top link event (top relation from req to decision)
  1062. function swDecUnTop (event) {
  1063. $jq("div.section-mainwindows").children("div.window").toggleClass("is-processing");
  1064. var resourcesjson = "[ \"" + $jq(event.target).attr("about") + "\" ]";
  1065. var instance = $jq("#requirement").attr("about");
  1066. $jq.get(
  1067. owUriBase + "softwiki/dec/","type=untop&resources=" + resourcesjson,
  1068. function(data) {
  1069. var msg = data;
  1070. $jq.get(owUriBase + "softwiki/view/?r=" + instance,
  1071. function (data) {
  1072. $jq("div.section-mainwindows").html(data);
  1073. $jq("div.section-mainwindows").children("div.window").
  1074. children(".content").prepend(msg);
  1075. });
  1076. });
  1077. event.stopPropagation();
  1078. }
  1079. // Un-Down link event (down relation from req to decision)
  1080. function swDecUnDown (event) {
  1081. $jq("div.section-mainwindows").children("div.window").toggleClass("is-processing");
  1082. var resourcesjson = "[ \"" + $jq(event.target).attr("about") + "\" ]";
  1083. var instance = $jq("#requirement").attr("about");
  1084. $jq.get(
  1085. owUriBase + "softwiki/dec/","type=undown&resources=" + resourcesjson,
  1086. function(data) {
  1087. var msg = data;
  1088. $jq.get(owUriBase + "softwiki/view/?r=" + instance,
  1089. function (data) {
  1090. $jq("div.section-mainwindows").html(data);
  1091. $jq("div.section-mainwindows").children("div.window").
  1092. children(".content").prepend(msg);
  1093. });
  1094. });
  1095. event.stopPropagation();
  1096. }
  1097. // Link event (add relation from req to decision)
  1098. function swDecLink (event) {
  1099. $jq("div.section-mainwindows").children("div.window").toggleClass("is-processing");
  1100. var resourcesjson = "[ \"" + $jq(event.target).attr("about") + "\" ]";
  1101. var instance = $jq("#requirement").attr("about");
  1102. //alert(resourcesjson + ' ' + instance);
  1103. $jq.get(
  1104. owUriBase + "softwiki/dec/","type=link&resources=" + resourcesjson,
  1105. function(data) {
  1106. var msg = data;
  1107. $jq.get(owUriBase + "softwiki/view/?r=" + instance,
  1108. function (data) {
  1109. $jq("div.section-mainwindows").html(data);
  1110. $jq("div.section-mainwindows").children("div.window").
  1111. children(".content").prepend(msg);
  1112. });
  1113. });
  1114. event.stopPropagation();
  1115. }
  1116. /* -------------------------- Hierarchy Dropdown --------------------------- */
  1117. $jq(document).ready(function() {
  1118. $jq('#rtopic-select').livequery(function() {
  1119. $jq(this).dropdownHierarchy({
  1120. url: owUriBase + 'service/gettreenodecontent/',
  1121. nodeType: hierarchyParams.nt,
  1122. subRelation: hierarchyParams.sr,
  1123. instanceRelation: hierarchyParams.ir
  1124. });
  1125. });
  1126. })
  1127. function repositionOverlay() {
  1128. $jq('#rtopic-select').css('width', '20em');
  1129. var offset = $jq('#rtopic-select').offset();
  1130. $jq('#rtopic-select-overlay').css('top', offset.top + 'px');
  1131. $jq('#rtopic-select-overlay').css('width', '16em');
  1132. $jq('#rtopic-tree-container').css('top', offset.top + $jq('#rtopic-select').height() + 3 + 'px');
  1133. $jq('#rtopic-tree-container').css('width', '20em');
  1134. if ($jq.browser.msie && $jq.browser.version == '6.0') {
  1135. $jq('#rtopic-select-overlay-iframe')
  1136. .css('top', offset.top + 'px')
  1137. .css('width', '16em');
  1138. }
  1139. }
  1140. jQuery.fn.dropdownHierarchy = function(settings) {
  1141. return this.each(function() {
  1142. var select = $jq(this);
  1143. var offset = select.offset();
  1144. if (select.attr('disabled')) {
  1145. $jq('#rtopic-select-overlay').addClass('disabled');
  1146. }
  1147. $jq('body').append('<div id="rtopic-select-overlay"></div><div id="rtopic-tree-container"></div>');
  1148. $jq('#rtopic-select-overlay')
  1149. .css('position', 'absolute')
  1150. .css('background-image', 'url("' + owUriBase + 'plugins/SoftWiki/trans.gif")')
  1151. .css('background-repeat', 'repeat')
  1152. .css('left', offset.left + 'px')
  1153. .css('top', offset.top + 'px')
  1154. .css('width', '20em')
  1155. .css('height', select.height() + 3 + 'px')
  1156. .css('padding-left', '0.5em')
  1157. .css('zIndex', '101')
  1158. .width(select.width());
  1159. $jq('#rtopic-tree-container')
  1160. .css('position', 'absolute')
  1161. .css('border', '1px solid #ccc')
  1162. .css('display', 'none')
  1163. .css('left', offset.left + 'px')
  1164. .css('top', offset.top + select.height() + 3 + 'px')
  1165. .css('height', '20em')
  1166. .css('font-size', '0.8em')
  1167. .css('opacity', '0.96')
  1168. .css('overflow', 'auto')
  1169. .css('background-color', '#fff')
  1170. .css('zIndex', '101')
  1171. .width(select.width() - 2);
  1172. // IE6 specific hack
  1173. if ($jq.browser.msie && $jq.browser.version == '6.0') {
  1174. $jq('body').append('<iframe id="rtopic-select-overlay-iframe"></iframe>');
  1175. $jq('#rtopic-select-overlay-iframe')
  1176. .css('position', 'absolute')
  1177. .css('top', offset.top + 'px')
  1178. .css('left', offset.left + 'px')
  1179. .css('height', select.height() + 3 + 'px')
  1180. .css('width', '16em')
  1181. .css('zIndex', '100')
  1182. .css('filter', 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)');
  1183. $jq('#rtopic-select-overlay')
  1184. .css('background-image', 'url("' + owUriBase + 'plugins/SoftWiki/select.gif")')
  1185. .css('background-repeat', 'no-repeat')
  1186. .css('width', '16em');
  1187. }
  1188. jQuery('.tree-item').livequery('click', function(event) {
  1189. select.find('option').remove();
  1190. var text = jQuery.trim(jQuery(this).text().replace(/\(\d\)/, ''));
  1191. select.append('<option value="' + jQuery(this).attr('about') + '" selected="selected">' + text + '</option>');
  1192. // IE6 specific hack
  1193. if ($jq.browser.msie && $jq.browser.version == '6.0') {
  1194. $jq('#rtopic-select-overlay').text(text);
  1195. }
  1196. jQuery('#rtopic-tree-container').fadeOut(effectTime);
  1197. event.stopPropagation();
  1198. })
  1199. jQuery('#rtopic-tree-container a').livequery('mouseover', function(event) {
  1200. jQuery(this).addClass('selected');
  1201. })
  1202. jQuery('#rtopic-tree-container a').livequery('mouseout', function(event) {
  1203. if (

Large files files are truncated, but you can click here to view the full file