skill_tree_student.tpl 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <style>
  2. /* just because */
  3. body {
  4. /* fallback */
  5. background-color: #eee;
  6. background-image: url(images/radial_bg.png);
  7. background-position: center center;
  8. background-repeat: no-repeat;
  9. /* Safari 4-5, Chrome 1-9 */ /* Can't specify a percentage size? Laaaaaame. */
  10. background: -webkit-gradient(radial, center center, 0, center center, 460, from(#eee), to(#666));
  11. /* Safari 5.1+, Chrome 10+ */
  12. background: -webkit-radial-gradient(circle, #eee, #666);
  13. /* Firefox 3.6+ */
  14. background: -moz-radial-gradient(circle, #eee, #666);
  15. /* IE 10 */
  16. background: -ms-radial-gradient(circle, #eee, #666);
  17. }
  18. </style>
  19. <script type="text/javascript">
  20. //js settings
  21. var url = '{{url}}';
  22. //Block settings see the SkillVisualizer Class
  23. var offset_x = {{skill_visualizer.offset_x}};
  24. var offset_y = {{skill_visualizer.offset_y}};
  25. var space_between_blocks_x = {{skill_visualizer.space_between_blocks_x}};
  26. var space_between_blocks_y = {{skill_visualizer.space_between_blocks_y}};
  27. var center_x = {{skill_visualizer.center_x}};
  28. var block_size = {{skill_visualizer.block_size}};
  29. jsPlumb.bind("ready", function() {
  30. //Open dialog
  31. $("#dialog-form").dialog({
  32. autoOpen: false,
  33. modal : true,
  34. width : 550,
  35. height : 350,
  36. });
  37. //Clicking in a box skill (we use live instead of bind because we're creating divs on the fly )
  38. $(".open_block").live('click', function() {
  39. var id = $(this).attr('id');
  40. console.log('click.open_block id: ' + id);
  41. console.log('parents: ' + parents);
  42. //if is root
  43. if (parents[0] == id) {
  44. parents = [id];
  45. }
  46. if (parents[1] != id) {
  47. console.log('parents.length ' +parents.length);
  48. //If there are 2 parents in the skill_tree
  49. if (parents.length == 2 ) {
  50. first_parent = parents[0];
  51. $('#'+parents[1]).css('top', '0px');
  52. //console.log('deleting: '+parents[0]);
  53. //removing father
  54. console.log("first_parent " + first_parent);
  55. for (var i = 0; i < skills.length; i++) {
  56. //console.log('looping '+skills[i].element + ' ');
  57. if (skills[i].element == parents[0] ) {
  58. console.log('deleting parent:'+ skills[i].element + ' here ');
  59. jsPlumb.deleteEndpoint(skills[i].element);
  60. jsPlumb.detachAllConnections(skills[i].element);
  61. jsPlumb.removeAllEndpoints(skills[i].element);
  62. $("#"+skills[i].element).remove();
  63. }
  64. }
  65. parents.splice(0,1);
  66. parents.push(id);
  67. console.log('parents after slice/push: ' + parents);
  68. }
  69. if ($(this).hasClass('first_window')) {
  70. console.log('im in a first_window (root)');
  71. $('#'+first_parent).css('top', '0px');
  72. //show the first_parent
  73. //if (first_parent != '') {
  74. parents = [first_parent, id];
  75. open_parent(first_parent, id);
  76. //}
  77. }
  78. if (jQuery.inArray(id, parents) == -1) {
  79. parents.push(id);
  80. console.log('parents push: ' + parents);
  81. }
  82. open_block(id, 0, 0);
  83. }
  84. //Setting class
  85. cleanclass($(this));
  86. $(this).addClass('second_window');
  87. parent_div = $("#"+parents[0]);
  88. cleanclass(parent_div);
  89. parent_div.addClass('first_window');
  90. parent_div.addClass('skill_root');
  91. parent_div = $("#"+parents[1]);
  92. cleanclass(parent_div);
  93. parent_div.addClass('second_window');
  94. //console.log(parents);
  95. // console.log(skills);
  96. console.log('first_parent : ' + first_parent);
  97. //redraw
  98. jsPlumb.repaintEverything();
  99. jsPlumb.repaint(id);
  100. });
  101. $(".edit_block").live('click',function() {
  102. var my_id = $(this).attr('id');
  103. my_id = my_id.split('_')[2];
  104. $.ajax({
  105. url: url+'&a=get_skill_info&id='+my_id,
  106. success: function(json) {
  107. var skill = jQuery.parseJSON(json);
  108. $("#name").html(skill.name);
  109. $("#id").attr('value', skill.id);
  110. $("#description").html(skill.description);
  111. //filling parent_id
  112. $("#parent_id option[value='"+skill.extra.parent_id+"']").attr('selected', 'selected');
  113. //filling the gradebook_id
  114. $("#gradebook_id").html('');
  115. jQuery.each(skill.gradebooks, function(index, data) {
  116. $("#gradebook_id").append('<span class="label_tag gradebook">'+data.name+'</div>');
  117. });
  118. },
  119. });
  120. $("#dialog-form").dialog("open");
  121. return false;
  122. });
  123. $("#dialog-form").dialog({
  124. close: function() {
  125. $("#name").html('');
  126. $("#description").html('');
  127. }
  128. });
  129. // chrome fix.
  130. document.onselectstart = function () { return false; };
  131. // render mode
  132. var resetRenderMode = function(desiredMode) {
  133. var newMode = jsPlumb.setRenderMode(desiredMode);
  134. jsPlumbDemo.init();
  135. };
  136. resetRenderMode(jsPlumb.CANVAS);
  137. });
  138. ;(function() {
  139. window.jsPlumbDemo = {
  140. init : function() {
  141. console.log('Import defaults');
  142. jsPlumb.Defaults.Anchors = [ "BottomCenter", "TopCenter" ];
  143. jsPlumb.Defaults.Container = "skill_tree";
  144. open_block('block_1', 1, 1);
  145. }
  146. };
  147. })();
  148. $(document).ready( function() {
  149. //When creating a connection see
  150. //http://jsplumb.org/apidocs/files/jsPlumb-1-3-2-all-js.html#bind
  151. jsPlumb.bind("jsPlumbConnection", function(conn) {
  152. //alert("Connection created " + conn.sourceId + " to " + conn.targetId + " ");
  153. //jsPlumb.detach(conn);
  154. });
  155. });
  156. </script>
  157. <div id="skill_tree"></div>
  158. <div id="dialog-form" style="display:none;">
  159. <form id="add_item" class="form-horizontal" name="form">
  160. <fieldset>
  161. <input type="hidden" name="id" id="id"/>
  162. <div class="control-group">
  163. <label class="control-label" for="name">Name</label>
  164. <div class="controls">
  165. <span id="name"></span>
  166. </div>
  167. </div>
  168. <div class="control-group">
  169. <label class="control-label" for="name">Description</label>
  170. <div class="controls">
  171. <span id="description"></span>
  172. </div>
  173. </div>
  174. <div class="control-group">
  175. <label class="control-label" for="name">Gradebook</label>
  176. <div class="controls">
  177. <div id="gradebook_id"></div>
  178. </div>
  179. </div>
  180. </fieldset>
  181. </form>
  182. </div>