diff --git a/app/assets/javascripts/repositories/forms/repository_item_edit.js b/app/assets/javascripts/repositories/forms/repository_item_edit.js index 039e581d5..34524f9d5 100644 --- a/app/assets/javascripts/repositories/forms/repository_item_edit.js +++ b/app/assets/javascripts/repositories/forms/repository_item_edit.js @@ -69,7 +69,7 @@ $.each(itemData.repository_row.repository_cells, function(i, cell) { var tableCellId = 'cellId-' + cell.repository_cell_id; if(cell.type === 'RepositoryAssetValue') { - formBindingsData[tableCellId] = new Blob([cell.value], { type: cell.value.file_content_type }); + formBindingsData[tableCellId] = new File(cell.asset_preview); } else { formBindingsData[tableCellId] = cell.value; } @@ -77,11 +77,10 @@ return formBindingsData; } - RepositoryItemEditForm.prototype.getRowNewData = function() { - return this.formData; - } - /** - * Private methods + /** + * |-----------------| + * | Private methods | + * |-----------------| */ /** @@ -100,7 +99,9 @@ } /** - * Takes object and creates an input file field + * Takes object and creates an input file field, contains a hidden + * input field which is triggered on button click and we get the uploaded + * file from there. * * @param {Object} object * @param {String} name @@ -111,8 +112,9 @@ */ function changeToInputFileField(object, name, value, id) { return "
" + - "
" + + "" + + "
" + "" + "" + ""; @@ -155,6 +157,7 @@ html += ''; return html; } + /** * Takes an object and creates custom html element * @@ -182,25 +185,46 @@ /** * Append the change listener to file field + * * @param {String} type * @param {Object} input + * @param {Object} formData * * @returns {undefined} */ - function _addSelectedFile(type, input) { + function _addSelectedFile(type, input, formData) { if (type === 'RepositoryAssetValue') { + $(input).on('change', function(){ this.dataset.changed = 'true'; + }).on('click', function(ev) { + ev.prevetDefault(); + ev.stopPropagation(); + var input = $(this).closest('input[type="file"]'); + input.trigger('click'); + initFileHandler(input, formData); }); } } + /** + * Handle extraction of file from the input field + * + * @param {Object} formData + * + * @returns {undefined} + */ + function initFileHandler(inputField, formData) { + if (inputField.files[0]) { + + } + } + function initializeDataBinding(row_node, data) { var uiBindings = {}; $.each(_.keys(data), function(i, element) { uiBindings['#' + element] = element; }) $(row_node).my({ui: uiBindings}, data); - debugger; } })(window); \ No newline at end of file diff --git a/app/assets/javascripts/repositories/repository_datatable.js.erb b/app/assets/javascripts/repositories/repository_datatable.js.erb index 78866f864..ec97c3221 100644 --- a/app/assets/javascripts/repositories/repository_datatable.js.erb +++ b/app/assets/javascripts/repositories/repository_datatable.js.erb @@ -667,35 +667,6 @@ var RepositoryDatatable = (function(global) { var editForm = new RepositoryItemEditForm(data, node); editForm.renderForm(TABLE); - /** - // Record name column - var colIndex = getColumnIndex('#row-name'); - if (colIndex) { - $(node).children('td').eq(colIndex) - .html(changeToInputField('repository_row', 'name', - data.repository_row.name)); - } - - // Take care of custom cells - var cells = data.repository_row.repository_cells; - var list_columns = data.repository_row.repository_column_items; - $(node).children('td').each(function(i) { - var td = $(this); - var rawIndex = TABLE.column.index('fromVisible', i); - var colHeader = TABLE.column(rawIndex).header(); - if ($(colHeader).hasClass('repository-column')) { - var type = $(colHeader).attr('data-type'); - // Check if cell on this record exists - var cell = cells[$(colHeader).attr('id')] || ''; - td.html(changeToFormField('repository_cell', - $(colHeader).attr('id'), - type, - cell, - list_columns)); - _addSelectedFile(type, cell, $(this).find('input')[0]); - } - }); - */ _initSelectPicker(); // initialize smart annotation diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index fc3f683c3..b987a29f2 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -86,7 +86,8 @@ class RepositoryRowsController < ApplicationController # Add custom cells ids as key (easier lookup on js side) @record.repository_cells.each do |cell| if cell.value_type == 'RepositoryAssetValue' - cell_value = cell.value.asset if cell.value_type == 'RepositoryAssetValue' + cell_value = cell.value.asset + asset_url = cell.value.asset.url(:original) else cell_value = escape_input(cell.value.data) end @@ -94,6 +95,7 @@ class RepositoryRowsController < ApplicationController json[:repository_row][:repository_cells][cell.repository_column_id] = { repository_cell_id: cell.id, value: cell_value, + asset_preview: (asset_url || ''), type: cell.value_type, list_items: fetch_list_items(cell) }