Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @{
- @model RND_ASSET_CATALOG.Controllers.TablesController.tableView
- RND_ASSET_CATALOG.Controllers.TablesController.tableView itemsView = Model;
- }
- <link href="~/Vendor/datatables/media/css/jquery.dataTables.min.css" rel="stylesheet" />
- <style>
- .ErrorClass {
- background-color: red;
- }
- </style>
- <div id="ColumnsPanel" class="content animate-panel" style="display: none;">
- <div class="hpanel">
- <div class="panel-heading">
- Columns
- </div>
- <div class="panel-body">
- <form method="get" action="UpdateColumns" class="form-horizontal">
- <div class="form-group" style="height:383px;overflow-y:auto">
- <input type="hidden" name="ViewName" value="+@itemsView.ViewName" />
- @foreach (var element in itemsView.data)
- {
- <label class='col-sm-2 control-label' style='text-align:left'>@element.Name </label>
- <div class='col-sm-10'>
- <input id='COLUMN_@element.Name' name='COLUMN_@element.Name' type='checkbox' class='form-control' @{ if (@element.Active=="0"){ @Html.Raw("checked") } } >
- </div>
- <div class='hr-line-dashed'/>
- }
- </div>
- <div class="hr-line-dashed"></div>
- <div class="form-group">
- <div class="col-sm-8 col-sm-offset-2">
- <button class="btn btn-default" type="button" onclick="closeform('ColumnsPanel');">Cancel</button>
- <button class="btn btn-primary" type="submit">Save changes</button>
- </div>
- </div>
- </form>
- </div>
- </div>
- </div>
- @{
- if (itemsView.Edit == "1")
- {
- <div id="Edit" class="content animate-panel" style="display: none;">
- <div class="hpanel">
- <div class="panel-heading">
- Edit
- </div>
- <div class="panel-body">
- <form method="get" action="UpdateData" class="form-horizontal">
- <div class="form-group" style="height:383px;overflow-y:auto">
- <input type="hidden" name="ViewName" value="+@itemsView.ViewName" />
- <input id="KeyTbl" type="hidden" name="KeyTbl" value="" />
- @foreach (var element in itemsView.data)
- {
- if (String.IsNullOrEmpty(element.FormEditFormatter))
- {
- <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>
- }
- else
- {
- <label class='col-sm-2 control-label' style='text-align:left'>@element.Name</label>
- <div class='col-sm-10'>
- <select class='form-control m-b' id='@element.Name' name='@element.Name'>
- @foreach (var item in element.FormEditOption)
- {
- <option>@item</option>
- ViewBag.itemValue = item;
- }
- </select>
- </div>
- }
- <div class='hr-line-dashed'></div>
- }
- </div>
- <div class="hr-line-dashed"></div>
- <div class="form-group">
- <div class="col-sm-8 col-sm-offset-2">
- <button class="btn btn-default" type="button" onclick="closeform('Edit');">Cancel</button>
- <button class="btn btn-primary" type="submit">Save changes</button>
- </div>
- </div>
- </form>
- </div>
- </div>
- </div>
- }
- }
- @{
- if (itemsView.New == "1")
- {
- <div id="New" class="content animate-panel" style="display: none;">
- <div class="hpanel">
- <div class="panel-heading">
- New
- </div>
- <div class="panel-body">
- <form method="get" action="InsertNewData" class="form-horizontal">
- <div class="form-group" style="height: 383px; overflow-y: auto">
- <input type="hidden" name="ViewName" value="+@itemsView.ViewName+" />
- @foreach (var element in itemsView.data)
- {
- if (String.IsNullOrEmpty(element.FormEditFormatter))
- {
- <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>
- }
- else if (String.Equals(element.FormEditFormatter, "date"))
- {
- <label class='col-sm-2 control-label' style='text-align:left'>@element.Name </label>
- <div class='input-group date' id='datetimepicker1'>
- <input type='text' class="form-control" />
- <span class="input-group-addon">
- <span class="glyphicon glyphicon-calendar"></span>
- </span>
- </div>
- }
- else
- {
- if(element.Mandatory == "1")
- {
- <label class='col-sm-2 control-label mandatory' style='text-align:left'>@element.Name</label>
- }
- else
- {
- <label class='col-sm-2 control-label' style='text-align:left'>@element.Name</label>
- }
- <div class='col-sm-10'>
- <select class='form-control m-b' id='@element.Name' name='@element.Name'>
- @foreach (var item in element.FormEditOption)
- {
- <option>@item</option>
- }
- </select>
- </div>
- }
- <div class='hr-line-dashed'></div>
- }
- </div>
- <div class="hr-line-dashed"></div>
- <div class="form-group">
- <div class="col-sm-8 col-sm-offset-2">
- <button class="btn btn-default" type="button" onclick="closeform('New');">Cancel</button>
- <button class="btn btn-primary" type="submit">Add</button>
- </div>
- </div>
- </form>
- </div>
- </div>
- </div>
- }
- }
- @{
- if (itemsView.Delete == "1")
- {
- <div id="Delete" class="content animate-panel" style="display: none;">
- <div class="hpanel">
- <div class="panel-heading">
- Delete
- </div>
- <div class="panel-body">
- <form method="get" action="DeleteData" class="form-horizontal">
- <div class="form-group" style="height: 383px; overflow-y: auto">
- <input type="hidden" name="ViewName" value="+@itemsView.ViewName+" />
- @foreach (var element in itemsView.data)
- {
- if (String.IsNullOrEmpty(element.FormEditFormatter))
- {
- <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>
- }
- else
- {
- <label class='col-sm-2 control-label' style='text-align:left'>@element.Name</label>
- <div class='col-sm-10'>
- <select class='form-control m-b' id='D_@element.Name' name='@element.Name'>
- @foreach (var item in element.FormEditOption)
- {
- <option>@item</option>
- }
- </select>
- </div>
- }
- <div class='hr-line-dashed'></div>
- }
- </div>
- <div class="hr-line-dashed"></div>
- <div class="form-group">
- <div class="col-sm-8 col-sm-offset-2">
- <button class="btn btn-default" type="button" onclick="closeform('Delete');">Cancel</button>
- <button class="btn btn-primary" type="submit">Delete</button>
- </div>
- </div>
- </form>
- </div>
- </div>
- </div>
- }
- }
- @{
- if (itemsView.UpdateTbl == "1")
- {
- <div id="Upload" class="content animate-panel" style="display:none">
- <div class="hpanel">
- <div class="panel-heading">
- Upload
- </div>
- <div class="panel-body">
- <form method="post" action="UploadFile" enctype="multipart/form-data" class="form-horizontal">
- <div class="form-group" style="height: 50px; overflow-y: auto">
- <input id='file' name='file' type='file' class='form-control' />
- <input type="hidden" name="ImpTblName" value="@itemsView.ViewName" />
- </div>
- <div class="hr-line-dashed"></div>
- <div class="form-group">
- <div class="col-sm-8 col-sm-offset-2">
- <button class="btn btn-default" type="button" onclick="closeform('Upload');">Cancel</button>
- <button class="btn btn-primary" type="submit">Upload</button>
- </div>
- </div>
- </form>
- </div>
- </div>
- </div>
- }
- }
- <div id="MainContainer" class="content animate-panel">
- <div class="hpanel">
- <div class="panel-heading">
- <h2 class="font-light ">
- @itemsView.Title
- </h2>
- <small>@itemsView.Description</small>
- </div>
- <div class="panel-body">
- <div class="table-responsive">
- <table id="example2" class="table table-striped table-bordered table-hover">
- <thead>
- <tr>
- @foreach (var element in itemsView.data)
- {
- <th>@Html.DisplayFor(m => element.ViewDescription)</th>
- }
- </tr>
- </thead>
- <tfoot>
- <tr>
- @foreach (var element in itemsView.data)
- {
- <th>@Html.DisplayFor(m => element.ViewDescription)</th>
- }
- </tr>
- </tfoot>
- </table>
- </div>
- <div class="panel-body">
- <div class="col-xs-4">
- <div class="col-xs-1">
- <div style="height:20px;width:20px;background-color:red;margin-right:-100px;"></div>
- </div>
- <div class="col-xs-4" style="margin-left:1px"><div>Campi non congruenti</div></div>
- </div>
- <div class="col-sm-4">
- <div></div>
- </div>
- </div>
- </div>
- <div class="row">
- </div>
- </div>
- </div>
- @section Styles {
- @Styles.Render("~/bundles/datatables/css")
- @Styles.Render("~/bundles/datepicker/css")
- }
- @section Scripts {
- @Scripts.Render("~/bundles/datatables/js")
- @Scripts.Render("~/bundles/datatablesBootstrap/js")
- @Scripts.Render("~/bundles/datatablesPlugins/js")
- @Scripts.Render("~/bundles/datepicker/js")
- <script type="text/javascript">
- function closeform(param) {
- $('#' + param).toggle();
- $('#MainContainer').toggle();
- }
- function htmlEscape(str) {
- str = ""+str;
- return str
- .replace(/&/g, '&')
- .replace(/"/g, '"')
- .replace(/'/g, ''')
- .replace(/</g, '<')
- .replace(/>/g, '>');
- }
- // I needed the opposite function today, so adding here too:
- function htmlUnescape(str) {
- return str
- .replace(/"/g, '"')
- .replace(/'/g, "'")
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/&/g, '&');
- }
- var getUrlParameter = function getUrlParameter(sParam) {
- var sPageURL = decodeURIComponent(window.location.search.substring(1)),
- sURLVariables = sPageURL.split('&'),
- sParameterName,
- i;
- for (i = 0; i < sURLVariables.length; i++) {
- sParameterName = sURLVariables[i].split('=');
- if (sParameterName[0] === sParam) {
- return sParameterName[1] === undefined ? true : sParameterName[1];
- }
- }
- };
- $(function () {
- var bindDatePicker = function () {
- $(".date").datepicker({
- format: 'YYYY-MM-DD',
- icons: {
- time: "fa fa-clock-o",
- date: "fa fa-calendar",
- up: "fa fa-arrow-up",
- down: "fa fa-arrow-down"
- }
- }).find('input:first').on("blur", function () {
- // check if the date is correct. We can accept dd-mm-yyyy and yyyy-mm-dd.
- // update the format if it's yyyy-mm-dd
- var date = parseDate($(this).val());
- if (!isValidDate(date)) {
- //create date based on momentjs (we have that)
- date = moment().format('YYYY-MM-DD');
- }
- $(this).val(date);
- });
- }
- var isValidDate = function (value, format) {
- format = format || false;
- // lets parse the date to the best of our knowledge
- if (format) {
- value = parseDate(value);
- }
- var timestamp = Date.parse(value);
- return isNaN(timestamp) == false;
- }
- var parseDate = function (value) {
- var m = value.match(/^(\d{1,2})(\/|-)?(\d{1,2})(\/|-)?(\d{4})$/);
- if (m)
- value = m[5] + '-' + ("00" + m[3]).slice(-2) + '-' + ("00" + m[1]).slice(-2);
- return value;
- }
- bindDatePicker();
- });
- var table;
- $(function () {
- var chartDataUrl = '@Url.Action("tableJsonData", "Tables", new { ViewName = itemsView.ViewName, NICKNAME = itemsView.paramNickName, SCOPE = itemsView.paramNickScope, HostName = itemsView.paramHostName ,Service=itemsView.Service})';
- table = $('#example2').DataTable({
- "ajax": chartDataUrl,
- "paging": true,
- "createdRow": function (row, data, dataIndex) {
- @for(int j = 0; j < itemsView.data.Count; j++ )
- {
- if(String.Equals(itemsView.data[j].Mandatory, "1"))
- {
- @Html.Raw("if(data["+ j + "] === \"\"){$(row).css('background-color', 'Red');}");
- }
- }
- },
- "fnRowCallback": @Html.Raw("function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {");
- @foreach (var element in itemsView.data)
- {
- if(element.FormEditOption != null && element.FormEditOption.Count > 0)
- {
- @Html.Raw("if(");
- for(var i = 0; i<element.FormEditOption.Count();i++)
- {
- if (i == 0) {
- @Html.Raw("!aData["+element.target+"] || aData["+element.target+"] === \""+element.FormEditOption[i]+"\"");
- }
- else
- {
- @Html.Raw(" || aData["+element.target+"] === \""+element.FormEditOption[i]+"\"");
- }
- }
- @Html.Raw(") { $('td', nRow).css('background-color', 'None');}");
- @Html.Raw("else{$('td', nRow).css('background-color', 'Red');}");
- }
- }
- @Html.Raw("},")
- "columnDefs": [
- @foreach (var element in itemsView.data)
- {
- var a = "true";
- if (element.Name=="Service") { a = "false"; }
- @Html.Raw("{\"render\": function ( data, type, row ) { "+@element.Formatter+ "},\"visible\":"+ @a+",\"targets\": " + element.target+"},");
- }
- ],
- dom: 'Bfrtip',
- select: true,
- buttons: [
- {text: 'Columns',action: function () {$('#MainContainer').toggle(); $('#ColumnsPanel').toggle();}}
- @{
- if (itemsView.Edit.Equals("1") && ViewBag.Admin)
- {
- @Html.Raw(",{");
- @Html.Raw("text: 'Edit',");
- @Html.Raw("action: function () {");
- @Html.Raw("if (table.rows('.selected').count()>0){ ");
- @Html.Raw("var item=table.rows('.selected').data()[0];");
- @Html.Raw("$('#MainContainer').toggle();")
- @Html.Raw("$('#Edit').toggle();");
- @Html.Raw("var tblValue=\"\";");
- int index = 0;
- foreach (var element in itemsView.data)
- {
- if (itemsView.PrimaryKey.Contains(element.ViewDescription) || itemsView.PrimaryKey.Contains(element.Name))
- {
- @Html.Raw("if(tblValue===''){tblValue += htmlEscape(item[" + index + "])}else{tblValue += ','+ htmlEscape(item[" + index + "])};");
- }
- @Html.Raw("$('#" + @element.Name + "').val(htmlEscape(item[" + index + "])); ");
- index++;
- }
- @Html.Raw("$('#KeyTbl').val(tblValue); ");
- //@Html.Raw("$('#KeyTbl').val(htmlEscape(item[" + index + "])); ");
- @Html.Raw("}");
- @Html.Raw("else{toastr.warning('Select the object to edit...');}");
- @Html.Raw("}");
- @Html.Raw("}");
- }
- }
- @{
- if (itemsView.UpdateTbl.Equals("1") && ViewBag.Admin)
- {
- @Html.Raw(",");
- @Html.Raw("{");
- @Html.Raw("text: 'Upload',");
- @Html.Raw("action: function () {");
- @Html.Raw("$('#MainContainer').toggle();")
- @Html.Raw("$('#Upload').toggle();");
- @Html.Raw("}");
- @Html.Raw("}");
- }
- }
- @{
- if (itemsView.New.Equals("1") && ViewBag.Admin)
- {
- @Html.Raw(",");
- @Html.Raw("{");
- @Html.Raw("text: 'New',");
- @Html.Raw("action: function () {");
- @Html.Raw("var item=table.rows('.selected').data()[0];")
- @Html.Raw("$('#MainContainer').toggle();");
- @Html.Raw("$('#New').toggle();");
- @Html.Raw("}");
- @Html.Raw("}");
- }
- }
- @{
- if (itemsView.Delete.Equals("1") && ViewBag.Admin)
- {
- @Html.Raw(",");
- @Html.Raw("{");
- @Html.Raw("text: 'Delete',");
- @Html.Raw("action: function () {");
- @Html.Raw("if (table.rows('.selected').count()>0){ ");
- @Html.Raw("var item = table.rows('.selected').data()[0];");
- @Html.Raw("$('#MainContainer').toggle();");
- @Html.Raw("$('#Delete').toggle();");
- int indexEdit = 0;
- foreach (var element in itemsView.data)
- {
- @Html.Raw("$('#D_" + @element.Name + "').val(htmlEscape(item[" + indexEdit + "])); ");
- indexEdit++;
- }
- @Html.Raw("}");
- @Html.Raw("else{toastr.warning('Select the object to delete...');}");
- @Html.Raw("}");
- @Html.Raw("}");
- }
- }
- @{
- if(itemsView.Export.Equals("1")){
- @Html.Raw(",");
- @Html.Raw("{ extend: 'csv', title: 'ExportFile',footer:false}");
- }
- }
- ],
- "autoWidth": true,
- initComplete: function () {
- this.api().columns().every(function () {
- var column = this;
- var select = $('<select ><option value=""></option></select>')
- // .appendTo($(column.footer()))
- .appendTo($(column.header()))
- .on('change', function () {
- var val = $.fn.dataTable.util.escapeRegex(
- $(this).val()
- );
- column
- .search(val ? '^' + val + '$' : '', true, false)
- .draw();
- });
- column.data().unique().sort().each(function (d, j) {
- select.append('<option value="' + d + '">' + d + '</option>')
- });
- });
- this.api().draw();
- }
- });
- $('#example2 tbody').on('click', 'tr', function () {
- table
- .rows('.selected')
- .nodes()
- .to$()
- .removeClass('selected');
- $(this).toggleClass('selected');
- });
- });
- </script>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement