index.tpl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. {{javascript}}
  2. <script type="text/javascript">
  3. {% if is_allowed_to_edit %}
  4. var sec_token = '{{sec_token}}';
  5. {% endif %}
  6. $(function() {
  7. $('.collapsible .head').click(function(e) {
  8. $(this).toggleClass('collapsed');
  9. $(this).next().toggle();
  10. return true;
  11. });
  12. {% if is_allowed_to_edit %}
  13. $(".categories.sortable" ).sortable({
  14. axis: 'y',
  15. handle: '.handle',
  16. //placeholder: 'ui-state-highlight',
  17. update: function(event, ui) {
  18. var c_id = 0;
  19. var ids = [];
  20. var items;
  21. items = $(this).children('li');
  22. items.each(function(index, li){
  23. li = $(li);
  24. var id;
  25. id = li.attr('data-id');
  26. c_id = li.attr('data-c_id');
  27. ids.push(id);
  28. });
  29. LinkCategory.sort(c_id, ids, message.update);
  30. }
  31. });
  32. $(".categories.sortable" ).disableSelection();
  33. $(".links.sortable" ).sortable({
  34. axis: 'y',
  35. placeholder: 'ui-state-highlight',
  36. update: function(event, ui) {
  37. var c_id = 0;
  38. var ids = [];
  39. var items;
  40. items = $(this).children('li');
  41. items.each(function(index, li){
  42. li = $(li);
  43. var id;
  44. id = li.attr('data-id');
  45. c_id = li.attr('data-c_id');
  46. ids.push(id);
  47. });
  48. Link.sort(c_id, ids, message.update);
  49. }
  50. });
  51. $(".links.sortable" ).disableSelection();
  52. {% endif %}
  53. });
  54. function expand_all(){
  55. $('.collapsible .head').removeClass('collapsed').next().show();
  56. }
  57. function collapse_all(){
  58. $('.collapsible .head').addClass('collapsed').next().hide();
  59. }
  60. function delete_category(name){
  61. if(!confirm("{{'ConfirmYourChoice'|get_lang}}")){
  62. return false;
  63. }
  64. var item = $('#'+name);
  65. var id = item.attr('data-id');
  66. var c_id = item.attr('data-c_id');
  67. var f = function(data){
  68. if(data.success){
  69. item.remove();
  70. }
  71. message.update(data);
  72. };
  73. LinkCategory.del(c_id, id, f);
  74. }
  75. function delete_all(){
  76. if(!confirm("{{'ConfirmYourChoice'|get_lang}}")){
  77. return false;
  78. }
  79. var f = function(data){
  80. if(data.success){
  81. var item = $('.data');
  82. item.remove();
  83. }
  84. message.update(data);
  85. };
  86. Link.delete_by_course({{c_id}}, {{session_id}}, f);
  87. }
  88. function delete_link(name, btn){
  89. if(!confirm("{{'ConfirmYourChoice'|get_lang}}")){
  90. return false;
  91. }
  92. var item = $('#'+name);
  93. var id = item.attr('data-id');
  94. var c_id = item.attr('data-c_id');
  95. var f = function(data){
  96. if(data.success){
  97. item.remove();
  98. }else{
  99. $(btn).removeClass("loading");
  100. }
  101. message.update(data);
  102. };
  103. $(btn).addClass("loading");
  104. Link.del(c_id, id, f);
  105. }
  106. function switch_li_visibility(name, btn)
  107. {
  108. var li = $('#'+name);
  109. var id = li.attr('data-id');
  110. var c_id = li.attr('data-c_id');
  111. var is_visible = !li.hasClass('invisible')
  112. var f = function(data){
  113. if(data.success){
  114. var btn = $('.btn.visibility', li);
  115. if(is_visible){
  116. btn.addClass('show');
  117. btn.removeClass('hide');
  118. li.addClass('invisible');
  119. li.removeClass('visible');
  120. }else{
  121. btn.removeClass('show');
  122. btn.addClass('hide');
  123. li.removeClass('invisible');
  124. li.addClass('visible');
  125. }
  126. }
  127. message.update(data);
  128. $(btn).removeClass("loading");
  129. };
  130. if(is_visible){
  131. Link.hide(c_id, id, f);
  132. }else{
  133. Link.show(c_id, id, f);
  134. }
  135. $(btn).addClass("loading");
  136. }
  137. function validate_link(name, btn){
  138. var li = $('#'+name);
  139. var id = li.attr('data-id');
  140. var c_id = li.attr('data-c_id');
  141. var f = function(data){
  142. if(data.success){
  143. li.addClass('valid');
  144. li.removeClass('invalid');
  145. }else{
  146. li.addClass('invalid');
  147. li.removeClass('valid');
  148. }
  149. message.update(data);
  150. $(btn).removeClass("loading");
  151. };
  152. $(btn).addClass("loading");
  153. Link.validate(c_id, id, f);
  154. }
  155. </script>
  156. <div id="messages">
  157. {% for message in messages %}
  158. {{ message }}
  159. {% endfor %}
  160. </div>
  161. <div class="btn-toolbar actions-bar" >
  162. {% if is_allowed_to_edit %}
  163. <div class="btn-group edit">
  164. <a href="{{root}}&amp;action=add_category" class="btn new_folder" title="{{'AddCategory'|get_lang}}">
  165. <em class="size-32 icon-new-folder"></em>
  166. </a>
  167. <a href="{{root}}&amp;action=add_link" class="btn new_link" title="{{'AddLink'|get_lang}}">
  168. <em class="size-32 icon-new-link"></em>
  169. </a>
  170. <a href="javascript:void(0)" onclick="delete_all();return false;" class="btn btn-default" title="{{'DeleteAll'|get_lang}}">
  171. <em class="size-32 icon-delete-all"></em>
  172. </a>
  173. <a href="{{root}}&amp;action=import_csv" class="btn import_csv" title="{{'ImportCSV'|get_lang}}">
  174. <em class="size-32 icon-import-csv"></em>
  175. </a>
  176. <a href="{{root}}&amp;action=export_csv" class="btn" title="{{'ExportAsCSV'|get_lang}}">
  177. <em class="size-32 icon-export-csv"></em>
  178. </a>
  179. </div>
  180. {% endif %}
  181. <div class="btn-group">
  182. <a href="javascript:void(0)" onclick="expand_all();return false;" class="btn btn-default" title="{{'ShowAll'|get_lang}}">
  183. <em class="size-32 icon-expand"></em>
  184. </a>
  185. <a href="javascript:void(0)" onclick="collapse_all();return false;" class="btn btn-default" title="{{'ShowNone'|get_lang}}">
  186. <em class="size-32 icon-collapse"></em>
  187. </a>
  188. </div>
  189. </div>
  190. <div class="data">
  191. <ul style="list-style: none; margin-left:0;" class="links sortable">
  192. {% for link in links %}
  193. {% set link_class %}
  194. {% if loop.first %}first{% endif %}
  195. {% if loop.last %}last{% endif %}
  196. {% if loop.index is odd %}odd{% else %}even{% endif %}
  197. {% if link.is_visible() %}visible{% else %}invisible{% endif %}
  198. {% endset %}
  199. <li id="link_{{link.id}}" class="link {{link_class}}" data-id="{{link.id}}" data-c_id="{{link.c_id}}" data-type="link" >
  200. <a class="icon" target="{{link.target}}" href="{{root}}&amp;action=go&amp;id={{link.id}}&amp;c_id={{link.c_id}}">
  201. {{ 'link.png' |icon(22)}}
  202. </a>
  203. <a class="title" target="{{link.target}}" href="{{root}}&amp;action=go&amp;id={{link.id}}&amp;c_id={{link.c_id}}">
  204. {%if link.title %}{{link.title}}{% else %}{{link.url}}{%endif%}
  205. </a>
  206. {% if link.session_id %}
  207. {{session_image}}
  208. {% endif %}
  209. <div class="status" style="display:inline-block;">&nbsp;</div>
  210. {% if is_allowed_to_edit %}
  211. <div style="float:right;">
  212. <a href="javascript:void(0)" onclick="validate_link('link_{{link.id}}', this);return false;"
  213. title="{{'CheckURL'|get_lang}}"
  214. class="btn validate_link">
  215. </a>
  216. <a href="{{root}}&amp;action=edit_link&amp;id={{link.id}}&amp;c_id={{link.c_id}}"
  217. title="{{'Edit'|get_lang}}"
  218. class="">
  219. <em class="size-22 icon-edit"></em>
  220. </a>
  221. <a href="javascript:void(0)" onclick="switch_li_visibility('link_{{link.id}}', this);return false;"
  222. class="btn visibility {%if link.visibility == 1%}hide{%else%}show{%endif%}">
  223. </a>
  224. <a href="javascript:void(0)" onclick="delete_link('link_{{link.id}}', this);return false;" title="{{'Delete'|get_lang}}" class="">
  225. <em class="size-22 icon-delete"></em>
  226. </a>
  227. </div>
  228. {% endif %}
  229. <div class="description">{{link.description}}</div>
  230. </li>
  231. {% endfor%}
  232. </ul>
  233. <ul id="link_categories" class="categories sortable" style="list-style: none; margin-left:0;">
  234. {% for category in categories %}
  235. <li id="category_{{category.id}}" class="link_category collapsible" data-id="{{category.id}}" data-c_id="{{category.c_id}}" data-type="category" >
  236. <div class="head handle collapsed">
  237. {% if is_allowed_to_edit %}
  238. <div style="float:right;">
  239. <a href="{{root}}&amp;action=edit_category&amp;id={{category.id}}&amp;c_id={{category.c_id}}"
  240. onclick="event.stopPropagation();"
  241. title="{{'Edit'|get_lang}}"
  242. class="">
  243. <em class="size-22 icon-edit"></em>
  244. </a>
  245. <a href="javascript:void(0)"
  246. onclick="delete_category('category_{{category.id}}');event.stopPropagation();return false;"
  247. title="{{'Delete'|get_lang}}"
  248. class="">
  249. <em class="size-22 icon-delete"></em>
  250. </a>
  251. </div>
  252. {% endif %}
  253. <h3>
  254. <a href="{{root}}&amp;action=view&amp;id={{category.id}}&amp;c_id={{category.c_id}}">{{category.category_title|escape}}</a>
  255. </h3>
  256. {{category.description}}
  257. </div>
  258. <div class="body" style="display:none;">
  259. <ul style="list-style: none; margin-left:0;" class="links sortable">
  260. {% for link in category.links %}
  261. {% set link_class %}
  262. {% if loop.first %}first{% endif %}
  263. {% if loop.last %}last{% endif %}
  264. {% if loop.index is odd %}odd{% else %}even{% endif %}
  265. {% if link.is_visible() %}visible{% else %}invisible{% endif %}
  266. {% endset %}
  267. <li id="link_{{link.id}}" class="link {{link_class}}" data-id="{{link.id}}" data-c_id="{{link.c_id}}" data-type="link" >
  268. <a class="icon" target="{{link.target}}" href="{{root}}&amp;action=go&amp;id={{link.id}}&amp;c_id={{link.c_id}}">
  269. {{ 'link.png' |icon(22) }}
  270. </a>
  271. <a class ="title" target="{{link.target}}" href="{{root}}&amp;action=go&amp;id={{link.id}}&amp;c_id={{link.c_id}}">
  272. {%if link.title %}{{link.title}}{% else %}{{link.url}}{%endif%}
  273. </a>
  274. {% if link.session_id %}
  275. {{session_image}}
  276. {% endif %}
  277. <div class="status" style="display:inline-block;">&nbsp;</div>
  278. {% if is_allowed_to_edit %}
  279. <div style="float:right;">
  280. <a href="javascript:void(0)" onclick="validate_link('link_{{link.id}}', this);return false;"
  281. title="{{'CheckURL'|get_lang}}"
  282. class="btn validate_link"></a>
  283. <a href="{{root}}&amp;action=edit_link&amp;id={{link.id}}&amp;c_id={{link.c_id}}"
  284. onclick=""
  285. title="{{'Edit'|get_lang}}"
  286. class="">
  287. <em class="size-22 icon-edit"></em>
  288. </a>
  289. <a href="javascript:void(0)"
  290. onclick="switch_li_visibility('link_{{link.id}}', this);return false;"
  291. class="btn visibility {%if link.visibility == 1%}hide{%else%}show{%endif%}"></a>
  292. <a href="javascript:void(0)"
  293. onclick="delete_link('link_{{link.id}}', this);return false;"
  294. title="{{'Delete'|get_lang}}"
  295. class="">
  296. <em class="size-22 icon-delete"></em>
  297. </a>
  298. </div>
  299. {% endif %}
  300. </li>
  301. {% endfor%}
  302. </ul>
  303. </div>
  304. <div class="details "></div>
  305. </li>
  306. {% endfor%}
  307. </ul>
  308. </div>