/extensions/tagging/exploretags.js

https://code.google.com/p/ontowiki/ · JavaScript · 249 lines · 171 code · 29 blank · 49 comment · 44 complexity · 264fb17f8a316be80cd6be873c19c88b MD5 · raw file

  1. /**
  2. * This file is part of the tagging extension for OntoWiki
  3. *
  4. * @author Atanas Alexandrov <sirakov@gmail.com>
  5. * @author Sebastian Dietzold <dietzold@informatik.uni-leipzig.de>
  6. * @copyright Copyright (c) 2009, {@link http://aksw.org AKSW}
  7. * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
  8. * @version $Id: $
  9. *
  10. */
  11. function reloadExploreTagsModule(param){
  12. taglistContainer.addClass("is-processing");
  13. var checkedparam = (typeof param != 'undefined') ? param : "";
  14. taglistContainer.load(
  15. urlBase+"tagging/explore" + checkedparam,
  16. function() {
  17. taglistContainer.removeClass("is-processing");
  18. }
  19. );
  20. }
  21. /**
  22. * The main document.ready assignments and code
  23. */
  24. $(document).ready(function() {
  25. taglistContainer = $('#exploretags-content');
  26. taggedResource = taglistContainer.attr('about');
  27. taggingInput = $("#exploretags-content");
  28. taglistContainer.droppable({
  29. accept: '.show-property',
  30. scope: 'Resource',
  31. activeClass: 'ui-droppable-accepted-destination',
  32. hoverClass: 'ui-droppable-hovered',
  33. drop:
  34. function(event, ui) {
  35. var data = {
  36. "uri" : $(ui.draggable).attr("about"),
  37. "label" : $(ui.draggable).attr('title'),
  38. "isInverse" : $(ui.draggable).hasClass("InverseProperty")
  39. }
  40. var getUri = urlBase+"service/session?method=setArrayValue&name=cloudproperties&valueIsSerialized=true";
  41. $.post(getUri,
  42. {
  43. "key": $(ui.draggable).attr("about"),
  44. "value" : $.toJSON(data)
  45. }, //as post because of possible size
  46. function(res) {
  47. if(res==""){
  48. reloadExploreTagsModule();
  49. } else alert('could not add cloudproperty\nReason:\n'+res)
  50. })
  51. }});
  52. taggingUrl = urlBase + 'tagging/';
  53. taggingAction('exploretags'); // make ajax request after pageload
  54. $('.cloudvalue').live('click', function(event) {
  55. toggleTag(this);
  56. });
  57. $('.delete-cloudproperty').live('click', function(event) {
  58. $.post(urlBase+"service/session?name=cloudproperties&method=unsetArrayKey",
  59. {"key" : $(this).attr("about")},
  60. function(res){
  61. if(res==""){
  62. reloadExploreTagsModule();
  63. } else alert('could not remove cloudproperty\nReason:\n'+res)
  64. }
  65. );
  66. });
  67. // at the moment, we refresh the complete page, so we do not need callbacks here
  68. //filter.addCallback(function(filter){ selectTags('exploretags') })
  69. });
  70. /**
  71. * set selected tags
  72. */
  73. function toggleTag(tag) {
  74. var tagvalue = $(tag).attr('value');
  75. var inverse = $(tag).parent().parent().hasClass("InverseProperty");
  76. var proplabel = $(tag).parent().parent().attr('title');
  77. var type = $(tag).attr('type');
  78. var datatype = $(tag).attr('datatype');
  79. var language = $(tag).attr('language');
  80. if(type=="typed-literal"){
  81. var literaltype = datatype;
  82. } else if(language!=""){
  83. var literaltype = language;
  84. }
  85. //propertyuri = 'http://www.holygoat.co.uk/owl/redwood/0.1/tags/taggedWithTag';
  86. propertyuri = $(tag).attr('cloudproperty');
  87. filterid = 'explore-'+(inverse ? "inverse" : "normal")+'-'+tagvalue+'-'+propertyuri;
  88. //alert(filter.filters[filterid]);
  89. if(!filter.filterExists(filterid)) {
  90. // id, property, isInverse, propertyLabel, filter, value1, value2, valuetype, literaltype, callback, hidden
  91. $(tag).addClass("selected");
  92. filter.add(
  93. filterid,
  94. propertyuri,
  95. inverse,
  96. proplabel,
  97. 'equals',
  98. tagvalue,
  99. null,
  100. type,
  101. literaltype,
  102. function(){},
  103. false);
  104. } else {
  105. filter.remove(
  106. filterid,
  107. function(){$(tag).removeClass("selected");}
  108. );
  109. }
  110. }
  111. /**
  112. * set selected tags
  113. */
  114. function selectTags(type) {
  115. // first we set the processing status
  116. taggingInput.addClass('is-processing');
  117. var allSelectedTags = "";
  118. var i = 0;
  119. $('.select').each(function(){
  120. allSelectedTags += "\""+i+"\" : \""+$(this).attr('about')+"\" , ";
  121. i++;
  122. });
  123. // remove the last comma and build the
  124. // complete selectedTags parameter
  125. allSelectedTags = "{"+allSelectedTags.substring(0,allSelectedTags.lastIndexOf(',')-1)+"}";
  126. params = {selectedTags: allSelectedTags};
  127. /* Debug
  128. if (window.console){
  129. window.console.log(allSelectedTags);
  130. }
  131. */
  132. $.post(taggingUrl + type, params,
  133. function (data) {
  134. taglistContainer.empty();
  135. taglistContainer.append(data);
  136. // remove the processing status
  137. taggingInput.removeClass('is-processing');
  138. }
  139. );
  140. return true;
  141. }
  142. /**
  143. * request a tagging action
  144. */
  145. function taggingAction(type, typeparam) {
  146. // first we set the processing status
  147. taggingInput.addClass('is-processing');
  148. if (type == 'exploretags') {
  149. params = { resources: taggedResource };
  150. }
  151. // reset selectedTags - not working
  152. else if (type == 'exploretags' && typeparam == 'reset') {
  153. $('.select').each(function(){
  154. $(this).toggleClass("select");
  155. });
  156. params = {resources: taggedResource, selectedTags: '' };
  157. }
  158. // sort by name - not working
  159. else if (type == 'exploretags' && typeparam == 'name') {
  160. params = {sort : "name" };
  161. }
  162. // sort by frequency - not working
  163. else if (type == 'exploretags' && typeparam == 'count') {
  164. params = {sort : "count" };
  165. }
  166. // show specific number of tags in the tagcloud - not working
  167. else if (type == 'exploretags' && typeparam > 4) {
  168. params = {count: typeparam };
  169. } else {
  170. taggingInput.removeClass('is-processing');
  171. return false;
  172. }
  173. //TODO fixme
  174. if(type =="exploretags"){
  175. type ="explore";
  176. }
  177. $.post(taggingUrl + type, params,
  178. function (data) {
  179. taglistContainer.empty();
  180. taglistContainer.append(data);
  181. // remove the processing status
  182. taggingInput.removeClass('is-processing');
  183. }
  184. );
  185. return true;
  186. }
  187. /**
  188. * Deselect tags
  189. */
  190. function resetSelectedTags() {
  191. for(key in filter.filters){
  192. if(key.substr(0, 7) == "explore"){
  193. filter.remove(key);
  194. } else alert(key);
  195. }
  196. //$('.cloudvalue').removeClass("selected");
  197. reloadExploreTagsModule();
  198. }
  199. function resetExploreTags() {
  200. $.post(urlBase+"service/session?name=cloudproperties&method=unsetArray",
  201. function(res){
  202. if(res==""){
  203. reloadExploreTagsModule();
  204. } else alert('could not remove cloudproperties\nReason:\n'+res)
  205. }
  206. );
  207. }
  208. // show number of tags
  209. function count(number) {
  210. reloadExploreTagsModule("?count=" + number);
  211. }
  212. // sort tagcloud
  213. function sortTagCloud(sortparameter) {
  214. if (sortparameter == 1) {
  215. param = "?sort=name" ;
  216. } else if (sortparameter == 2) {
  217. param = "?sort=count" ;
  218. }
  219. reloadExploreTagsModule(param);
  220. }