Commit d33abee5 authored by Tejesh's avatar Tejesh 🖖
Browse files

wip: save code

parent 08918dd6
Pipeline #77357 failed with stage
in 1 minute and 24 seconds
...@@ -309,6 +309,8 @@ function editHandler($this, template_data, options, template) { ...@@ -309,6 +309,8 @@ function editHandler($this, template_data, options, template) {
// TST: Ensure spec remains same // TST: Ensure spec remains same
// Listen for fh-row-selector events and Do what is being done now // Listen for fh-row-selector events and Do what is being done now
// Listen for // Listen for
var row_cache = {}
$('body') $('body')
.on('change', 'input.fh-row-selector', function(e) { .on('change', 'input.fh-row-selector', function(e) {
// toggle editable state // toggle editable state
...@@ -316,31 +318,17 @@ function editHandler($this, template_data, options, template) { ...@@ -316,31 +318,17 @@ function editHandler($this, template_data, options, template) {
var td_cells = row.children() var td_cells = row.children()
if ($(e.target).prop('checked')) { if ($(e.target).prop('checked')) {
// get closest tr from target, convert from second td - if ($(e.target).val() in row_cache) row_cache[$(e.target).val()] = row
// all td's with Input HTML elements as given in spec
// above is done with iteration
$.each(td_cells, function (index, td_cell) { $.each(td_cells, function (index, td_cell) {
if (index === 0) return if (index === 0) return
var isEditable = _.includes(options.columns, function(o) {return o.colinfo == td_cell.col_name}).isEditable var col_options = _.find(options.columns, function(o) {return o.name == $(td_cell).data('key')})
var val = td_cell.val() var isEditable = col_options ? col_options.editable: false
// isEditable = colinfo.editable === undefined ? true : colinfo.editable, $(td_cell).html(_.template(default_templates['template_editable'])({isEditable: isEditable, val: $(td_cell).data('value')}))
// <% } else if (isEdit && isEditable) { %>
// <td data-key="<%- colinfo.name %>">
// <%= _.template(templates['template_editable'])({isEditable: isEditable, val: val}) %>
// </td>
$(td_cell).html(_.template(default_templates['template_editable'])({isEditable: isEditable, val: val}))
}) })
} else { } else {
// take dictionary from tr element, // take dictionary from tr element,
// data-attribute and rebuild td with divs containing the value from dictionary // data-attribute and rebuild td with divs containing the value from dictionary
td_cells
// inject below html
var temp = `<td>
<a class="urlfilter" href="?<%- colinfo.name %>=<%- val %>&amp;_offset=">
<%= disp %>
</a>
</td>`
} }
}) })
.on('click', 'button.edit-btn', function () { .on('click', 'button.edit-btn', function () {
......
...@@ -96,7 +96,7 @@ Each template receives these variables: ...@@ -96,7 +96,7 @@ Each template receives these variables:
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<% menu_item = false } %> <% menu_item = false } %>
<% _.each(colinfo.filters, function(title, op) { menu_item = true %> <% _.each(colinfo.filters, function(title, op) { menu_item = true %>
<a class="dropdown-item <%= colinfo.name + op in args ? 'active' : '' %>" href="#" data-op="<%- op %>" data-toggle="modal" data-target="#fh-modal-<%- form_id %>"> <a class="dropdown-item <%- colinfo.name + op in args ? 'active' : '' %>" href="#" data-op="<%- op %>" data-toggle="modal" data-target="#fh-modal-<%- form_id %>">
<%- title %> <%- title %>
</a> </a>
<% }) %> <% }) %>
...@@ -138,7 +138,7 @@ Each template receives these variables: ...@@ -138,7 +138,7 @@ Each template receives these variables:
<% if (isEdit) { %> <% if (isEdit) { %>
<td> <td>
<%= _.template(templates['template_checkbox'])({ <%= _.template(templates['template_checkbox'])({
label: '', value: '', name: '', labelClass: 'm-0', label: '', value: rowIndex, name: '', labelClass: 'm-0',
id: '', checked: false, inputClass: 'fh-row-selector d-none' id: '', checked: false, inputClass: 'fh-row-selector d-none'
}) %> }) %>
</td> </td>
...@@ -160,19 +160,17 @@ Each template receives these variables: ...@@ -160,19 +160,17 @@ Each template receives these variables:
<% if (colinfo.template) { %> <% if (colinfo.template) { %>
<%= typeof colinfo.template == 'function' ? colinfo.template({name: colinfo.name, value: val, format: disp, link: col_link, index: rowIndex, row: row, data: data}) : _.template(colinfo.template)(({name: colinfo.name, value: val, format: disp, link: col_link, index: rowIndex, row: row, data: data})) %> <%= typeof colinfo.template == 'function' ? colinfo.template({name: colinfo.name, value: val, format: disp, link: col_link, index: rowIndex, row: row, data: data}) : _.template(colinfo.template)(({name: colinfo.name, value: val, format: disp, link: col_link, index: rowIndex, row: row, data: data})) %>
<% } else if (col_link) { %> <% } else if (col_link) { %>
<td data-key="<%- colinfo.name %>" data-value="<%- val %>">
<td> <a href="<%- col_link %>" target="_blank">
<a href="<%- col_link %>" target="_blank"> <%- disp %>
<%= disp %> </a>
</a> </td>
</td>
<% } else { %> <% } else { %>
<td> <td data-key="<%- colinfo.name %>" data-value="<%- val %>">
<a class="urlfilter" href="?<%- colinfo.name %>=<%- val %>&amp;_offset="> <a class="urlfilter" data-val="<%- %>" href="?<%- colinfo.name %>=<%- val %>&amp;_offset=">
<%= disp %> <%- disp %>
</a> </a>
</td> </td>
<% } %> <% } %>
<% }) %> <% }) %>
</tr> </tr>
...@@ -183,9 +181,9 @@ Each template receives these variables: ...@@ -183,9 +181,9 @@ Each template receives these variables:
<!-- end --> <!-- end -->
<!-- var template_checkbox --> <!-- var template_checkbox -->
<label for="<%- id %>" data-label="<%= label %>" class="<%- labelClass %>"> <label for="<%- id %>" data-label="<%- label %>" class="<%- labelClass %>">
<input type="checkbox" name="<%- name %>" id="<%- id %>" class="<%- inputClass %>" value="<%- value %>" <%- checked ? "checked": "" %>> <input type="checkbox" name="<%- name %>" id="<%- id %>" class="<%- inputClass %>" value="<%- value %>" <%- checked ? "checked": "" %>>
<%= label %> <%- label %>
</label> </label>
<!-- end --> <!-- end -->
...@@ -194,7 +192,7 @@ Each template receives these variables: ...@@ -194,7 +192,7 @@ Each template receives these variables:
<select <select
<% for (key in isEditable.attrs) { %> <% for (key in isEditable.attrs) { %>
<%= key + '="' + isEditable.attrs[key] + '"' %> <%- key + '="' + isEditable.attrs[key] + '"' %>
<% } %> <% } %>
class="form-control form-control-sm" class="form-control form-control-sm"
> >
...@@ -212,7 +210,7 @@ Each template receives these variables: ...@@ -212,7 +210,7 @@ Each template receives these variables:
<% _.each(isEditable.options, function(item) { %> <% _.each(isEditable.options, function(item) { %>
<input type="radio" <%- val && val === item ? 'checked': null %> value="<%- item %>" <input type="radio" <%- val && val === item ? 'checked': null %> value="<%- item %>"
<% for (key in isEditable.attrs) { %> <% for (key in isEditable.attrs) { %>
<%= key + '="' + isEditable.attrs[key] + '"' %> <%- key + '="' + isEditable.attrs[key] + '"' %>
<% } %> <% } %>
class="form-control form-control-sm" class="form-control form-control-sm"
/> />
...@@ -222,7 +220,7 @@ Each template receives these variables: ...@@ -222,7 +220,7 @@ Each template receives these variables:
<% } else { %> <% } else { %>
<input type="<%- isEditable.input || 'text' %>" value="<%- val %>" <input type="<%- isEditable.input || 'text' %>" value="<%- val %>"
<% for (key in isEditable.attrs) { %> <% for (key in isEditable.attrs) { %>
<%= key + '="' + isEditable.attrs[key] + '"' %> <%- key + '="' + isEditable.attrs[key] + '"' %>
<% } %> <% } %>
class="form-control form-control-sm" class="form-control form-control-sm"
/> />
...@@ -387,13 +385,13 @@ Each template receives these variables: ...@@ -387,13 +385,13 @@ Each template receives these variables:
} else { %> } else { %>
<div class="formhandler-grid row"> <div class="formhandler-grid row">
<% _.each(data, function(row, rowIndex) { %> <% _.each(data, function(row, rowIndex) { %>
<div class="col-sm-3 <%= options.classes || 'formhandler-grid-cell d-inline-block p-3 box-shadow' %>"> <div class="col-sm-3 <%- options.classes || 'formhandler-grid-cell d-inline-block p-3 box-shadow' %>">
<div class="thumbnail"> <div class="thumbnail">
<% img = options.icon ? ((typeof(options.icon) == 'function' ? options.icon({row: row, data: data, index: rowIndex}) : options.icon)) : 'fa fa-home' %> <% img = options.icon ? ((typeof(options.icon) == 'function' ? options.icon({row: row, data: data, index: rowIndex}) : options.icon)) : 'fa fa-home' %>
<% if (img.indexOf('fa ') >= 0) { %> <% if (img.indexOf('fa ') >= 0) { %>
<i class="<%= img %>"></i> <i class="<%- img %>"></i>
<% } else { %> <% } else { %>
<img class="img img-responsive" src="<%= img %>"/> <img class="img img-responsive" src="<%- img %>"/>
<% } %> <% } %>
<div class="caption"> <div class="caption">
<% _.each(cols, function(colinfo) { <% _.each(cols, function(colinfo) {
...@@ -404,13 +402,13 @@ Each template receives these variables: ...@@ -404,13 +402,13 @@ Each template receives these variables:
fmt === "string" && colinfo.type === "date" ? moment(val).format(colinfo.format) : fmt === "string" && colinfo.type === "date" ? moment(val).format(colinfo.format) :
val) %> val) %>
<div> <div>
<strong><%= colinfo.name %></strong>: <strong><%- colinfo.name %></strong>:
<% if ('link' in colinfo) { <% if ('link' in colinfo) {
var col_link = typeof colinfo.link == 'function' ? colinfo.link({row: row, value: val, index: rowIndex, name: colinfo.name, data: data, format: disp}) : _.template(colinfo.link)({row: row, value: val, index: rowIndex, name: colinfo.name, data: data, format: disp}) %> var col_link = typeof colinfo.link == 'function' ? colinfo.link({row: row, value: val, index: rowIndex, name: colinfo.name, data: data, format: disp}) : _.template(colinfo.link)({row: row, value: val, index: rowIndex, name: colinfo.name, data: data, format: disp}) %>
<a href="<%- col_link %>" target="_blank"><%= disp %></a> <a href="<%- col_link %>" target="_blank"><%- disp %></a>
<% } else { %> <% } else { %>
<a class="urlfilter" href="?<%- colinfo.name %>=<%- val %>&amp;_offset="> <a class="urlfilter" href="?<%- colinfo.name %>=<%- val %>&amp;_offset=">
<%= disp %> <%- disp %>
</a> </a>
<% } %> <% } %>
</div> </div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment