PageRenderTime 2735ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_base_list.html

https://gitlab.com/g66shivam/gstudio
HTML | 422 lines | 307 code | 88 blank | 27 comment | 0 complexity | dcb8511da0aa9aff7347940e9b657227 MD5 | raw file
  1. {% extends "ndf/mis_base.html" %}
  2. {% load i18n %}
  3. {% load ndf_tags %}
  4. {% load pagination_tags %}
  5. {% block title %} {{ title }} {% endblock %}
  6. {% block body_content %}
  7. {% check_is_gstaff groupid request.user as gstaff_access %}
  8. {% if nodes.count %}
  9. {% autopaginate nodes 25 %}
  10. <div id="myModal" class="reveal-modal" data-reveal style="height:500px;overflow:scroll;">
  11. <h3>{% trans "Are you sure you want to delete? All of the following related items also will be deleted!" %}</h3>
  12. <input class="button confirmDeleteObjects" type="button" value="Confirm">
  13. <input class="button cancelDeleteObjects" type="button" value="Cancel">
  14. <div id="deletion_results"></div>
  15. <a class="close-reveal-modal"> &#215;</a>
  16. </div>
  17. <div id="linkModal" class="reveal-modal small" data-reveal>
  18. <center>
  19. {% blocktrans %}<h3>Link user-account to respective user-details</h3>
  20. <p>NOTE: Please provide username of the user (i.e. student/voluntary-teacher), that he/she has registered on to the website.</p>
  21. {% endblocktrans %}
  22. </center>
  23. <form id="linkform" data-abide>
  24. <div class="row">
  25. <div class="small-2 small-offset-2 columns">
  26. <label for="link_to" class="inline left">{% trans "Username:" %}</label>
  27. </div>
  28. <div class="small-6 columns end">
  29. <input id="link_to" name="link_to" type="text" required >
  30. <small class="error">{% trans "Please fill username!" %}</small>
  31. </div>
  32. </div>
  33. <div class="row">
  34. <div class="small-4 small-offset-4 columns end">
  35. <input type="button" class="button small link_to_ac" value="Link to User A/C" disabled />
  36. </div>
  37. </div>
  38. </form>
  39. <a class="close-reveal-modal">{% trans "&#215" %};</a>
  40. </div>
  41. {% if gstaff_access %}
  42. <input class="button deleteObjects" type="button" value="Delete">
  43. {% endif %}
  44. <form method="POST" style="float:right; margin-top:15px;padding-top:10px;">
  45. {% csrf_token %}
  46. <input name="search" type="textbox" value="" style="width:300px;">
  47. <input type="hidden" name="class" value="{{class_name}}">
  48. <input type="submit" value="search" style="width:100px;">
  49. </form>
  50. {% endif %}
  51. {% if nodes.count %}
  52. <table >
  53. <thead>
  54. <tr>
  55. <th width="20"> <input class="checkedAll" type="checkbox"></th>
  56. <th>Title</th>
  57. {% if gstaff_access %}
  58. <th>Edit</th>
  59. {% comment %}
  60. <!--
  61. <th>Confirmation status</th>
  62. {% if is_link_needed %}
  63. <th>Link to User A/C</th>
  64. {% endif %}
  65. -->
  66. {% endcomment %}
  67. {% endif %}
  68. </tr>
  69. </thead>
  70. <tbody>
  71. {% for each in nodes %}
  72. <tr>
  73. <td id="{{each.pk}}" class="objectsCheckbox"> <input type="checkbox"> </td>
  74. {% if app_name == "MIS" %}
  75. <td style="font-size:14px;">
  76. <a href="{% url 'mis:mis_app_instance_detail' groupid app_id app_set_id each.pk %}">{{each.name}}</a>
  77. </td>
  78. {% else %}
  79. <td style="font-size:14px;">
  80. <a href="{% url 'mis-po:mis_app_instance_detail' groupid app_id app_set_id each.pk %}">{{each.name}}</a>
  81. </td>
  82. {% endif %}
  83. {% if gstaff_access %}
  84. <!-- Show below Edit, Confirm & Link buttons only to GStaff members -->
  85. {% if app_name == "MIS" %}
  86. <td>
  87. <a href="{% url 'mis:mis_app_instance_edit' groupid app_id app_set_id each.pk %}" style="font-size:14px;" class="button small">{% trans "Edit" %}</a>
  88. </td>
  89. {% else %}
  90. <td>
  91. <a href="{% url 'mis-po:mis_app_instance_edit' groupid app_id app_set_id each.pk %}" style="font-size:14px;" class="button small">{% trans "Edit" %}</a>
  92. </td>
  93. {% endif %}
  94. {% comment %}
  95. <!--
  96. <td>
  97. <div id="enrollement_code_{{each.pk}}">
  98. <a href="#" class="button small enrollment_code" onclick="get_enrollment_code('{{each.pk}}')">Confirm</a>
  99. </div>
  100. </td>
  101. {% if is_link_needed %}
  102. {% check_node_linked each.pk as is_linked %}
  103. <td style="font-size:11px;">
  104. <input id="link_{{each.pk}}" data-reveal-id="linkModal" type="button" style="font-size:14px;" class="button small link"
  105. {% if is_linked %}value="Linked" disabled="disabled"
  106. {% else %}value="Link"
  107. {% endif %}
  108. />
  109. </td>
  110. {% endif %}
  111. -->
  112. {% endcomment %}
  113. <!-- endif of GStaff members -->
  114. {% endif %}
  115. </tr>
  116. {% endfor %}
  117. </tbody>
  118. </table>
  119. {% else %}
  120. <div class="row">
  121. <div class="small-12 columns">
  122. <h5> {% trans "This group doesn't have a registered" %}<b> {{title}}</b>. </h5>
  123. </div>
  124. </div>
  125. {% endif %}
  126. {% paginate %}
  127. {% endblock %}
  128. {% block script %}
  129. {{block.super}}
  130. $(document).on('click', ".checkedAll", function() {
  131. if($(this).is(":checked")==true){
  132. $('.objectsCheckbox input').prop( "checked", true );
  133. }
  134. else{
  135. $('.objectsCheckbox input').prop( "checked", false );
  136. }
  137. });
  138. $(document).on('click', ".button.confirmDeleteObjects", function() {
  139. var selectedobject = $(".objectsCheckbox input:checked")
  140. $('#myModal').foundation('reveal', 'open');
  141. // $('#myModal').foundation('reveal', 'close');
  142. if(selectedobject.length > 0) {
  143. var i = 0;
  144. var str = "";
  145. $.map(selectedobject, function(each) {
  146. if(i == 0) {
  147. str = str.concat(each.parentElement.id)
  148. }
  149. else {
  150. str = str.concat(","+each.parentElement.id)
  151. }
  152. i = i+1
  153. })
  154. $.ajax({
  155. url: "{% url 'deletion_instances' groupid %}",
  156. type: 'POST',
  157. data: {deleteobjects:str,csrfmiddlewaretoken: '{{ csrf_token }}',confirm:"yes"},
  158. beforeSend: function() {},
  159. success: function(result) {
  160. },
  161. complete: function() {
  162. $('#myModal').foundation('reveal', 'close');
  163. }
  164. });
  165. $.map(selectedobject,function(each) {
  166. each.parentElement.parentElement.remove()
  167. });
  168. $('#myModal').foundation('reveal', 'close');
  169. }
  170. else {
  171. alert("select object to delete");
  172. }
  173. });
  174. $(document).on('click',".button.deleteObjects",function(){
  175. var selectedobject = $(".objectsCheckbox input:checked");
  176. // $('#myModal').foundation('reveal', 'close');
  177. if(selectedobject.length > 0) {
  178. $('#myModal').foundation('reveal', 'open');
  179. // var confirmed = confirm("Deleting "+selectedobject.length+" objects");
  180. // if(confirmed == true){
  181. var i = 0;
  182. var str = "";
  183. $.map(selectedobject,function(each) {
  184. if(i == 0) {
  185. str = str.concat(each.parentElement.id)
  186. }
  187. else {
  188. str = str.concat(","+each.parentElement.id)
  189. }
  190. i= i+1;
  191. });
  192. $.ajax({
  193. url: "{% url 'deletion_instances' groupid %}",
  194. type: 'POST',
  195. data: {deleteobjects:str, csrfmiddlewaretoken: '{{ csrf_token }}'},
  196. beforeSend: function() {},
  197. success: function(result) {
  198. $("#deletion_results").html("");
  199. for(var obj in result){
  200. var ulist = $("<ul>"+"</ul>")
  201. .attr("id","conceptlist")
  202. .appendTo($("#deletion_results"));
  203. var li = $("<li><b>"+result[obj].title+"</b></li>")
  204. .appendTo(ulist);
  205. var ulist1 = $("<ul>"+"</ul>")
  206. .attr("id","conceptlist")
  207. .appendTo(li);
  208. for(var obj2 in result[obj].content) {
  209. object = result[obj].content[obj2]
  210. for(var obj3 in object) {
  211. for(var each in object[obj3]) {
  212. var li1 = $("<li>"+object[obj3][each]+"</li>")
  213. .appendTo(ulist1);
  214. }
  215. }
  216. }
  217. }
  218. },
  219. complete: function() {}
  220. });
  221. // }
  222. }
  223. else {
  224. alert("select object to delete");
  225. }
  226. });
  227. $(document).on('click',".button.cancelDeleteObjects",function(){
  228. $('#myModal').foundation('reveal', 'close');
  229. });
  230. // ========================================================================================
  231. /*
  232. * Code regarding "Link" button & its reveal-modal (id: linkModal)
  233. + linkModal consists of
  234. - text-box: link_to (id)
  235. - button: link_to_ac (class)
  236. */
  237. var link_username = ""
  238. var parent_link_button = ""
  239. var is_linked = false
  240. $(".link").click(function() {
  241. /*
  242. * Stores the current clicked button object from given list of "Link" buttons
  243. */
  244. parent_link_button = $(this);
  245. });
  246. $("#link_to").bind("keyup keypress onmouseup blur change", function() {
  247. /*
  248. * Changes state (disabled/enabled) of "Link to User A/C" button (class: link_to_ac)
  249. * depending on whether text-box (id: link_to) having some input or not
  250. */
  251. link_username = $("#link_to").val().trim()
  252. if (link_username != "") {
  253. if ($(".link_to_ac").attr("disabled")) {
  254. $(".link_to_ac").removeAttr('disabled');
  255. }
  256. }
  257. else {
  258. if (!$(".link_to_ac").attr("disabled")) {
  259. $(".link_to_ac").attr("disabled", "disabled")
  260. }
  261. }
  262. });
  263. $(".link_to_ac").click(function() {
  264. /*
  265. * On click of "Link to User A/C" button
  266. + Retrieves
  267. - ObjectId of node from parent ("Link") button's id attribute
  268. - Username from text-box
  269. + Ajax call made to "set_user_link" url
  270. + Parameters passed
  271. - ObjectId of group (groupid) via url
  272. - ObjectId of node (node_id) via POST request
  273. - Username entered (username) via POST request
  274. + Depending on the result of the ajax call, label of parent button is modified:
  275. - If successful, Linked.
  276. - Else, it remains as Link only!
  277. */
  278. link_node_id = parent_link_button.attr('id').slice(5) // remove "link_" from given id
  279. link_username = $("#link_to").val()
  280. $.ajax({
  281. url:"{% url 'set_user_link' groupid %}",
  282. data: {
  283. node_id: link_node_id,
  284. username: link_username,
  285. csrfmiddlewaretoken: "{{csrf_token}}"
  286. },
  287. type: "POST",
  288. dataType: "json",
  289. complete: function () {
  290. $('#linkModal').foundation('reveal', 'close');
  291. },
  292. success: function (data) {
  293. is_linked = data["result"]
  294. alert(data["message"])
  295. if (is_linked) {
  296. parent_link_button.attr("disabled", "disabled")
  297. parent_link_button.val("Linked");
  298. }
  299. }
  300. });
  301. });
  302. $(document).on('closed.fndtn.reveal', '[data-reveal]', function () {
  303. /*
  304. * On closing of reveal-modal
  305. - Clear text-box (id: link_to)
  306. - Disable "Link to User A/C" button
  307. */
  308. $("#link_to").val("")
  309. if (is_linked) {
  310. $(".link_to_ac").attr("disabled", "disabled")
  311. }
  312. });
  313. // ========================================================================================
  314. function get_enrollment_code(node_id) {
  315. alert("node_id: " + node_id)
  316. $.ajax({
  317. url:"{% url 'set_enrollment_code' groupid %}",
  318. data: {
  319. node_id: node_id,
  320. csrfmiddlewaretoken: "{{csrf_token}}"
  321. },
  322. type: "POST",
  323. dataType: "html",
  324. success: function(data) {
  325. $("#enrollement_code_"+node_id).html("Enrollment Code: <br><b>"+data+"</b>")
  326. },
  327. error: function(data) {
  328. alert("EnrollementCodeError: Either not an ajax call or not a POST request!!!")
  329. }
  330. });
  331. }
  332. {% endblock %}