PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/core/limsadmin.container_types.php

https://bitbucket.org/unixcrab/colab-lims
PHP | 220 lines | 181 code | 34 blank | 5 comment | 18 complexity | 102a5fa9a1f40d4cd98966d371e0aba1 MD5 | raw file
  1. <div id="user_feedback" class="alert alert-info" style="display: none;">
  2. <? print $_SESSION['lims']['langdata']['please_complete']; ?>
  3. </div>
  4. <div id="containerTypeList">
  5. <h4><?php print $_SESSION['lims']['langdata']['limsadmin_container_types']; ?></h4>
  6. <hr>
  7. <table id="containerTypesTable" class="table table-hover table-condensed tablesorter" style="width: 80%;">
  8. <thead>
  9. <tr>
  10. <th><?php print $_SESSION['lims']['langdata']['name']; ?></th>
  11. <th><?php print $_SESSION['lims']['langdata']['rows']; ?></th>
  12. <th><?php print $_SESSION['lims']['langdata']['columns']; ?></th>
  13. <th><?php print $_SESSION['lims']['langdata']['capacity']; ?></th>
  14. <th></th>
  15. </tr>
  16. </thead>
  17. <tbody>
  18. <?php
  19. include "functions.lims.php";
  20. $cts = getContainerTypes();
  21. if( count($cts) == 0 )
  22. print "<strong>".$_SESSION['lims']['langdata']['limsadmin_no_storage_devices']."</strong>";
  23. foreach($cts as $ct) {
  24. $ctype_del_link = "<a href='#' id='containerTypeDel-".$ct->id."'>".$icon_trash."</a>";
  25. if( containerTypeInUse($ct->id) ) $ctype_del_link = "<i class='icon-trash' title='".$_SESSION['lims']['langdata']['cannot_delete'].": ".$_SESSION['lims']['langdata']['err_in_use']."' rel='tooltip' data-placement='right'></i>";
  26. print "<tr><td id='containerTypeName-".$ct->id."'>".myhtmlentities($ct->container_type)."</td><td id='containerTypeRows-".$ct->id."'>".$ct->number_of_rows."</td><td id='containerTypeColumns-".$ct->id."'>".$ct->number_of_columns."</td><td id='containerTypeCapacity-".$ct->id."'>".$ct->capacity."</td><td><a href='#' id='containerTypeEdit-".$ct->id."'>".$icon_edit."</a>&nbsp;&nbsp;&nbsp;".$ctype_del_link."</td></tr>\n";
  27. //print "<tr><td id='containerTypeName-".$ct->id."'>".$ct->container_type."</td><td id='containerTypeRows-".$ct->id."'>".$ct->number_of_rows."</td><td id='containerTypeColumns-".$ct->id."'>".$ct->number_of_columns."</td><td id='containerTypeCapacity-".$ct->id."'>".$ct->capacity."</td><td><a href='#' id='containerTypeEdit-".$ct->id."'><i class='icon-edit' title='".$_SESSION['lims']['langdata']['edit']."' data-placement='right' rel='tooltip'></i></a>&nbsp;&nbsp;&nbsp;<a href='#'><i class='icon-trash' id='containerTypeDel-".$ct->id."' title='".$_SESSION['lims']['langdata']['delete']."' data-placement='right'></i></a></td></tr>\n";
  28. }
  29. ?>
  30. </tbody>
  31. </table>
  32. <!-- <br/> -->
  33. <hr>
  34. </div>
  35. <div id="newContainerTypeDef" style="display:none;">
  36. <h4><?php print $_SESSION['lims']['langdata']['limsadmin_new_container_type']; ?></h4>
  37. <hr/>
  38. <form>
  39. <label><?php print $_SESSION['lims']['langdata']['type']; ?>:</label>
  40. <input type="text" id="newContainerTypeName">
  41. <label><?php print $_SESSION['lims']['langdata']['rows']; ?>:</label>
  42. <input type="text" id="newContainerTypeRows" value="1">
  43. <label><?php print $_SESSION['lims']['langdata']['columns']; ?>:</label>
  44. <input type="text" id="newContainerTypeColumns" value="1">
  45. <label><?php print $_SESSION['lims']['langdata']['capacity']; ?>:</label>
  46. <input type="text" id="newContainerTypeCapacity" value="1" disabled="disabled">
  47. <br/>
  48. <button type="submit" class="btn btn-primary" id="newContainerTypeSave"><?php print $button_save; ?></button>
  49. </form>
  50. </div>
  51. <button class="btn btn-primary" id="newContainerTypeBtn"><i class="icon-plus icon-white"></i> <?php print $_SESSION['lims']['langdata']['limsadmin_new_container_type']; ?></button>
  52. <!-- Edit Modal -->
  53. <div id="containerTypeEditModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="containerTypeEditModalLabel" aria-hidden="true">
  54. <div class="modal-header">
  55. <!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>-->
  56. <h4 id="containerTypeEditModalLabel"></h4>
  57. </div>
  58. <div class="modal-body">
  59. <form>
  60. <label class="control-label" for="containerTypeEditName" id="containerTypeEditNameLabel"><?php print $_SESSION['lims']['langdata']['name']; ?>:</label>
  61. <input type="text" id="containerTypeEditName">
  62. <label class="control-label" for="containerTypeEditRows" id="containerTypeEditRowsLabel"><?php print $_SESSION['lims']['langdata']['rows']; ?>:</label>
  63. <input type="text" id="containerTypeEditRows">
  64. <label class="control-label" for="containerTypeEditColumns" id="containerTypeEditColumnsLabel"><?php print $_SESSION['lims']['langdata']['columns']; ?>:</label>
  65. <input type="text" id="containerTypeEditColumns">
  66. <label class="control-label" for="containerTypeEditCapacity" id="containerTypeEditCapacityLabel"><?php print $_SESSION['lims']['langdata']['capacity']; ?>:</label>
  67. <input type="text" id="containerTypeEditCapacity" disabled="disabled">
  68. </form>
  69. </div>
  70. <div class="modal-footer">
  71. <button class="btn btn-warning" id="containerTypeEditCancel"><?php print $button_cancel; ?></button>
  72. <button class="btn btn-primary" id="containerTypeEditSave"><?php print $button_save; ?></button>
  73. </div>
  74. </div>
  75. <!-- Delete Modal -->
  76. <div id="containerTypeDelModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="containerTypeDelModalLabel" aria-hidden="true">
  77. <div class="modal-header">
  78. <!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>-->
  79. <h4 id="containerTypeDelModalLabel"><i class="icon-trash"></i> <?php print $_SESSION['lims']['langdata']['delete']; ?></h4>
  80. </div>
  81. <div class="modal-body" id="containerTypeDelModalBody">
  82. </div>
  83. <div class="modal-footer">
  84. <button class="btn btn-warning" id="containerTypeDelCancel"><?php print $button_cancel; ?></button>
  85. <button class="btn btn-danger" id="containerTypeDelConfirm"><?php print $button_trash; ?></button>
  86. </div>
  87. </div>
  88. <script src="core/js/__jquery.tablesorter/jquery.tablesorter.min.js"></script>
  89. <script>
  90. $(function() {
  91. $("#containerTypesTable").tablesorter({headers:{4:{sorter:false}}});
  92. $('#containerTypeDelCancel').click( function() {
  93. $('#containerTypeDelConfirm').unbind('click');
  94. $('#containerTypeDelModal').modal('hide');
  95. });
  96. $('#containerTypeEditCancel').click( function() {
  97. $('#containerTypeEditSave').unbind('click');
  98. $('#containerTypeEditModal').modal('hide');
  99. });
  100. $('#newContainerTypeBtn').click(function(){
  101. $(this).slideUp(200);
  102. $('#containerTypeList').slideUp( 200, function() { $('#newContainerTypeDef').slideDown(200); });
  103. });
  104. $('#newContainerTypeSave').click( function(){
  105. var newCTName = encodeURIComponent( $('#newContainerTypeName').val() );
  106. var newCTCap = encodeURIComponent( $('#newContainerTypeCapacity').val() );
  107. var newCTRows = encodeURIComponent( $('#newContainerTypeRows').val() );
  108. var newCTCols = encodeURIComponent( $('#newContainerTypeColumns').val() );
  109. if( newCTName == "" ) {
  110. userFeedback("alert-error","<?php print $_SESSION['lims']['langdata']['err_enter_name']; ?>.");
  111. return false;
  112. }
  113. if( ! isInt(newCTCap) ) { userFeedback("alert-error","<?php print $_SESSION['lims']['langdata']['error']." (".$_SESSION['lims']['langdata']['capacity']."): ".$_SESSION['lims']['langdata']['err_int_required']; ?>"); return false; }
  114. if( ! isInt(newCTRows) ) { userFeedback("alert-error","<?php print $_SESSION['lims']['langdata']['error']." (".$_SESSION['lims']['langdata']['rows']."): ".$_SESSION['lims']['langdata']['err_int_required']; ?>"); return false; }
  115. if( ! isInt(newCTCols) ) { userFeedback("alert-error","<?php print $_SESSION['lims']['langdata']['error']." (".$_SESSION['lims']['langdata']['columns']."): ".$_SESSION['lims']['langdata']['err_int_required']; ?>"); return false; }
  116. // $.post("core/ajax_devices.php", { m: "nsd", n: newSDName, l: newSDLab, e: newSDEnv, t: newSDType }, function(){ location.reload(); } );
  117. $('#newContainerTypeSave').attr('disabled','disabled');
  118. $('#newContainerTypeSave').html("<? print $button_save; ?> <i class='icon-spinner icon-spin'></i>");
  119. $.post("core/ajax_devices.php", { m: "nc", n: newCTName, cap: newCTCap, r: newCTRows, c: newCTCols }, function(){ location.reload(); } );
  120. return false;
  121. });
  122. // calculate the capacity
  123. $('#newContainerTypeRows').on('input', function(){
  124. if( ! isInt($('#newContainerTypeRows').val()) ) return false;
  125. var r = parseInt( $('#newContainerTypeRows').val() );
  126. var c = parseInt( $('#newContainerTypeColumns').val() );
  127. $('#newContainerTypeCapacity').val(r*c);
  128. });
  129. $('#newContainerTypeColumns').on('input', function(){
  130. if( ! isInt($('#newContainerTypeColumns').val()) ) return false;
  131. var r = parseInt( $('#newContainerTypeRows').val() );
  132. var c = parseInt( $('#newContainerTypeColumns').val() );
  133. $('#newContainerTypeCapacity').val(r*c);
  134. });
  135. $('#containerTypeEditRows').on('input', function(){
  136. if( ! isInt($('#containerTypeEditRows').val()) ) return false;
  137. var r = parseInt( $('#containerTypeEditRows').val() );
  138. var c = parseInt( $('#containerTypeEditColumns').val() );
  139. $('#containerTypeEditCapacity').val(r*c);
  140. });
  141. $('#containerTypeEditColumns').on('input', function(){
  142. if( ! isInt($('#containerTypeEditColumns').val()) ) return false;
  143. var r = parseInt( $('#containerTypeEditRows').val() );
  144. var c = parseInt( $('#containerTypeEditColumns').val() );
  145. $('#containerTypeEditCapacity').val(r*c);
  146. });
  147. $("[id^=containerTypeDel-]").click( function() {
  148. // check if in use first
  149. var cid = this.id.split("-")[1];
  150. var sdname = $('#containerTypeName-'+cid).text();
  151. $('#containerTypeDelModalBody').html('<p><?php print $_SESSION['lims']['langdata']['delete']; ?> <i>'+sdname+'</i>?</p>');
  152. $('#containerTypeDelConfirm').click(function() {
  153. $.post("core/ajax_devices.php", { m: "dc", i: cid }, function(){
  154. $('#containerTypeDelModal').modal('hide');
  155. $('#containerTypeDelModal').on('hidden', function () { location.reload() });
  156. });
  157. });
  158. $('#containerTypeDelModal').modal();
  159. });
  160. $("[id^=containerTypeEdit-]").click(function(){
  161. var cid = this.id.split("-")[1];
  162. var cname = $('#containerTypeName-'+cid).text();
  163. $('#containerTypeEditName').val( $('#containerTypeName-'+cid).text() );
  164. $('#containerTypeEditCapacity').val( $('#containerTypeCapacity-'+cid).text() );
  165. $('#containerTypeEditRows').val( $('#containerTypeRows-'+cid).text() );
  166. $('#containerTypeEditColumns').val( $('#containerTypeColumns-'+cid).text() );
  167. $('#containerTypeEditModalLabel').html("<i class='icon-edit'></i> <?php print $_SESSION['lims']['langdata']['limsadmin_edit_container_type']; ?>: <i>"+cname+"</i>");
  168. $('#containerTypeEditModal').modal();
  169. // $('#containerTypeEditModal').on('hidden', function() { location.reload(); });
  170. $('#containerTypeEditSave').click( function(){
  171. var bValid = true;
  172. if( $('#containerTypeEditName').val() == "" ) { $('#containerTypeEditName').css('background', '#ffdddd'); $('#containerTypeEditNameLabel').css('color', 'red'); bValid=false;}
  173. if( !isInt($('#containerTypeEditCapacity').val() ) ) { $('#containerTypeEditCapacity').css('background', '#ffdddd'); $('#containerTypeEditCapacityLabel').css('color', 'red'); bValid=false;}
  174. if( !isInt($('#containerTypeEditRows').val() ) ) { $('#containerTypeEditRows').css('background', '#ffdddd'); $('#containerTypeEditRowsLabel').css('color', 'red'); bValid=false;}
  175. if( !isInt($('#containerTypeEditColumns').val() ) ) { $('#containerTypeEditColumns').css('background', '#ffdddd'); $('#containerTypeEditColumnsLabel').css('color', 'red'); bValid=false;}
  176. if( bValid ) {
  177. $.post("core/ajax_devices.php", { m: "uc", i: cid, n: $('#containerTypeEditName').val(), cap: $('#containerTypeEditCapacity').val(), r: $('#containerTypeEditRows').val(), c: $('#containerTypeEditColumns').val() }, function(){
  178. $('#containerTypeEditModal' ).modal( "hide" );
  179. $('#containerTypeEditModal').on('hidden', function () { location.reload() });
  180. });
  181. }
  182. });
  183. });
  184. $("[rel=tooltip]").tooltip();
  185. });
  186. </script>