document_questions.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. var eo_creation_url;
  2. $(document).ready(function () {
  3. "use strict";
  4. $(document).foundation();
  5. $(".toolbox label input").each(function () {
  6. var $this = $(this);
  7. $this.parent().addClass("toolbox-option-{0}".format($this.val()));
  8. });
  9. });
  10. var app = window.angular.module(
  11. 'labelingApp',
  12. ['ngResource', 'ngRoute', 'ngCookies']
  13. ).run(
  14. function ($http, $cookies) {
  15. $http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
  16. // Add the following two lines
  17. $http.defaults.xsrfCookieName = 'csrftoken';
  18. $http.defaults.xsrfHeaderName = 'X-CSRFToken';
  19. }
  20. );
  21. app.factory('EntityOccurrence', ['$resource',
  22. function ($resource) {
  23. return $resource('/corpus/crud/entity_occurrence/', {'pk': '@pk'}, {});
  24. }
  25. ]);
  26. app.factory('Entity', ['$resource',
  27. function ($resource) {
  28. return $resource('/corpus/crud/entity/', {'pk': '@pk'}, {});
  29. }
  30. ]);
  31. app.directive('ngRightClick', function ($parse) {
  32. return function ($scope, element, attrs) {
  33. var fn = $parse(attrs.ngRightClick);
  34. element.bind('contextmenu', function (event) {
  35. event.preventDefault();
  36. fn($scope, {$event: event});
  37. });
  38. };
  39. });
  40. app.controller('QuestionsController', ['$scope', 'EntityOccurrence', 'Entity',
  41. function ($scope, EntityOccurrence, Entity) {
  42. "use strict";
  43. // ### Attributes ###
  44. $scope.eo_selected = undefined; // Id of the selected occurrence
  45. // Publish into the scope the variables defined globally
  46. $scope.eos = window.eos;
  47. $scope.forms = window.forms;
  48. $scope.relations = window.relations;
  49. $scope.current_tool = window.initial_tool;
  50. $scope.different_kind = window.different_kind;
  51. $scope.question_options = window.question_options;
  52. $scope.other_judges_labels = window.other_judges_labels;
  53. $scope.arrows = {};
  54. $scope.eo_edition_modal = {};
  55. $scope.eo_creation_modal = {};
  56. $scope.metadata_visible = "pos";
  57. $scope.interaction_activated = true;
  58. $(document).ready(function () {
  59. $scope.$segments = $(".segments");
  60. $scope.$svg = $("svg");
  61. $scope.svg = $scope.$svg[0];
  62. $(window).resize($scope.update_relations_arrows);
  63. $("body").keypress(function (event) {
  64. var $toolbox_options = $(".toolbox li input");
  65. var index = event.which - 49;
  66. if (index >= 0 && index <= 5) {
  67. $scope.current_tool = $scope.question_options[index];
  68. $($toolbox_options[index]).prop("checked", "checked");
  69. }
  70. });
  71. setTimeout($scope.update_relations_arrows, 300);
  72. $(".rich-token").on("click", function (event, stop) {
  73. stop = stop === undefined ? true : stop;
  74. if (stop) {
  75. event.preventDefault();
  76. event.stopPropagation();
  77. }
  78. });
  79. $(".eo-submenu").on("click", $scope.on_eo_submenu_click);
  80. $(".eo-submenu").mouseover($scope.highlight_eo_tokens);
  81. $(".eo-submenu").mouseout($scope.highlight_eo_tokens);
  82. $(".judge-answers-wrapper").change(function(){
  83. var $this = $(this);
  84. var selected = $this.val();
  85. if(selected === "me"){
  86. $scope.interaction_activated = true;
  87. $scope.update_relations_arrows();
  88. } else {
  89. $scope.interaction_activated = false;
  90. $scope.draw_judge_answers(selected);
  91. }
  92. });
  93. $(".entity-occurrence").mouseover(function () {
  94. var $eo = $(this);
  95. $scope.on_eo_mouseover($eo, false);
  96. });
  97. $(".entity-occurrence").mouseout(function () {
  98. var $eo = $(this);
  99. $scope.on_eo_mouseover($eo, true);
  100. });
  101. // EO Creation modal
  102. $scope.eo_creation_modal.elem = $('#eo-creation-modal');
  103. $scope.eo_creation_modal.elem.find('a.save').bind('click', function () {
  104. $scope.eo_creation_modal.submit();
  105. });
  106. $scope.eo_creation_modal.elem.find('a.cancel').bind('click', function () {
  107. $scope.eo_creation_modal.elem.foundation('reveal', 'close');
  108. });
  109. // EO Edition modal
  110. $scope.eo_edition_modal.elem = $('#eo-edition-modal');
  111. $scope.eo_edition_modal.elem.find('a.cancel').bind('click', function () {
  112. $scope.eo_edition_modal.elem.foundation('reveal', 'close');
  113. });
  114. $scope.eo_edition_modal.elem.find('a.save').bind('click', function () {
  115. $scope.eo_edition_modal.submit();
  116. });
  117. $scope.eo_edition_modal.elem.find('a.remove-eo-ask').bind(
  118. 'click', $scope.eo_edition_modal.remove_eo_ask
  119. );
  120. $scope.eo_edition_modal.elem.find('a.remove-eo-confirm').bind(
  121. 'click', $scope.eo_edition_modal.remove_eo_confirm
  122. );
  123. $scope.eo_edition_modal.elem.find('a.remove-eo-confirm-all').bind(
  124. 'click', $scope.eo_edition_modal.remove_eo_confirm_all
  125. );
  126. $scope.eo_edition_modal.elem.find('a.remove-eo-cancel').bind(
  127. 'click', $scope.eo_edition_modal.remove_eo_cancel
  128. );
  129. });
  130. // ### Methods ###
  131. $scope.clean_all_arrows = function () {
  132. // Remove all arrows before re-drawing
  133. $($scope.svg).find("path").each(function () {
  134. var $elem = $(this);
  135. if ($elem.parent("marker").length === 0) {
  136. $scope.svg.removeChild($elem[0]);
  137. }
  138. });
  139. $scope.arrows = {};
  140. };
  141. $scope.update_relations_arrows = function () {
  142. // Update width and height of the svg element
  143. $scope.$svg.attr("width", $scope.$segments.width());
  144. $scope.$svg.attr("height", $scope.$segments.height() + 100);
  145. $scope.clean_all_arrows();
  146. var data = [];
  147. for (var i in $scope.relations) {
  148. if ($scope.relations.hasOwnProperty(i)) {
  149. var rel_obj = $scope.relations[i];
  150. var path = $scope.calculate_arrow_string(
  151. rel_obj.relation[0],
  152. rel_obj.relation[1],
  153. $scope.forms[rel_obj.form_id]
  154. );
  155. $scope.arrows[rel_obj.form_id] = path;
  156. }
  157. }
  158. };
  159. $scope.set_selectables = function (value) {
  160. // Sets the value for selectable on all entity occurrences
  161. for (var i in $scope.eos) {
  162. if ($scope.eos.hasOwnProperty(i)) {
  163. $scope.eos[i].selectable = value;
  164. }
  165. }
  166. };
  167. $scope.eo_click = function (ids) {
  168. // Handles only left click
  169. if(event.button !== 0) { return; }
  170. // Handles only the case of 1 id, if it has
  171. // more than one, it shows the menu
  172. if (ids.length === 1) {
  173. var id = ids[0];
  174. $scope.handle_click_on_eo(id);
  175. }
  176. };
  177. $scope.on_eo_submenu_click = function (event) {
  178. event.preventDefault();
  179. var $this = $(this);
  180. var eo_id = $this.data("eo-id");
  181. $scope.handle_click_on_eo(eo_id);
  182. $scope.$apply();
  183. };
  184. $scope.handle_click_on_eo = function (id) {
  185. var eo = $scope.eos[id];
  186. // Not selectable
  187. if (!eo || !eo.selectable) { return; }
  188. // If interaction disabled, do nothing
  189. if (!$scope.interaction_activated) {
  190. var $wrapper = $(".judge-answers-wrapper");
  191. $wrapper.addClass("shake shake-constant shake-rotate");
  192. setTimeout(function(){ $wrapper.removeClass("shake"); }, 800);
  193. return;
  194. }
  195. if ($scope.eo_selected === undefined) {
  196. // Marking as selected
  197. $scope.eo_first_click(id);
  198. } else {
  199. $scope.eo_second_click(id);
  200. }
  201. };
  202. $scope.on_eo_mouseover = function ($eo, mouseout) {
  203. // If interaction disabled, do nothing
  204. if (!$scope.interaction_activated) { return; }
  205. var eo_id = $eo.data("eo-id");
  206. mouseout = mouseout || false;
  207. for (var i in $scope.relations) {
  208. if ($scope.relations.hasOwnProperty(i)) {
  209. var rel_obj = $scope.relations[i];
  210. if (rel_obj.relation.indexOf(eo_id) === -1) {
  211. var arrow = $scope.arrows[rel_obj.form_id];
  212. if (mouseout) {
  213. arrow.style.opacity = "";
  214. } else {
  215. arrow.style.opacity = ".15";
  216. }
  217. }
  218. }
  219. }
  220. $(".eo-{0}".format(eo_id)).each(function () {
  221. var $this = $(this);
  222. $this.toggleClass("highlight");
  223. });
  224. };
  225. $scope.highlight_relation = function () {
  226. var $this = $(this);
  227. var toggle = $this.data("toggle");
  228. var rel_id = $this.data("relation-id");
  229. var arrow = $scope.arrows[rel_id];
  230. if (toggle) {
  231. $this.data("toggle", false);
  232. arrow.style.strokeWidth = "";
  233. } else {
  234. $this.data("toggle", true);
  235. arrow.style.strokeWidth = "4px";
  236. }
  237. };
  238. $scope.eo_first_click = function (id) {
  239. var eo = $scope.eos[id];
  240. $scope.eo_selected = id;
  241. $scope.set_selectables(false);
  242. eo.selectable = true;
  243. eo.selected = true;
  244. // Calculate wich ones must be selectable
  245. for (var i in $scope.relations) {
  246. if ($scope.relations.hasOwnProperty(i)) {
  247. var rel = $scope.relations[i];
  248. var rel_index = rel.relation.indexOf(id);
  249. if (rel_index >= 0) {
  250. var eo_id = $scope.relations[i].relation[(rel_index + 1) % 2];
  251. $scope.eos[eo_id].selectable = true;
  252. }
  253. }
  254. }
  255. };
  256. $scope.eo_second_click = function (id) {
  257. if ($scope.eo_selected === id) {
  258. // You're de-selecting the one you've just selected
  259. $scope.eos[id].selected = false;
  260. } else {
  261. var eo_id1 = $scope.eo_selected;
  262. var eo_id2 = id;
  263. for (var i in $scope.relations) {
  264. if ($scope.relations.hasOwnProperty(i)) {
  265. var rel = $scope.relations[i];
  266. var eo_rel_index1 = rel.relation.indexOf(eo_id1);
  267. var eo_rel_index2 = rel.relation.indexOf(eo_id2);
  268. var order_check = $scope.different_kind || eo_rel_index1 < eo_rel_index2;
  269. if (eo_rel_index1 >= 0 && eo_rel_index2 >= 0 && order_check) {
  270. var form_value = $scope.forms[rel.form_id];
  271. var new_value = form_value ? "": $scope.current_tool;
  272. $scope.forms[rel.form_id] = new_value;
  273. $scope.add_or_remove_arrow(
  274. rel.relation[0], rel.relation[1],
  275. new_value, rel.form_id
  276. );
  277. $scope.eos[eo_id1].selected = false;
  278. $scope.eos[eo_id2].selected = false;
  279. }
  280. }
  281. }
  282. }
  283. $scope.set_selectables(true);
  284. $scope.eo_selected = undefined;
  285. };
  286. $scope.add_or_remove_arrow = function (eo_id1, eo_id2, value, form_id) {
  287. var path;
  288. if (value === null || value === "") {
  289. path = $scope.arrows[form_id];
  290. var $prev_arrow = $(".prev-relation-{0}".format(form_id));
  291. if ($prev_arrow.length > 0) {
  292. $prev_arrow.remove();
  293. }
  294. if (path !== undefined) {
  295. $scope.svg.removeChild(path);
  296. }
  297. } else {
  298. path = $scope.calculate_arrow_string(eo_id1, eo_id2, value);
  299. $scope.arrows[form_id] = path;
  300. }
  301. };
  302. $scope.calculate_arrow_string = function (eo_id1, eo_id2, value, alternative) {
  303. alternative = alternative || false;
  304. var path;
  305. // Curve configuration
  306. var curve_distance = 25;
  307. var y_offset = 10;
  308. if (alternative) {
  309. curve_distance *= 1.5;
  310. }
  311. // Entity occurrences
  312. var $eo1 = $(".eo-" + eo_id1);
  313. var $eo2 = $(".eo-" + eo_id2);
  314. // Positions
  315. var eo1_pos_top = $eo1.offset().top - $scope.$svg.offset().top;
  316. var eo1_pos_left = $eo1.offset().left - $scope.$svg.offset().left;
  317. var eo2_pos_top = $eo2.offset().top - $scope.$svg.offset().top;
  318. var eo2_pos_left = $eo2.offset().left - $scope.$svg.offset().left;
  319. // Corrected positions
  320. var eo1_pos_shifted_left = eo1_pos_left + $eo1.width() / 4;
  321. var eo1_pos_shifted_top = eo1_pos_top - y_offset;
  322. var eo2_pos_shifted_left = eo2_pos_left + $eo2.width() / 4;
  323. var eo2_pos_shifted_top = eo2_pos_top - y_offset;
  324. // Format should be:
  325. // M<x1>,<y1> C<x1>,<y1 + distance> <x2>,<y2 + distance> <x2>,<y2>
  326. var curve_string = "M{0},{1} C{0},{4} {2},{5} {2},{3}".format(
  327. Math.round(eo1_pos_shifted_left), // {0}
  328. Math.round(eo1_pos_shifted_top), // {1}
  329. Math.round(eo2_pos_shifted_left), // {2}
  330. Math.round(eo2_pos_shifted_top), // {3}
  331. Math.round(eo1_pos_shifted_top - curve_distance), // {4}
  332. Math.round(eo2_pos_shifted_top - curve_distance) // {5}
  333. );
  334. path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  335. path.setAttribute("class", 'arrow arrow_{0}'.format(value));
  336. path.setAttribute("style", 'marker-end: url(#arrow-point-{0});'.format(
  337. value
  338. ));
  339. path.setAttribute("d", curve_string);
  340. $scope.svg.appendChild(path);
  341. return path;
  342. };
  343. // ### Entity Occurrence Modification methods (and modal) ###
  344. $scope.token_context_menu = function (token_id) {
  345. var $dropdown = $("#token-edition-dropdown");
  346. var $token = $(".rich-token-" + token_id);
  347. var $modify_eo_item = $dropdown.find("#modify-eo-item");
  348. var $create_eo_item = $dropdown.find("#create-eo-item");
  349. $create_eo_item.unbind("click");
  350. $create_eo_item.on("click", function (event) {
  351. event.preventDefault();
  352. $scope.display_creation_modal($token);
  353. $scope.eo_creation_modal.selected = $token;
  354. });
  355. if ($token.hasClass("entity-occurrence")) {
  356. var segment_id = $token.parents(".segment").data("segment-id");
  357. var entity_id = $token.data("eo-id");
  358. $modify_eo_item.unbind("click");
  359. $modify_eo_item.on("click", function (event) {
  360. event.preventDefault();
  361. $scope.display_edition_modal(entity_id, segment_id);
  362. });
  363. $modify_eo_item.show();
  364. } else {
  365. $modify_eo_item.hide();
  366. }
  367. $token.trigger("click", false);
  368. };
  369. $scope.display_edition_modal = function (value, segment_id) {
  370. EntityOccurrence.get({pk: value}).$promise.then(
  371. function (eo_obj) {
  372. var $modal = $scope.eo_edition_modal.elem;
  373. var marker_html = '<div class="marker"><span class="rotate">';
  374. marker_html += '<i class="fi-arrows-expand"></span></div>';
  375. $modal.find('.message').empty();
  376. $modal.find('.segment').empty();
  377. $modal.find('.entity_id span').text(eo_obj.entity);
  378. $modal.find('.entity_kind span').text(eo_obj.entity__kind__name);
  379. $scope.eo_edition_modal.eo = eo_obj;
  380. var $eo = $(".eo-" + eo_obj.pk);
  381. var $tokens = $eo.parent(".segment").find(".rich-token");
  382. var $segment = $modal.find('.segment');
  383. $tokens.each(function(){
  384. var $this = $(this);
  385. var $token = $("<div>");
  386. $token.addClass("token");
  387. $token.text($this.find(".token").text());
  388. $token.data("offset", $this.find(".token").data("offset"));
  389. if($this.hasClass("eo-" + eo_obj.pk)){
  390. $token.addClass("eo");
  391. }
  392. $segment.append($token);
  393. });
  394. var eo_tokens = $segment.find(".eo");
  395. $(marker_html).insertBefore($(eo_tokens[0]));
  396. $(marker_html).insertAfter($(eo_tokens[eo_tokens.length - 1]));
  397. $scope.update_selection($modal);
  398. $segment.sortable({
  399. cancel: ".token",
  400. update: function () { $scope.update_selection($modal); }
  401. });
  402. $modal.foundation('reveal', 'open');
  403. });
  404. };
  405. $scope.display_creation_modal = function ($selected, segment_id) {
  406. var $modal = $scope.eo_creation_modal.elem;
  407. var marker_html = '<div class="marker"><span class="rotate">';
  408. marker_html += '<i class="fi-arrows-expand"></span></div>';
  409. $modal.find('.message').empty();
  410. $modal.find('.segment').empty();
  411. var $tokens = $selected.parent(".segment").find(".rich-token");
  412. var $segment = $modal.find('.segment');
  413. var $new_selected = {};
  414. $tokens.each(function(){
  415. var $this = $(this);
  416. var $token = $("<div>");
  417. $token.addClass("token");
  418. $token.text($this.find(".token").text());
  419. $token.data("offset", $this.find(".token").data("offset"));
  420. $segment.append($token);
  421. if ($this.hasClass($selected.attr("class"))) {
  422. $new_selected = $token;
  423. }
  424. });
  425. $(marker_html).insertBefore($new_selected);
  426. $(marker_html).insertAfter($new_selected);
  427. $scope.update_selection($modal);
  428. $segment.sortable({
  429. cancel: ".token",
  430. update: function () { $scope.update_selection($modal); }
  431. });
  432. $modal.foundation('reveal', 'open');
  433. };
  434. $scope.eo_edition_modal.reset = function () {
  435. var $elem = $scope.eo_edition_modal.elem;
  436. $elem.find('.message').empty();
  437. $elem.find('.segment').empty();
  438. };
  439. $scope.modal_add_msg = function ($modal, msg) {
  440. $modal.find('.message').empty().append('<p>' + msg + '</p>');
  441. };
  442. $scope.update_selection = function ($modal) {
  443. var paiting = false;
  444. var new_offsets = [];
  445. $modal.find('.segment div').each(function (idx) {
  446. var className = 'between-markers';
  447. var $elem = $(this);
  448. $elem.removeClass(className);
  449. var is_marker = $elem.hasClass('marker');
  450. if (is_marker) {
  451. new_offsets.push(idx);
  452. }
  453. if (paiting && is_marker) {
  454. // stop paiting
  455. paiting = false;
  456. } else if (!paiting && is_marker) {
  457. // start paiting
  458. paiting = true;
  459. }
  460. // now, paint
  461. if (paiting && !is_marker) {
  462. $elem.addClass(className);
  463. }
  464. });
  465. if (new_offsets.length === 2) {
  466. var $divs = $modal.find('.segment div');
  467. var $first_word_in = $divs.eq([new_offsets[0] + 1]);
  468. var $first_word_out = $divs.eq([new_offsets[1] + 1]);
  469. var new_offset_end, new_offset;
  470. if ($first_word_out.length === 0) {
  471. $first_word_out = $divs.eq([new_offsets[1] - 1]);
  472. new_offset_end = $first_word_out.data("offset") + 1;
  473. } else {
  474. new_offset_end = $first_word_out.data("offset");
  475. }
  476. new_offset = $first_word_in.data("offset");
  477. if ($first_word_in.hasClass("marker")) {
  478. new_offset = new_offset_end;
  479. }
  480. $modal.data("new_offset", new_offset);
  481. $modal.data("new_offset_end", new_offset_end);
  482. }
  483. };
  484. $scope.eo_edition_modal.submit = function () {
  485. var $modal = $scope.eo_edition_modal.elem;
  486. var eo = $scope.eo_edition_modal.eo;
  487. var new_offset = $modal.data("new_offset");
  488. var new_offset_end = $modal.data("new_offset_end");
  489. if (new_offset_end - new_offset <= 0) {
  490. $scope.modal_add_msg(
  491. $modal, "Invalid Entity Occurrence limits. Can't be empty."
  492. );
  493. } else {
  494. eo.offset = new_offset;
  495. eo.offset_end = new_offset_end;
  496. eo.$save().then(
  497. $scope.modal_save_success,
  498. function (response) {
  499. $scope.modal_add_msg($modal, "Not saved. " + response.statusText);
  500. }
  501. );
  502. }
  503. };
  504. $scope.eo_creation_modal.submit = function () {
  505. var $modal = $scope.eo_creation_modal.elem;
  506. var new_offset = $modal.data("new_offset");
  507. var new_offset_end = $modal.data("new_offset_end");
  508. var $new_entity_kind = $("#new_entity_kind");
  509. var $document = $(".document");
  510. var $button = $modal.find(".save");
  511. if (new_offset_end - new_offset <= 0) {
  512. $scope.modal_add_msg(
  513. $modal, "Invalid Entity Occurrence limits. Can't be empty."
  514. );
  515. } else if ($new_entity_kind.val() === null) {
  516. $scope.modal_add_msg($modal, "Error: you must select a kind");
  517. } else {
  518. var csrftoken = getCookie('csrftoken');
  519. $button.find(".text").fadeOut(function () {
  520. $button.find(".loading").fadeIn();
  521. });
  522. $.ajax({
  523. url: eo_creation_url,
  524. type: "POST",
  525. data: {
  526. offset: new_offset,
  527. offset_end: new_offset_end,
  528. kind: $new_entity_kind.val(),
  529. doc_id: $document.data("document-id")
  530. },
  531. success: function () {
  532. $button.find(".loading").fadeOut(function () {
  533. $button.find(".text").fadeIn();
  534. });
  535. $scope.modal_save_success();
  536. },
  537. error: function (jqXHR, textStatus) {
  538. $scope.modal_add_msg($modal, "Not saved. " + textStatus);
  539. },
  540. beforeSend: function(xhr, settings) {
  541. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  542. }
  543. });
  544. }
  545. };
  546. $scope.run_partial_save = function () {
  547. var $partial_save = $("#partial-save");
  548. if($partial_save.length !== 0){
  549. $partial_save.val('enabled').parents('form').submit();
  550. } else {
  551. location.reload();
  552. }
  553. };
  554. $scope.modal_save_success = function () {
  555. /* Here is handled not the segment on the modal, but on the actual underlying
  556. * page */
  557. $scope.run_partial_save();
  558. };
  559. $scope.eo_edition_modal.remove_eo_ask = function (event) {
  560. event.preventDefault();
  561. $(".remove-eo-ask").fadeOut("fast", function () {
  562. $(".remove-confirm-wrapper").fadeIn("fast");
  563. });
  564. };
  565. $scope.eo_edition_modal.remove_eo_cancel = function (event) {
  566. $(".remove-confirm-wrapper").fadeOut("fast", function () {
  567. $(".remove-eo-ask").fadeIn("fast");
  568. });
  569. };
  570. $scope.eo_edition_modal.remove_eo_confirm = function (event) {
  571. event.preventDefault();
  572. var eo = $scope.eo_edition_modal.eo;
  573. EntityOccurrence.delete({pk: eo.pk}).$promise.then(function () {
  574. $scope.run_partial_save();
  575. });
  576. };
  577. $scope.eo_edition_modal.remove_eo_confirm_all = function (event) {
  578. event.preventDefault();
  579. var eo = $scope.eo_edition_modal.eo;
  580. Entity.delete({pk: eo.entity}).$promise.then(function () {
  581. $scope.run_partial_save();
  582. });
  583. };
  584. $scope.draw_judge_answers = function (judge) {
  585. event.preventDefault();
  586. var data = $scope.other_judges_labels[judge];
  587. $scope.clean_all_arrows();
  588. for (var i in data) {
  589. if (data.hasOwnProperty(i)) {
  590. var path = $scope.calculate_arrow_string(
  591. data[i][0], data[i][1], data[i][2], true
  592. );
  593. }
  594. }
  595. };
  596. }
  597. ]);
  598. String.prototype.format = String.prototype.f = function () {
  599. var s = this;
  600. var i = arguments.length;
  601. while (i--) {
  602. s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
  603. }
  604. return s;
  605. };
  606. // using jQuery
  607. function getCookie(name) {
  608. var cookieValue = null;
  609. if (document.cookie && document.cookie !== '') {
  610. var cookies = document.cookie.split(';');
  611. for (var i = 0; i < cookies.length; i++) {
  612. var cookie = jQuery.trim(cookies[i]);
  613. // Does this cookie string begin with the name we want?
  614. if (cookie.substring(0, name.length + 1) === (name + '=')) {
  615. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  616. break;
  617. }
  618. }
  619. }
  620. return cookieValue;
  621. }