skill_wheel.tpl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. {% include template ~ '/skill/skill_wheel.js.tpl' %}
  2. <script>
  3. /* Skill search input in the left menu */
  4. function check_skills_sidebar() {
  5. //Selecting only selected skills
  6. $("#skill_id option:selected").each(function() {
  7. var skill_id = $(this).val();
  8. if (skill_id != "" ) {
  9. $.ajax({
  10. url: "{{ url }}&a=skill_exists",
  11. data: "skill_id="+skill_id,
  12. // async: false,
  13. success: function(return_value) {
  14. if (return_value == 0 ) {
  15. alert("{{ 'SkillDoesNotExist'|get_lang }}");
  16. //Deleting select option tag
  17. //$("#skill_id option[value="+skill_id+"]").remove();
  18. $("#skill_id").empty();
  19. //Deleting holder
  20. $("#skill_search .holder li").each(function () {
  21. if ($(this).attr("rel") == skill_id) {
  22. $(this).remove();
  23. }
  24. });
  25. } else {
  26. $("#skill_id option[value="+skill_id+"]").remove();
  27. //Deleting holder
  28. $("#skill_search .holder li").each(function () {
  29. if ($(this).attr("rel") == skill_id) {
  30. $(this).remove();
  31. }
  32. });
  33. if ($('#skill_to_select_id_'+skill_id).length == 0) {
  34. skill_info = get_skill_info(skill_id);
  35. li = fill_skill_search_li(skill_id, skill_info.name);
  36. $("#skill_holder").append(li);
  37. }
  38. }
  39. }
  40. });
  41. }
  42. });
  43. }
  44. function fill_skill_search_li(skill_id, skill_name, checked) {
  45. checked_condition = '';
  46. if (checked == 1) {
  47. checked_condition = 'checked=checked';
  48. }
  49. 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>';
  50. }
  51. function check_skills_edit_form() {
  52. //selecting only selected parents
  53. $("#parent_id option:selected").each(function() {
  54. var skill_id = $(this).val();
  55. if (skill_id != "" ) {
  56. $.ajax({
  57. async: false,
  58. url: "{{ url }}&a=skill_exists",
  59. data: "skill_id="+skill_id,
  60. success: function(return_value) {
  61. if (return_value == 0 ) {
  62. alert("{{ 'SkillDoesNotExist'|get_lang }}");
  63. //Deleting select option tag
  64. $("#parent_id").find('option').remove();
  65. //Deleting holder
  66. $("#skill_row .holder li").each(function () {
  67. if ($(this).attr("rel") == skill_id) {
  68. $(this).remove();
  69. }
  70. });
  71. } else {
  72. $("#parent_id").empty();
  73. $("#skill_edit_holder").find('li').remove();
  74. //Deleting holder
  75. $("#skill_row .holder li").each(function () {
  76. if ($(this).attr("rel") == skill_id) {
  77. $(this).remove();
  78. }
  79. });
  80. skill = get_skill_info(skill_id);
  81. $("#skill_edit_holder").append('<li class="bit-box" id="skill_option_'+skill_id+'"> '+skill.name+'</li>');
  82. $("#parent_id").append('<option class="selected" selected="selected" value="'+skill_id+'"></option>');
  83. }
  84. }
  85. });
  86. }
  87. });
  88. }
  89. function check_gradebook() {
  90. //selecting only selected users
  91. $("#gradebook_id option:selected").each(function() {
  92. var gradebook_id = $(this).val();
  93. if (gradebook_id != "" ) {
  94. $.ajax({
  95. url: "{{ url }}&a=gradebook_exists",
  96. data: "gradebook_id="+gradebook_id,
  97. success: function(return_value) {
  98. if (return_value == 0 ) {
  99. alert("{{ 'GradebookDoesNotExist'|get_lang }}");
  100. //Deleting select option tag
  101. $("#gradebook_id option[value="+gradebook_id+"]").remove();
  102. //Deleting holder
  103. $("#gradebook_row .holder li").each(function () {
  104. if ($(this).attr("rel") == gradebook_id) {
  105. $(this).remove();
  106. }
  107. });
  108. } else {
  109. //Deleting holder
  110. $("#gradebook_row .holder li").each(function () {
  111. if ($(this).attr("rel") == gradebook_id) {
  112. $(this).remove();
  113. }
  114. });
  115. if ($('#gradebook_item_'+gradebook_id).length == 0) {
  116. gradebook = get_gradebook_info(gradebook_id);
  117. if (gradebook) {
  118. $("#gradebook_holder").append('<li id="gradebook_item_'+gradebook_id+'" class="bit-box"> '+gradebook.name+' <a rel="'+gradebook_id+'" class="closebutton" href="#"></a></li>');
  119. }
  120. }
  121. }
  122. }
  123. });
  124. }
  125. });
  126. }
  127. function delete_gradebook_from_skill(skill_id, gradebook_id) {
  128. $.ajax({
  129. url: url+'&a=delete_gradebook_from_skill&skill_id='+skill_id+'&gradebook_id='+gradebook_id,
  130. async: false,
  131. success: function(result) {
  132. //if (result == 1) {
  133. $('#gradebook_item_'+gradebook_id).remove();
  134. $("#gradebook_id option").each(function() {
  135. if ($(this).attr("value") == gradebook_id) {
  136. $(this).remove();
  137. }
  138. });
  139. //}
  140. }
  141. });
  142. }
  143. function return_skill_list_from_profile_search() {
  144. var skill_list = {};
  145. if ($("#profile_search li").length != 0) {
  146. $("#profile_search li").each(function(index) {
  147. id = $(this).attr("id").split('_')[3];
  148. if (id) {
  149. skill_list[index] = id;
  150. }
  151. });
  152. }
  153. return skill_list;
  154. }
  155. function submit_profile_search_form() {
  156. $("#skill_wheel").remove();
  157. var skill_list = return_skill_list_from_profile_search();
  158. if (skill_list.length != 0) {
  159. skill_list = { 'skill_id' : skill_list };
  160. skill_params = $.param(skill_list);
  161. $.ajax({
  162. url: url+'&a=profile_matches&'+skill_params,
  163. async: false,
  164. success: function (html) {
  165. //users = jQuery.parseJSON(users);
  166. $('#wheel_container').html(html);
  167. }
  168. });
  169. }
  170. //return skill;
  171. }
  172. function add_skill_in_profile_list(skill_id, skill_name) {
  173. if ($('#profile_match_item_'+skill_id).length == 0 ) {
  174. $('#profile_search').append('<li class="bit-box" id="profile_match_item_'+skill_id+'">'+skill_name+' <a rel="'+skill_id+'" class="closebutton" href="#"></a> </li>');
  175. } else {
  176. $('#profile_match_item_'+skill_id).remove();
  177. }
  178. toogle_save_profile_form();
  179. }
  180. function toogle_save_profile_form() {
  181. //Hiding showing the save this search
  182. if ($('#profile_search li').length == 0) {
  183. $('#profile-options-container').hide();
  184. } else {
  185. $('#profile-options-container').show();
  186. }
  187. }
  188. $(document).ready(function() {
  189. /* Skill search */
  190. //Tool tip (in exercises)
  191. var tip_options = {
  192. placement : 'right'
  193. }
  194. $('.tooltip_skill').tooltip(tip_options);
  195. /* Skill item list onclick */
  196. $("#skill_holder").on("click", "input.skill_to_select", function() {
  197. skill_id = $(this).attr('rel');
  198. skill_name = $(this).attr('name');
  199. add_skill_in_profile_list(skill_id, skill_name);
  200. });
  201. /* URL link when searching skills */
  202. $("#skill_holder").on("click", "a.load_wheel", function(e) {
  203. e.preventDefault();
  204. skill_id = $(this).attr('rel');
  205. skill_to_load_from_get = 0;
  206. load_nodes(skill_id, main_depth);
  207. });
  208. /* URL link when searching skills */
  209. $("#skill_search").on("click", "a.load_root", function() {
  210. skill_id = $(this).attr('rel');
  211. skill_to_load_from_get = 0;
  212. load_nodes(skill_id, main_depth);
  213. });
  214. /* Profile matcher */
  215. /* Submit button */
  216. $("#search_profile_form").submit(function() {
  217. submit_profile_search_form();
  218. return false;
  219. });
  220. $("form#save_profile_form_button").on('submit', function(e) {
  221. e.preventDefault();
  222. var profileId = parseInt($('input[name="profile_id"]').val());
  223. var getProfileInfo = $.getJSON(
  224. '{{ url }}',
  225. {
  226. a: 'get_profile',
  227. profile_id: profileId
  228. }
  229. );
  230. $.when(getProfileInfo).done(function(profileInfo) {
  231. $("#name_profile").val(profileInfo.name);
  232. $("#description_profile").val(profileInfo.description);
  233. $('#frm-save-profile').modal('show');
  234. });
  235. });
  236. /* Close button in profile matcher items */
  237. $("#profile_search").on("click", "a.closebutton", function() {
  238. skill_id = $(this).attr('rel');
  239. $('input[id=skill_to_select_id_'+skill_id+']').attr('checked', false);
  240. $('#profile_match_item_'+skill_id).remove();
  241. submit_profile_search_form();
  242. toogle_save_profile_form();
  243. });
  244. // Fill saved profiles list
  245. update_my_saved_profiles();
  246. /* Click in profile */
  247. $("#saved_profiles").on("click", "li.load_profile", function() {
  248. profile_id = $(this).attr('rel');
  249. $('input[name="profile_id"]').val(profile_id);
  250. $.ajax({
  251. url: '{{ url }}&a=get_skills_by_profile&profile_id='+profile_id,
  252. success:function(json) {
  253. skill_list = jQuery.parseJSON(json);
  254. $('#profile_search').empty();
  255. $('#skill_holder').empty();
  256. jQuery.each(skill_list, function(index, skill_id) {
  257. skill_info = get_skill_info(skill_id);
  258. li = fill_skill_search_li(skill_id, skill_info.name, 1);
  259. $("#skill_holder").append(li);
  260. add_skill_in_profile_list(skill_id, skill_info.name);
  261. });
  262. submit_profile_search_form();
  263. }
  264. });
  265. });
  266. $("#saved_profiles").on('click', 'li.load_profile button.close', function () {
  267. var $parent = $(this).parent();
  268. var profileId = $parent.attr('rel');
  269. $.getJSON('{{ url }}&a=delete_profile', {
  270. profile: profileId
  271. }, function (response) {
  272. if (response.status) {
  273. $parent.remove();
  274. }
  275. });
  276. });
  277. /* Wheel skill popup form */
  278. /* Close button in gradebook select */
  279. $("#gradebook_holder").on("click", "a.closebutton", function() {
  280. gradebook_id = $(this).attr('rel');
  281. skill_id = $('input[name="id"]').attr('value');
  282. delete_gradebook_from_skill(skill_id, gradebook_id);
  283. });
  284. $("#skill_id").fcbkcomplete({
  285. json_url: "{{ url }}&a=find_skills",
  286. cache: false,
  287. filter_case: false,
  288. filter_hide: true,
  289. complete_text:"{{ 'StartToType' | get_lang }}",
  290. firstselected: true,
  291. //onremove: "testme",
  292. onselect:"check_skills_sidebar",
  293. filter_selected: true,
  294. newel: true
  295. });
  296. load_nodes(0, main_depth);
  297. function update_my_saved_profiles() {
  298. $.ajax({
  299. url: '{{ url }}&a=get_saved_profiles',
  300. success:function(data) {
  301. $("#saved_profiles").html(data);
  302. }
  303. });
  304. }
  305. /* change background color */
  306. $("#celestial").click(function () {
  307. $("#page-back").css("background","#A9E2F3");
  308. });
  309. $("#white").click(function () {
  310. $("#page-back").css("background","#FFFFFF");
  311. });
  312. $("#black").click(function () {
  313. $("#page-back").css("background","#000000");
  314. });
  315. $("#lead").click(function () {
  316. $("#page-back").css("background","#848484");
  317. });
  318. $("#light-yellow").click(function () {
  319. $("#page-back").css("background","#F7F8E0");
  320. });
  321. /* Generated random colour */
  322. /*
  323. function colour(d) {
  324. if (d.children) {
  325. // There is a maximum of two children!
  326. var colours = d.children.map(colour),
  327. a = d3.hsl(colours[0]),
  328. b = d3.hsl(colours[1]);
  329. // L*a*b* might be better here...
  330. return d3.hsl((a.h + b.h) / 2, a.s * 1.2, a.levels_to_show / 1.2);
  331. }
  332. return d.colour || "#fff";
  333. }*/
  334. $('#form-button-edit').on('click', function(e) {
  335. e.preventDefault();
  336. if (SkillWheel.currentSkill === null) {
  337. return;
  338. }
  339. window.location.href = "{{ _p.web_main }}admin/skill_edit.php?id=" + SkillWheel.currentSkill.id;
  340. });
  341. $('#form-button-create-child').on('click', function(e) {
  342. e.preventDefault();
  343. if (SkillWheel.currentSkill === null) {
  344. return;
  345. }
  346. window.location.href = "{{ _p.web_main }}admin/skill_create.php?parent=" + SkillWheel.currentSkill.id;
  347. });
  348. $('#form-button-add-to-profile').on('click', function(e) {
  349. e.preventDefault();
  350. if (SkillWheel.currentSkill === null) {
  351. return;
  352. }
  353. add_skill_in_profile_list(SkillWheel.currentSkill.id, SkillWheel.currentSkill.name);
  354. });
  355. $('#frm-save-profile').on('hidden.bs.modal', function () {
  356. $("#name_profile").val('');
  357. $("#description_profile").val('');
  358. $('input[name="profile_id"]').val(0);
  359. });
  360. $('#form-button-save-profile').on('click', function(e) {
  361. e.preventDefault();
  362. var saveProfile = $.ajax(
  363. '{{ url }}',
  364. {
  365. data: {
  366. a: 'save_profile',
  367. name: $("#name_profile").val(),
  368. description: $("#description_profile").val(),
  369. skill_id: return_skill_list_from_profile_search(),
  370. profile: $('input[name="profile_id"]').val()
  371. }
  372. }
  373. );
  374. $.when(saveProfile).done(function(response) {
  375. if (parseInt(response) === 1 ) {
  376. update_my_saved_profiles();
  377. alert("{{ "Saved" | get_lang }}");
  378. } else {
  379. alert("{{ "Error" | get_lang }}");
  380. }
  381. $('#frm-save-profile').modal('hide');
  382. });
  383. });
  384. });
  385. </script>
  386. <div id="page-back" class="page-skill">
  387. <div class="container-fluid">
  388. <div class="row">
  389. <div class="col-md-3 skill-options">
  390. <div class="skill-home">
  391. <a class="btn btn-large btn-block btn-success" href="{{ _p.web }}user_portal.php"><i class="fa fa-home"></i> {{ "ReturnToCourseList"|get_lang }}</a>
  392. </div>
  393. <!-- ACCORDION -->
  394. <div class="panel-group" id="accordion2">
  395. <div class="panel panel-primary">
  396. <div class="panel-heading">
  397. <a data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
  398. {{ 'SkillsSearch' | get_lang }}
  399. </a>
  400. </div>
  401. <div id="collapseOne" class="panel-collapse collapse">
  402. <div class="panel-body">
  403. <!-- SEARCH -->
  404. <div class="search-skill">
  405. <p class="text">{{ 'EnterTheSkillNameToSearch' | get_lang }}</p>
  406. <form id="skill_search" class="form-search">
  407. <select id="skill_id" name="skill_id" /></select>
  408. <div class="button-skill">
  409. <a class="btn btn-block btn-default load_root" rel="0" href="#"><i class="fa fa-eye"></i> {{ "ViewSkillsWheel"|get_lang }}</a>
  410. <!-- <a id="clear_selection" class="btn btn-danger">{{ "Clear"|get_lang }}</a> -->
  411. </div>
  412. <ul id="skill_holder" class="holder_simple border"></ul>
  413. </form>
  414. </div>
  415. <!-- END SEARCH -->
  416. </div>
  417. </div>
  418. </div>
  419. <div class="panel panel-primary">
  420. <div class="panel-heading">
  421. <a data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
  422. {{ 'ProfileSearch'|get_lang }}
  423. </a>
  424. </div>
  425. <div id="collapseTwo" class="panel-collapse collapse">
  426. <div class="panel-body">
  427. <!-- SEARCH PROFILE -->
  428. <div class="search-profile-skill">
  429. <p class="text">{{ 'WhatSkillsAreYouLookingFor'|get_lang }}</p>
  430. <ul id="profile_search" class="holder holder_simple"></ul>
  431. <form id="search_profile_form" class="form-search">
  432. <button class="btn btn-default btn-block" type="submit"><i class="fa fa-search"></i> {{ "SearchProfileMatches"|get_lang }}</button>
  433. </form>
  434. <p class="text">{{ 'IsThisWhatYouWereLookingFor'|get_lang }}</p>
  435. <form id="save_profile_form_button" class="form-search">
  436. <button class="btn btn-default btn-block" type="submit"><i class="fa fa-floppy-o"></i> {{ "SaveThisSearch"|get_lang }}</button>
  437. </form>
  438. </div>
  439. <!-- END SEARCH PROFILE-->
  440. <div id="saved_profiles"></div>
  441. </div>
  442. </div>
  443. </div>
  444. <div class="panel panel-primary">
  445. <div class="panel-heading">
  446. <a data-toggle="collapse" data-parent="#accordion2" href="#collapseThree">
  447. {{ 'DisplayOptions' | get_lang }}
  448. </a>
  449. </div>
  450. <div id="collapseThree" class="panel-collapse collapse">
  451. <div class="panel-body">
  452. <p class="text">{{ 'ChooseABackgroundColor' | get_lang }}</p>
  453. <ul>
  454. <li><a href="#" id="white">{{ 'White' | get_lang }}</a></li>
  455. <li><a href="#" id="black">{{ 'Black' | get_lang }}</a></li>
  456. <li><a href="#" id="celestial">{{ 'LightBlue' }}</a></li>
  457. <li><a href="#" id="lead">{{ 'Gray' | get_lang }}</a></li>
  458. <li><a href="#" id="light-yellow">{{ 'Corn' | get_lang }}</a></li>
  459. </ul>
  460. </div>
  461. </div>
  462. </div>
  463. <div class="panel panel-primary">
  464. <div class="panel-heading">
  465. <a data-toggle="collapse" data-parent="#accordion2" href="#collapseFour">
  466. {{ "Legend"|get_lang }}
  467. </a>
  468. </div>
  469. <div id="collapseFour" class="panel-collapse collapse">
  470. <div class="panel-body">
  471. <p class="text"><span class="skill-legend-add">&nbsp;&nbsp;&nbsp;&nbsp;</span> {{ "SkillsYouCanLearn"|get_lang }}</p>
  472. <p class="text"><span class="skill-legend-search">&nbsp;&nbsp;&nbsp;&nbsp;</span> {{ "SkillsSearchedFor"|get_lang }}</p>
  473. </div>
  474. </div>
  475. </div>
  476. </div>
  477. <!-- END ACCORDEON -->
  478. </div>
  479. <div id="wheel_container" class="col-md-9">
  480. <div id="skill_wheel">
  481. <img src="">
  482. </div>
  483. </div>
  484. </div>
  485. </div>
  486. </div>
  487. <div class="modal fade" id="frm-skill" tabindex="-1" role="dialog" aria-labelledby="form-skill-title" aria-hidden="true">
  488. <div class="modal-dialog modal-lg">
  489. <div class="modal-content">
  490. <div class="modal-header">
  491. <button type="button" class="close" data-dismiss="modal" aria-label="{{ "Close" | get_lang }}">
  492. <span aria-hidden="true">&times;</span>
  493. </button>
  494. <h4 class="modal-title" id="form-skill-title">{{ "Skill" | get_lang }}</h4>
  495. </div>
  496. <div class="modal-body">
  497. {{ dialogForm }}
  498. </div>
  499. <div class="modal-footer">
  500. <button id="form-button-edit" class="btn btn-primary">
  501. <i class="fa fa-edit"></i> {{ "Edit" | get_lang }}
  502. </button>
  503. <button id="form-button-create-child" class="btn btn-primary">
  504. <i class="fa fa-plus"></i> {{ "CreateChildSkill" | get_lang }}
  505. </button>
  506. <button id="form-button-add-to-profile" class="btn btn-primary">
  507. <i class="fa fa-check"></i> {{ "AddSkillToProfileSearch" | get_lang }}
  508. </button>
  509. <button type="button" class="btn btn-primary" data-dismiss="modal">
  510. <i class="fa fa-close"></i> {{ "Close" | get_lang }}
  511. </button>
  512. </div>
  513. </div>
  514. </div>
  515. </div>
  516. <div class="modal fade" id="frm-save-profile" tabindex="-1" role="dialog" aria-labelledby="form-save-profile-title" aria-hidden="true">
  517. <div class="modal-dialog modal-lg">
  518. <div class="modal-content">
  519. <div class="modal-header">
  520. <button type="button" class="close" data-dismiss="modal" aria-label="{{ "Close" | get_lang }}">
  521. <span aria-hidden="true">&times;</span>
  522. </button>
  523. <h4 class="modal-title" id="form-save-profile-title">{{ "SkillProfile" | get_lang }}</h4>
  524. </div>
  525. <div class="modal-body">
  526. {{ saveProfileForm }}
  527. </div>
  528. <div class="modal-footer">
  529. <button id="form-button-save-profile" class="btn btn-primary">
  530. <i class="fa fa-save"></i> {{ "Save" | get_lang }}
  531. </button>
  532. <button type="button" class="btn btn-primary" data-dismiss="modal">
  533. <i class="fa fa-close"></i> {{ "Close" | get_lang }}
  534. </button>
  535. </div>
  536. </div>
  537. </div>
  538. </div>