Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. @{
  2. ViewBag.Title = "Viser infrastruktur";
  3. Layout = "~/Views/Shared/_SuperOfficeLayout.cshtml";
  4. }
  5.  
  6. <table class="table table-striped compact hover row-border">
  7. <thead>
  8. <tr>
  9. <th>Produsent</th>
  10. <th>Modell</th>
  11. <th>Serienummer</th>
  12. <th>Firmware</th>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr>
  17. <td>
  18. <div class="control-group">
  19. <input type="text" class="col-md-12 form-control autosave new" name="manufacturer" placeholder="Produsent" value="" />
  20. <input type="hidden" class="autosave new" name="id" value="" />
  21. <input type="hidden" class="autosave new" name="superOfficeCustomerId" value="@Model.SuperOfficeCustomerId" />
  22. </div>
  23. </td>
  24. <td>
  25. <div class="control-group">
  26. <input type="text" class="col-md-12 form-control autosave new" name="model" placeholder="Modell" />
  27. </div>
  28. </td>
  29. <td>
  30. <div class="control-group">
  31. <input type="text" class="col-md-12 form-control autosave new" name="serialNumber" placeholder="Serienummer" />
  32. </div>
  33. </td>
  34. <td>
  35. <div class="control-group">
  36. <input type="text" class="col-md-12 form-control autosave new" name="firmware" placeholder="Firmware" />
  37. </div>
  38. </td>
  39. </tr>
  40. @foreach (var infrastructure in Model.Infrastructures)
  41. {
  42. <tr>
  43. <td>
  44. <div class="control-group">
  45. <input type="text" class="col-md-12 form-control autosave" name="manufacturer" placeholder="Produsent" value="@infrastructure.Manufacturer" />
  46. <input type="hidden" class="autosave" name="id" value="@infrastructure.Id" />
  47. <input type="hidden" class="autosave" name="superOfficeCustomerId" value="@Model.SuperOfficeCustomerId" />
  48. </div>
  49. </td>
  50. <td>
  51. <div class="control-group">
  52. <input type="text" class="col-md-12 form-control autosave" name="model" placeholder="Modell" value="@infrastructure.Model" />
  53. </div>
  54. </td>
  55. <td>
  56. <div class="control-group">
  57. <input type="text" class="col-md-12 form-control autosave" name="serialNumber" placeholder="Serienummer" value="@infrastructure.SerialNumber" />
  58. </div>
  59. </td>
  60. <td>
  61. <div class="control-group">
  62. <input type="text" class="col-md-12 form-control autosave" name="firmware" placeholder="Firmware" value="@infrastructure.Firmware" />
  63. </div>
  64. </td>
  65. </tr>
  66. }
  67. </tbody>
  68.  
  69. @section SpecializedScripts
  70. {
  71. <script type="text/javascript">
  72. function saveSettings(element, ajaxUrl, ajaxType) {
  73. var fields = $(element).closest('tr').children('td').children('div').children('.autosave');
  74. var abort = false;
  75.  
  76. var ajaxData = {};
  77. $(fields).each(function () {
  78. abort = ($(this).val() == '' || $(this).val() == null);
  79. backgroundColor = abort == true ? '#d9534f' : '#f9f598';
  80.  
  81. $(this).css('background-color', backgroundColor).css('color', '#ffffff').stop().animate({ 'background-color': '#ffffff', 'color': '#000000' }, 1500);
  82.  
  83. ajaxData[$(this).prop('name')] = $(this).val();
  84. });
  85.  
  86. if (abort == true) {
  87. return false;
  88. }
  89.  
  90. $.ajax({
  91. url: ajaxUrl,
  92. type: ajaxType,
  93. data: ajaxData
  94. }).success(function (data, textStatus, jqXHR) {
  95. $(fields).each(function() {
  96. $(this).css('background-color', '#5cb85c').css('color', '#ffffff').stop().animate({ 'background-color': '#ffffff', 'color': '#000000' }, 1500);
  97. });
  98.  
  99. switch(data.status)
  100. {
  101. case 'Deleted':
  102. $(element).closest('tr').remove();
  103. break;
  104. case 'Added':
  105. var tableBody = $('tbody');
  106. var html = '<tr>';
  107. for (var field in data.result) {
  108. if (field == 'id' || field == 'superOfficeCustomerId')
  109. {
  110. html += '<input type="hidden" class="autosave" name="' + field + '" value="' + data.result[field] + '" />';
  111. }
  112. else {
  113. html += '<td>'
  114. + '<div class="control-group">'
  115. + '<input type="text" class="col-md-12 autosave form-control" name="' + field + '" value="' + data.result[field] + '" />'
  116. + '</div>'
  117. + '</td>';
  118.  
  119. $('input.new[name=' + field + ']').val('');
  120. }
  121. }
  122. html += '</tr>';
  123. $(tableBody).append(html);
  124. case 'Modified':
  125. $(fields).each(function () {
  126. $(this).val(data.result[$(this).prop('name')]);
  127. });
  128. break;
  129. }
  130. }).fail(function () {
  131. });
  132. }
  133.  
  134. $(document).on('blur', 'input.autosave', function () {
  135. saveSettings($(this), '/Link/SaveInfrastructure', 'POST');
  136. });
  137.  
  138. $(document).on('change', 'input.new', function () {
  139. });
  140. </script>
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement