Advertisement
Guest User

Untitled

a guest
Jan 31st, 2018
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.23 KB | None | 0 0
  1.  
  2. @{
  3.  
  4. @model RND_ASSET_CATALOG.Controllers.TablesController.tableView
  5. RND_ASSET_CATALOG.Controllers.TablesController.tableView itemsView = Model;
  6. }
  7. <link href="~/Vendor/datatables/media/css/jquery.dataTables.min.css" rel="stylesheet" />
  8. <style>
  9. .ErrorClass {
  10. background-color: red;
  11. }
  12. </style>
  13.  
  14.  
  15. <div id="ColumnsPanel" class="content animate-panel" style="display: none;">
  16. <div class="hpanel">
  17. <div class="panel-heading">
  18. Columns
  19. </div>
  20. <div class="panel-body">
  21. <form method="get" action="UpdateColumns" class="form-horizontal">
  22. <div class="form-group" style="height:383px;overflow-y:auto">
  23. <input type="hidden" name="ViewName" value="+@itemsView.ViewName" />
  24. @foreach (var element in itemsView.data)
  25. {
  26. <label class='col-sm-2 control-label' style='text-align:left'>@element.Name </label>
  27. <div class='col-sm-10'>
  28. <input id='COLUMN_@element.Name' name='COLUMN_@element.Name' type='checkbox' class='form-control' @{ if (@element.Active=="0"){ @Html.Raw("checked") } } >
  29. </div>
  30. <div class='hr-line-dashed'/>
  31. }
  32. </div>
  33. <div class="hr-line-dashed"></div>
  34. <div class="form-group">
  35. <div class="col-sm-8 col-sm-offset-2">
  36. <button class="btn btn-default" type="button" onclick="closeform('ColumnsPanel');">Cancel</button>
  37. <button class="btn btn-primary" type="submit">Save changes</button>
  38. </div>
  39. </div>
  40. </form>
  41. </div>
  42. </div>
  43.  
  44.  
  45.  
  46. </div>
  47.  
  48.  
  49.  
  50.  
  51.  
  52. @{
  53. if (itemsView.Edit == "1")
  54. {
  55. <div id="Edit" class="content animate-panel" style="display: none;">
  56. <div class="hpanel">
  57. <div class="panel-heading">
  58. Edit
  59. </div>
  60. <div class="panel-body">
  61. <form method="get" action="UpdateData" class="form-horizontal">
  62. <div class="form-group" style="height:383px;overflow-y:auto">
  63. <input type="hidden" name="ViewName" value="+@itemsView.ViewName" />
  64. <input id="KeyTbl" type="hidden" name="KeyTbl" value="" />
  65.  
  66. @foreach (var element in itemsView.data)
  67. {
  68. if (String.IsNullOrEmpty(element.FormEditFormatter))
  69. {
  70. <label class='col-sm-2 control-label' style='text-align:left'>@element.ViewDescription</label><div class='col-sm-10'><input id='@element.Name' name='@element.Name' type='text' class='form-control'></div>
  71. }
  72. else
  73. {
  74. <label class='col-sm-2 control-label' style='text-align:left'>@element.Name</label>
  75. <div class='col-sm-10'>
  76. <select class='form-control m-b' id='@element.Name' name='@element.Name'>
  77. @foreach (var item in element.FormEditOption)
  78. {
  79. <option>@item</option>
  80. ViewBag.itemValue = item;
  81. }
  82. </select>
  83. </div>
  84.  
  85. }
  86. <div class='hr-line-dashed'></div>
  87. }
  88. </div>
  89. <div class="hr-line-dashed"></div>
  90. <div class="form-group">
  91. <div class="col-sm-8 col-sm-offset-2">
  92. <button class="btn btn-default" type="button" onclick="closeform('Edit');">Cancel</button>
  93. <button class="btn btn-primary" type="submit">Save changes</button>
  94. </div>
  95. </div>
  96. </form>
  97. </div>
  98. </div>
  99.  
  100.  
  101.  
  102. </div>
  103. }
  104. }
  105.  
  106.  
  107.  
  108.  
  109. @{
  110. if (itemsView.New == "1")
  111. {
  112. <div id="New" class="content animate-panel" style="display: none;">
  113. <div class="hpanel">
  114. <div class="panel-heading">
  115. New
  116. </div>
  117. <div class="panel-body">
  118. <form method="get" action="InsertNewData" class="form-horizontal">
  119. <div class="form-group" style="height: 383px; overflow-y: auto">
  120. <input type="hidden" name="ViewName" value="+@itemsView.ViewName+" />
  121. @foreach (var element in itemsView.data)
  122. {
  123. if (String.IsNullOrEmpty(element.FormEditFormatter))
  124. {
  125. <label class='col-sm-2 control-label' style='text-align:left'>@element.ViewDescription</label><div class='col-sm-10'><input id='@element.Name' name='@element.Name' type='text' class='form-control'></div>
  126. }
  127. else if (String.Equals(element.FormEditFormatter, "date"))
  128. {
  129. <label class='col-sm-2 control-label' style='text-align:left'>@element.Name </label>
  130. <div class='input-group date' id='datetimepicker1'>
  131. <input type='text' class="form-control" />
  132. <span class="input-group-addon">
  133. <span class="glyphicon glyphicon-calendar"></span>
  134. </span>
  135. </div>
  136. }
  137. else
  138. {
  139. if(element.Mandatory == "1")
  140. {
  141. <label class='col-sm-2 control-label mandatory' style='text-align:left'>@element.Name</label>
  142. }
  143. else
  144. {
  145. <label class='col-sm-2 control-label' style='text-align:left'>@element.Name</label>
  146. }
  147. <div class='col-sm-10'>
  148. <select class='form-control m-b' id='@element.Name' name='@element.Name'>
  149. @foreach (var item in element.FormEditOption)
  150. {
  151. <option>@item</option>
  152. }
  153. </select>
  154. </div>
  155.  
  156. }
  157. <div class='hr-line-dashed'></div>
  158. }
  159. </div>
  160. <div class="hr-line-dashed"></div>
  161. <div class="form-group">
  162. <div class="col-sm-8 col-sm-offset-2">
  163. <button class="btn btn-default" type="button" onclick="closeform('New');">Cancel</button>
  164. <button class="btn btn-primary" type="submit">Add</button>
  165. </div>
  166. </div>
  167. </form>
  168. </div>
  169. </div>
  170.  
  171.  
  172.  
  173. </div>
  174. }
  175. }
  176.  
  177.  
  178.  
  179. @{
  180. if (itemsView.Delete == "1")
  181. {
  182. <div id="Delete" class="content animate-panel" style="display: none;">
  183. <div class="hpanel">
  184. <div class="panel-heading">
  185. Delete
  186. </div>
  187. <div class="panel-body">
  188. <form method="get" action="DeleteData" class="form-horizontal">
  189. <div class="form-group" style="height: 383px; overflow-y: auto">
  190. <input type="hidden" name="ViewName" value="+@itemsView.ViewName+" />
  191. @foreach (var element in itemsView.data)
  192. {
  193. if (String.IsNullOrEmpty(element.FormEditFormatter))
  194. {
  195. <label class='col-sm-2 control-label' style='text-align:left'>@element.Name </label><div class='col-sm-10'><input id='D_@element.Name' name='@element.Name' type='text' class='form-control'></div>
  196.  
  197. }
  198. else
  199. {
  200. <label class='col-sm-2 control-label' style='text-align:left'>@element.Name</label>
  201. <div class='col-sm-10'>
  202. <select class='form-control m-b' id='D_@element.Name' name='@element.Name'>
  203. @foreach (var item in element.FormEditOption)
  204. {
  205. <option>@item</option>
  206. }
  207. </select>
  208. </div>
  209.  
  210. }
  211. <div class='hr-line-dashed'></div>
  212. }
  213. </div>
  214. <div class="hr-line-dashed"></div>
  215. <div class="form-group">
  216. <div class="col-sm-8 col-sm-offset-2">
  217. <button class="btn btn-default" type="button" onclick="closeform('Delete');">Cancel</button>
  218. <button class="btn btn-primary" type="submit">Delete</button>
  219. </div>
  220. </div>
  221. </form>
  222. </div>
  223. </div>
  224.  
  225.  
  226.  
  227. </div>
  228. }
  229. }
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237. @{
  238. if (itemsView.UpdateTbl == "1")
  239. {
  240. <div id="Upload" class="content animate-panel" style="display:none">
  241. <div class="hpanel">
  242. <div class="panel-heading">
  243. Upload
  244. </div>
  245. <div class="panel-body">
  246. <form method="post" action="UploadFile" enctype="multipart/form-data" class="form-horizontal">
  247.  
  248. <div class="form-group" style="height: 50px; overflow-y: auto">
  249. <input id='file' name='file' type='file' class='form-control' />
  250. <input type="hidden" name="ImpTblName" value="@itemsView.ViewName" />
  251. </div>
  252.  
  253. <div class="hr-line-dashed"></div>
  254.  
  255. <div class="form-group">
  256. <div class="col-sm-8 col-sm-offset-2">
  257. <button class="btn btn-default" type="button" onclick="closeform('Upload');">Cancel</button>
  258. <button class="btn btn-primary" type="submit">Upload</button>
  259. </div>
  260. </div>
  261.  
  262. </form>
  263. </div>
  264. </div>
  265.  
  266.  
  267.  
  268. </div>
  269. }
  270. }
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290. <div id="MainContainer" class="content animate-panel">
  291. <div class="hpanel">
  292. <div class="panel-heading">
  293. <h2 class="font-light ">
  294. @itemsView.Title
  295. </h2>
  296. <small>@itemsView.Description</small>
  297.  
  298. </div>
  299. <div class="panel-body">
  300. <div class="table-responsive">
  301. <table id="example2" class="table table-striped table-bordered table-hover">
  302. <thead>
  303. <tr>
  304. @foreach (var element in itemsView.data)
  305. {
  306.  
  307. <th>@Html.DisplayFor(m => element.ViewDescription)</th>
  308. }
  309. </tr>
  310. </thead>
  311. <tfoot>
  312. <tr>
  313. @foreach (var element in itemsView.data)
  314. {
  315. <th>@Html.DisplayFor(m => element.ViewDescription)</th>
  316. }
  317. </tr>
  318. </tfoot>
  319. </table>
  320. </div>
  321. <div class="panel-body">
  322. <div class="col-xs-4">
  323. <div class="col-xs-1">
  324. <div style="height:20px;width:20px;background-color:red;margin-right:-100px;"></div>
  325. </div>
  326. <div class="col-xs-4" style="margin-left:1px"><div>Campi non congruenti</div></div>
  327. </div>
  328. <div class="col-sm-4">
  329. <div></div>
  330. </div>
  331. </div>
  332. </div>
  333. <div class="row">
  334.  
  335. </div>
  336. </div>
  337. </div>
  338.  
  339. @section Styles {
  340. @Styles.Render("~/bundles/datatables/css")
  341. @Styles.Render("~/bundles/datepicker/css")
  342.  
  343. }
  344.  
  345. @section Scripts {
  346. @Scripts.Render("~/bundles/datatables/js")
  347. @Scripts.Render("~/bundles/datatablesBootstrap/js")
  348. @Scripts.Render("~/bundles/datatablesPlugins/js")
  349. @Scripts.Render("~/bundles/datepicker/js")
  350.  
  351. <script type="text/javascript">
  352.  
  353. function closeform(param) {
  354. $('#' + param).toggle();
  355. $('#MainContainer').toggle();
  356. }
  357.  
  358.  
  359.  
  360. function htmlEscape(str) {
  361. str = ""+str;
  362. return str
  363. .replace(/&/g, '&amp;')
  364. .replace(/"/g, '&quot;')
  365. .replace(/'/g, '&#39;')
  366. .replace(/</g, '&lt;')
  367. .replace(/>/g, '&gt;');
  368. }
  369.  
  370. // I needed the opposite function today, so adding here too:
  371. function htmlUnescape(str) {
  372. return str
  373. .replace(/&quot;/g, '"')
  374. .replace(/&#39;/g, "'")
  375. .replace(/&lt;/g, '<')
  376. .replace(/&gt;/g, '>')
  377. .replace(/&amp;/g, '&');
  378. }
  379.  
  380. var getUrlParameter = function getUrlParameter(sParam) {
  381. var sPageURL = decodeURIComponent(window.location.search.substring(1)),
  382. sURLVariables = sPageURL.split('&'),
  383. sParameterName,
  384. i;
  385.  
  386. for (i = 0; i < sURLVariables.length; i++) {
  387. sParameterName = sURLVariables[i].split('=');
  388.  
  389. if (sParameterName[0] === sParam) {
  390. return sParameterName[1] === undefined ? true : sParameterName[1];
  391. }
  392. }
  393. };
  394.  
  395. $(function () {
  396. var bindDatePicker = function () {
  397. $(".date").datepicker({
  398. format: 'YYYY-MM-DD',
  399. icons: {
  400. time: "fa fa-clock-o",
  401. date: "fa fa-calendar",
  402. up: "fa fa-arrow-up",
  403. down: "fa fa-arrow-down"
  404. }
  405. }).find('input:first').on("blur", function () {
  406. // check if the date is correct. We can accept dd-mm-yyyy and yyyy-mm-dd.
  407. // update the format if it's yyyy-mm-dd
  408. var date = parseDate($(this).val());
  409.  
  410. if (!isValidDate(date)) {
  411. //create date based on momentjs (we have that)
  412. date = moment().format('YYYY-MM-DD');
  413. }
  414.  
  415. $(this).val(date);
  416. });
  417. }
  418.  
  419. var isValidDate = function (value, format) {
  420. format = format || false;
  421. // lets parse the date to the best of our knowledge
  422. if (format) {
  423. value = parseDate(value);
  424. }
  425.  
  426. var timestamp = Date.parse(value);
  427.  
  428. return isNaN(timestamp) == false;
  429. }
  430.  
  431. var parseDate = function (value) {
  432. var m = value.match(/^(\d{1,2})(\/|-)?(\d{1,2})(\/|-)?(\d{4})$/);
  433. if (m)
  434. value = m[5] + '-' + ("00" + m[3]).slice(-2) + '-' + ("00" + m[1]).slice(-2);
  435.  
  436. return value;
  437. }
  438.  
  439. bindDatePicker();
  440. });
  441.  
  442.  
  443. var table;
  444. $(function () {
  445.  
  446.  
  447. var chartDataUrl = '@Url.Action("tableJsonData", "Tables", new { ViewName = itemsView.ViewName, NICKNAME = itemsView.paramNickName, SCOPE = itemsView.paramNickScope, HostName = itemsView.paramHostName ,Service=itemsView.Service})';
  448.  
  449. table = $('#example2').DataTable({
  450. "ajax": chartDataUrl,
  451. "paging": true,
  452. "createdRow": function (row, data, dataIndex) {
  453. @for(int j = 0; j < itemsView.data.Count; j++ )
  454. {
  455. if(String.Equals(itemsView.data[j].Mandatory, "1"))
  456. {
  457. @Html.Raw("if(data["+ j + "] === \"\"){$(row).css('background-color', 'Red');}");
  458. }
  459. }
  460. },
  461. "fnRowCallback": @Html.Raw("function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {");
  462. @foreach (var element in itemsView.data)
  463. {
  464. if(element.FormEditOption != null && element.FormEditOption.Count > 0)
  465. {
  466. @Html.Raw("if(");
  467. for(var i = 0; i<element.FormEditOption.Count();i++)
  468. {
  469. if (i == 0) {
  470. @Html.Raw("!aData["+element.target+"] || aData["+element.target+"] === \""+element.FormEditOption[i]+"\"");
  471. }
  472. else
  473. {
  474. @Html.Raw(" || aData["+element.target+"] === \""+element.FormEditOption[i]+"\"");
  475. }
  476. }
  477. @Html.Raw(") { $('td', nRow).css('background-color', 'None');}");
  478. @Html.Raw("else{$('td', nRow).css('background-color', 'Red');}");
  479. }
  480.  
  481. }
  482. @Html.Raw("},")
  483. "columnDefs": [
  484. @foreach (var element in itemsView.data)
  485. {
  486. var a = "true";
  487. if (element.Name=="Service") { a = "false"; }
  488. @Html.Raw("{\"render\": function ( data, type, row ) { "+@element.Formatter+ "},\"visible\":"+ @a+",\"targets\": " + element.target+"},");
  489. }
  490.  
  491. ],
  492. dom: 'Bfrtip',
  493. select: true,
  494.  
  495. buttons: [
  496. {text: 'Columns',action: function () {$('#MainContainer').toggle(); $('#ColumnsPanel').toggle();}}
  497. @{
  498. if (itemsView.Edit.Equals("1") && ViewBag.Admin)
  499. {
  500. @Html.Raw(",{");
  501. @Html.Raw("text: 'Edit',");
  502. @Html.Raw("action: function () {");
  503. @Html.Raw("if (table.rows('.selected').count()>0){ ");
  504.  
  505. @Html.Raw("var item=table.rows('.selected').data()[0];");
  506. @Html.Raw("$('#MainContainer').toggle();")
  507. @Html.Raw("$('#Edit').toggle();");
  508. @Html.Raw("var tblValue=\"\";");
  509. int index = 0;
  510. foreach (var element in itemsView.data)
  511. {
  512. if (itemsView.PrimaryKey.Contains(element.ViewDescription) || itemsView.PrimaryKey.Contains(element.Name))
  513. {
  514. @Html.Raw("if(tblValue===''){tblValue += htmlEscape(item[" + index + "])}else{tblValue += ','+ htmlEscape(item[" + index + "])};");
  515. }
  516.  
  517. @Html.Raw("$('#" + @element.Name + "').val(htmlEscape(item[" + index + "])); ");
  518. index++;
  519. }
  520. @Html.Raw("$('#KeyTbl').val(tblValue); ");
  521. //@Html.Raw("$('#KeyTbl').val(htmlEscape(item[" + index + "])); ");
  522. @Html.Raw("}");
  523. @Html.Raw("else{toastr.warning('Select the object to edit...');}");
  524.  
  525. @Html.Raw("}");
  526. @Html.Raw("}");
  527. }
  528. }
  529. @{
  530. if (itemsView.UpdateTbl.Equals("1") && ViewBag.Admin)
  531. {
  532. @Html.Raw(",");
  533. @Html.Raw("{");
  534. @Html.Raw("text: 'Upload',");
  535. @Html.Raw("action: function () {");
  536. @Html.Raw("$('#MainContainer').toggle();")
  537. @Html.Raw("$('#Upload').toggle();");
  538. @Html.Raw("}");
  539. @Html.Raw("}");
  540. }
  541. }
  542.  
  543. @{
  544. if (itemsView.New.Equals("1") && ViewBag.Admin)
  545. {
  546. @Html.Raw(",");
  547. @Html.Raw("{");
  548. @Html.Raw("text: 'New',");
  549. @Html.Raw("action: function () {");
  550. @Html.Raw("var item=table.rows('.selected').data()[0];")
  551. @Html.Raw("$('#MainContainer').toggle();");
  552. @Html.Raw("$('#New').toggle();");
  553. @Html.Raw("}");
  554. @Html.Raw("}");
  555. }
  556. }
  557. @{
  558. if (itemsView.Delete.Equals("1") && ViewBag.Admin)
  559. {
  560. @Html.Raw(",");
  561. @Html.Raw("{");
  562. @Html.Raw("text: 'Delete',");
  563. @Html.Raw("action: function () {");
  564. @Html.Raw("if (table.rows('.selected').count()>0){ ");
  565. @Html.Raw("var item = table.rows('.selected').data()[0];");
  566. @Html.Raw("$('#MainContainer').toggle();");
  567. @Html.Raw("$('#Delete').toggle();");
  568. int indexEdit = 0;
  569. foreach (var element in itemsView.data)
  570. {
  571. @Html.Raw("$('#D_" + @element.Name + "').val(htmlEscape(item[" + indexEdit + "])); ");
  572. indexEdit++;
  573. }
  574. @Html.Raw("}");
  575. @Html.Raw("else{toastr.warning('Select the object to delete...');}");
  576.  
  577. @Html.Raw("}");
  578.  
  579. @Html.Raw("}");
  580. }
  581. }
  582. @{
  583. if(itemsView.Export.Equals("1")){
  584. @Html.Raw(",");
  585. @Html.Raw("{ extend: 'csv', title: 'ExportFile',footer:false}");
  586.  
  587. }
  588. }
  589. ],
  590. "autoWidth": true,
  591. initComplete: function () {
  592. this.api().columns().every(function () {
  593. var column = this;
  594. var select = $('<select ><option value=""></option></select>')
  595. // .appendTo($(column.footer()))
  596. .appendTo($(column.header()))
  597. .on('change', function () {
  598. var val = $.fn.dataTable.util.escapeRegex(
  599. $(this).val()
  600. );
  601.  
  602. column
  603. .search(val ? '^' + val + '$' : '', true, false)
  604. .draw();
  605. });
  606.  
  607. column.data().unique().sort().each(function (d, j) {
  608. select.append('<option value="' + d + '">' + d + '</option>')
  609. });
  610.  
  611. });
  612. this.api().draw();
  613. }
  614.  
  615. });
  616.  
  617.  
  618.  
  619.  
  620.  
  621. $('#example2 tbody').on('click', 'tr', function () {
  622. table
  623. .rows('.selected')
  624. .nodes()
  625. .to$()
  626. .removeClass('selected');
  627. $(this).toggleClass('selected');
  628. });
  629. });
  630.  
  631. </script>
  632. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement