skill_wheel.tpl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. {% include app.template_style ~ '/skill/skill_wheel.js.tpl' %}
  2. <script>
  3. function add_skill(params) {
  4. $.ajax({
  5. async: false,
  6. url: url+'&a=add&'+params,
  7. success:function(my_id) {
  8. //Close dialog
  9. $("#dialog-form").dialog("close");
  10. }
  11. });
  12. }
  13. /* Skill search input in the left menu */
  14. function check_skills_sidebar() {
  15. //Selecting only selected skills
  16. $("#skill_id option:selected").each(function() {
  17. var skill_id = $(this).val();
  18. if (skill_id != "" ) {
  19. $.ajax({
  20. url: "{{ url }}&a=skill_exists",
  21. data: "skill_id="+skill_id,
  22. // async: false,
  23. success: function(return_value) {
  24. if (return_value == 0 ) {
  25. alert("{{ 'SkillDoesNotExist'|get_lang }}");
  26. //Deleting select option tag
  27. //$("#skill_id option[value="+skill_id+"]").remove();
  28. $("#skill_id").empty();
  29. //Deleting holder
  30. $("#skill_search .holder li").each(function () {
  31. if ($(this).attr("rel") == skill_id) {
  32. $(this).remove();
  33. }
  34. });
  35. } else {
  36. $("#skill_id option[value="+skill_id+"]").remove();
  37. //Deleting holder
  38. $("#skill_search .holder li").each(function () {
  39. if ($(this).attr("rel") == skill_id) {
  40. $(this).remove();
  41. }
  42. });
  43. if ($('#skill_to_select_id_'+skill_id).length == 0) {
  44. skill_info = get_skill_info(skill_id);
  45. li = fill_skill_search_li(skill_id, skill_info.name);
  46. $("#skill_holder").append(li);
  47. }
  48. }
  49. },
  50. });
  51. }
  52. });
  53. }
  54. function fill_skill_search_li(skill_id, skill_name, checked) {
  55. checked_condition = '';
  56. if (checked == 1) {
  57. checked_condition = 'checked=checked';
  58. }
  59. return '<li><input id="skill_to_select_id_'+skill_id+'" rel="'+skill_id+'" name="'+skill_name+'" class="skill_to_select" '+checked_condition+' type="checkbox" value=""> <a href="#" class="load_wheel" rel="'+skill_id+'">'+skill_name+'</a></li>';
  60. }
  61. function check_skills_edit_form() {
  62. //selecting only selected parents
  63. $("#parent_id option:selected").each(function() {
  64. var skill_id = $(this).val();
  65. if (skill_id != "" ) {
  66. $.ajax({
  67. async: false,
  68. url: "{{ url }}&a=skill_exists",
  69. data: "skill_id="+skill_id,
  70. success: function(return_value) {
  71. if (return_value == 0 ) {
  72. alert("{{ 'SkillDoesNotExist'|get_lang }}");
  73. //Deleting select option tag
  74. $("#parent_id").find('option').remove();
  75. //Deleting holder
  76. $("#skill_row .holder li").each(function () {
  77. if ($(this).attr("rel") == skill_id) {
  78. $(this).remove();
  79. }
  80. });
  81. } else {
  82. $("#parent_id").empty();
  83. $("#skill_edit_holder").find('li').remove();
  84. //Deleting holder
  85. $("#skill_row .holder li").each(function () {
  86. if ($(this).attr("rel") == skill_id) {
  87. $(this).remove();
  88. }
  89. });
  90. skill = get_skill_info(skill_id);
  91. $("#skill_edit_holder").append('<li class="bit-box" id="skill_option_'+skill_id+'"> '+skill.name+'</li>');
  92. $("#parent_id").append('<option class="selected" selected="selected" value="'+skill_id+'"></option>');
  93. }
  94. },
  95. });
  96. }
  97. });
  98. }
  99. function check_gradebook() {
  100. //selecting only selected users
  101. $("#gradebook_id option:selected").each(function() {
  102. var gradebook_id = $(this).val();
  103. if (gradebook_id != "" ) {
  104. $.ajax({
  105. url: "{{ url }}&a=gradebook_exists",
  106. data: "gradebook_id="+gradebook_id,
  107. success: function(return_value) {
  108. if (return_value == 0 ) {
  109. alert("{{ 'GradebookDoesNotExist'|get_lang }}");
  110. //Deleting select option tag
  111. $("#gradebook_id option[value="+gradebook_id+"]").remove();
  112. //Deleting holder
  113. $("#gradebook_row .holder li").each(function () {
  114. if ($(this).attr("rel") == gradebook_id) {
  115. $(this).remove();
  116. }
  117. });
  118. } else {
  119. //Deleting holder
  120. $("#gradebook_row .holder li").each(function () {
  121. if ($(this).attr("rel") == gradebook_id) {
  122. $(this).remove();
  123. }
  124. });
  125. if ($('#gradebook_item_'+gradebook_id).length == 0) {
  126. gradebook = get_gradebook_info(gradebook_id);
  127. if (gradebook) {
  128. $("#gradebook_holder").append('<li id="gradebook_item_'+gradebook_id+'" class="bit-box"> '+gradebook.name+' <a rel="'+gradebook_id+'" class="closebutton" href="#"></a></li>');
  129. }
  130. }
  131. }
  132. },
  133. });
  134. }
  135. });
  136. }
  137. function delete_gradebook_from_skill(skill_id, gradebook_id) {
  138. $.ajax({
  139. url: url+'&a=delete_gradebook_from_skill&skill_id='+skill_id+'&gradebook_id='+gradebook_id,
  140. async: false,
  141. success: function(result) {
  142. //if (result == 1) {
  143. $('#gradebook_item_'+gradebook_id).remove();
  144. $("#gradebook_id option").each(function() {
  145. if ($(this).attr("value") == gradebook_id) {
  146. $(this).remove();
  147. }
  148. });
  149. //}
  150. }
  151. });
  152. }
  153. function return_skill_list_from_profile_search() {
  154. var skill_list = {};
  155. if ($("#profile_search li").length != 0) {
  156. $("#profile_search li").each(function(index) {
  157. id = $(this).attr("id").split('_')[3];
  158. if (id) {
  159. skill_list[index] = id;
  160. }
  161. });
  162. }
  163. return skill_list;
  164. }
  165. function submit_profile_search_form() {
  166. $("#skill_wheel").remove();
  167. var skill_list = return_skill_list_from_profile_search();
  168. if (skill_list.length != 0) {
  169. skill_list = { 'skill_id' : skill_list };
  170. skill_params = $.param(skill_list);
  171. $.ajax({
  172. url: url+'&a=profile_matches&'+skill_params,
  173. async: false,
  174. success: function (html) {
  175. //users = jQuery.parseJSON(users);
  176. $('#wheel_container').html(html);
  177. }
  178. });
  179. }
  180. //return skill;
  181. }
  182. function add_skill_in_profile_list(skill_id, skill_name) {
  183. if ($('#profile_match_item_'+skill_id).length == 0 ) {
  184. $('#profile_search').append('<li class="bit-box" id="profile_match_item_'+skill_id+'">'+skill_name+' <a rel="'+skill_id+'" class="closebutton" href="#"></a> </li>');
  185. } else {
  186. $('#profile_match_item_'+skill_id).remove();
  187. }
  188. toogle_save_profile_form();
  189. }
  190. function toogle_save_profile_form() {
  191. //Hiding showing the save this search
  192. if ($('#profile_search li').length == 0) {
  193. $('#profile-options-container').hide();
  194. } else {
  195. $('#profile-options-container').show();
  196. }
  197. }
  198. $(document).ready(function() {
  199. /* Skill search */
  200. //Tool tip (in exercises)
  201. var tip_options = {
  202. placement : 'right'
  203. }
  204. $('.tooltip_skill').tooltip(tip_options);
  205. /* Skill item list onclick */
  206. $("#skill_holder").on("click", "input.skill_to_select", function() {
  207. skill_id = $(this).attr('rel');
  208. skill_name = $(this).attr('name');
  209. add_skill_in_profile_list(skill_id, skill_name);
  210. });
  211. /* URL link when searching skills */
  212. $("#skill_holder").on("click", "a.load_wheel", function() {
  213. skill_id = $(this).attr('rel');
  214. skill_to_load_from_get = 0;
  215. load_nodes(skill_id, main_depth);
  216. });
  217. /* URL link when searching skills */
  218. $("#skill_search").on("click", "a.load_root", function() {
  219. skill_id = $(this).attr('rel');
  220. skill_to_load_from_get = 0;
  221. load_nodes(skill_id, main_depth);
  222. });
  223. /*$("#skill_search").on("click", "a#clear_selection", function() {
  224. });*/
  225. /* Profile matcher */
  226. /* Submit button */
  227. $("#search_profile_form").submit(function() {
  228. submit_profile_search_form();
  229. return false;
  230. });
  231. $("#save_profile_form_button").submit(function() {
  232. open_save_profile_popup();
  233. return false;
  234. });
  235. /* Close button in profile matcher items */
  236. $("#profile_search").on("click", "a.closebutton", function() {
  237. skill_id = $(this).attr('rel');
  238. $('input[id=skill_to_select_id_'+skill_id+']').attr('checked', false);
  239. $('#profile_match_item_'+skill_id).remove();
  240. submit_profile_search_form();
  241. toogle_save_profile_form();
  242. });
  243. //Fill saved profiles list
  244. update_my_saved_profiles();
  245. /* Click in profile */
  246. $("#saved_profiles").on("click", "a.load_profile", function() {
  247. profile_id = $(this).attr('rel');
  248. $.ajax({
  249. url: '{{ url }}&a=get_skills_by_profile&profile_id='+profile_id,
  250. success:function(json) {
  251. skill_list = jQuery.parseJSON(json);
  252. $('#profile_search').empty();
  253. $('#skill_holder').empty();
  254. jQuery.each(skill_list, function(index, skill_id) {
  255. skill_info = get_skill_info(skill_id);
  256. li = fill_skill_search_li(skill_id, skill_info.name, 1);
  257. $("#skill_holder").append(li);
  258. add_skill_in_profile_list(skill_id, skill_info.name);
  259. });
  260. submit_profile_search_form();
  261. }
  262. });
  263. });
  264. /* Wheel skill popup form */
  265. /* Close button in gradebook select */
  266. $("#gradebook_holder").on("click", "a.closebutton", function() {
  267. gradebook_id = $(this).attr('rel');
  268. skill_id = $('#id').attr('value');
  269. delete_gradebook_from_skill(skill_id, gradebook_id);
  270. });
  271. $("#skill_id").fcbkcomplete({
  272. json_url: "{{ url }}&a=find_skills",
  273. cache: false,
  274. filter_case: false,
  275. filter_hide: true,
  276. complete_text:"{{ 'StartToType' | get_lang }}",
  277. firstselected: true,
  278. //onremove: "testme",
  279. onselect:"check_skills_sidebar",
  280. filter_selected: true,
  281. newel: true
  282. });
  283. $("#parent_id").fcbkcomplete({
  284. json_url: "{{ url }}&a=find_skills",
  285. cache: false,
  286. filter_case: false,
  287. filter_hide: true,
  288. complete_text:"{{ 'StartToType' | get_lang }}",
  289. firstselected: true,
  290. //onremove: "testme",
  291. onselect:"check_skills_edit_form",
  292. filter_selected: true,
  293. newel: true
  294. });
  295. $("#gradebook_id").fcbkcomplete({
  296. json_url: "{{ url }}&a=find_gradebooks",
  297. cache: false,
  298. filter_case: false,
  299. filter_hide: true,
  300. complete_text:"{{ 'StartToType' | get_lang }}",
  301. firstselected: true,
  302. //onremove: "testme",
  303. onselect:"check_gradebook",
  304. filter_selected: true,
  305. newel: true
  306. });
  307. //Skill popup (edit, create child... )
  308. $("#dialog-form").dialog({
  309. autoOpen: false,
  310. modal : true,
  311. width : 600,
  312. height : 630
  313. });
  314. //Save search profile dialog
  315. $("#dialog-form-profile").dialog({
  316. autoOpen: false,
  317. modal : true,
  318. width : 500,
  319. height : 400
  320. });
  321. load_nodes(0, main_depth);
  322. function open_save_profile_popup() {
  323. $("#dialog-form-profile").dialog({
  324. buttons: {
  325. "{{ "Save"|get_lang }}" : function() {
  326. var params = $("#save_profile_form").serialize();
  327. var skill_list = return_skill_list_from_profile_search();
  328. skill_list = { 'skill_id' : skill_list };
  329. skill_params = $.param(skill_list);
  330. $.ajax({
  331. url: '{{ url }}&a=save_profile&'+params+'&'+skill_params,
  332. success:function(data) {
  333. if (data == 1 ) {
  334. update_my_saved_profiles();
  335. alert("{{ "Saved"|get_lang }}");
  336. } else {
  337. alert("{{ "Error"|get_lang }}");
  338. }
  339. $("#dialog-form-profile").dialog("close");
  340. $("#name").attr('value', '');
  341. $("#description").attr('value', '');
  342. }
  343. });
  344. }
  345. },
  346. close: function() {
  347. $("#name").attr('value', '');
  348. $("#description").attr('value', '');
  349. }
  350. });
  351. $("#dialog-form-profile").dialog("open");
  352. }
  353. function update_my_saved_profiles() {
  354. $.ajax({
  355. url: '{{ url }}&a=get_saved_profiles',
  356. success:function(data) {
  357. $("#saved_profiles").html(data);
  358. }
  359. });
  360. }
  361. /* Generated random colour */
  362. /*
  363. function colour(d) {
  364. if (d.children) {
  365. // There is a maximum of two children!
  366. var colours = d.children.map(colour),
  367. a = d3.hsl(colours[0]),
  368. b = d3.hsl(colours[1]);
  369. // L*a*b* might be better here...
  370. return d3.hsl((a.h + b.h) / 2, a.s * 1.2, a.levels_to_show / 1.2);
  371. }
  372. return d.colour || "#fff";
  373. }*/
  374. });
  375. </script>
  376. <div class="container-fluid">
  377. <div class="row-fluid">
  378. <div class="span3">
  379. <div class="well sidebar-nav-skill-wheel">
  380. <div class="page-header">
  381. <h3>{{ 'Skills'|get_lang }}</h3>
  382. </div>
  383. <form id="skill_search" class="form-search">
  384. <select id="skill_id" name="skill_id" />
  385. </select>
  386. <br /><br />
  387. <div class="btn-group">
  388. <a class="btn load_root" rel="0" href="#">{{ "SkillRoot"|get_lang }}</a>
  389. <!-- <a id="clear_selection" class="btn">{{ "Clear"|get_lang }}</a> -->
  390. </div>
  391. <ul id="skill_holder" class="holder holder_simple">
  392. </ul>
  393. </form>
  394. <div class="page-header">
  395. <h3>{{ 'ProfileSearch'|get_lang }}</h3>
  396. </div>
  397. {{ 'WhatSkillsAreYouLookingFor'|get_lang }}
  398. <ul id="profile_search" class="holder holder_simple">
  399. </ul>
  400. <form id="search_profile_form" class="form-search">
  401. <input class="btn" type="submit" value="{{ "SearchProfileMatches"|get_lang }}">
  402. </form>
  403. <div id="profile-options-container" style="display:none">
  404. {{ 'IsThisWhatYouWereLookingFor'|get_lang }}
  405. <form id="save_profile_form_button" class="form-search">
  406. <input class="btn" type="submit" value="{{ "SaveThisSearch"|get_lang }}">
  407. </form>
  408. </div>
  409. <div id="saved_profiles">
  410. </div>
  411. <div class="page-header">
  412. <h3>{{ "Legend"|get_lang }}</h3>
  413. </div>
  414. <span class="label label-warning">{{ "SkillsYouCanLearn"|get_lang }}</span><br /><br />
  415. <span class="label label-important">{{ "SkillsSearchedFor"|get_lang }}</span><br /><br />
  416. <div><a class="btn btn-small" href="{{ _p.web }}user_portal.php">{{ "ReturnToCourseList"|get_lang }}</a></div>
  417. </div>
  418. </div>
  419. <div id="wheel_container" class="span9">
  420. <div id="skill_wheel">
  421. <img src="">
  422. </div>
  423. </div>
  424. </div>
  425. <div id="dialog-form" style="">
  426. <p class="validateTips"></p>
  427. <form id="add_item" class="form-horizontal" name="form">
  428. <fieldset>
  429. <input type="hidden" name="id" id="id"/>
  430. <div class="control-group">
  431. <label class="control-label" for="name">{{ 'Name' | get_lang }}</label>
  432. <div class="controls">
  433. <input type="text" name="name" id="name" class="span4" />
  434. </div>
  435. </div>
  436. <div class="control-group">
  437. <label class="control-label">{{ 'ShortCode' | get_lang }}</label>
  438. <div class="controls">
  439. <input type="text" name="short_code" id="short_code" class="span2" />
  440. </div>
  441. </div>
  442. <div id="skill_row" class="control-group">
  443. <label class="control-label" for="name">{{'Parent'|get_lang}}</label>
  444. <div class="controls">
  445. <select id="parent_id" name="parent_id" />
  446. </select>
  447. <ul id="skill_edit_holder" class="holder holder_simple">
  448. </ul>
  449. </div>
  450. </div>
  451. <div id="gradebook_row" class="control-group">
  452. <label class="control-label" for="name">{{'Gradebook'|get_lang}}</label>
  453. <div class="controls">
  454. <select id="gradebook_id" name="gradebook_id" multiple="multiple"/>
  455. </select>
  456. <ul id="gradebook_holder" class="holder holder_simple">
  457. </ul>
  458. <span class="help-block">
  459. {{ 'WithCertificate'|get_lang }}
  460. </span>
  461. </div>
  462. </div>
  463. <div class="control-group">
  464. <label class="control-label" for="name">{{ 'Description'|get_lang }}</label>
  465. <div class="controls">
  466. <textarea name="description" id="description" class="span4" rows="7"></textarea>
  467. </div>
  468. </div>
  469. </fieldset>
  470. </form>
  471. </div>
  472. <div id="dialog-form-profile" style="display:none;">
  473. <form id="save_profile_form" class="form-horizontal" name="form">
  474. <fieldset>
  475. <div class="control-group">
  476. <label class="control-label" for="name">{{"Name"|get_lang}}</label>
  477. <div class="controls">
  478. <input type="text" name="name" id="name" size="40" />
  479. </div>
  480. </div>
  481. <div class="control-group">
  482. <label class="control-label" for="name">{{"Description"|get_lang}}</label>
  483. <div class="controls">
  484. <textarea name="description" id="description" class="span2" rows="7"></textarea>
  485. </div>
  486. </div>
  487. </fieldset>
  488. </form>
  489. </div>