Skip to content

Commit

Permalink
#491. Add file_field_formatter_view() with file_table support.
Browse files Browse the repository at this point in the history
  • Loading branch information
signalpoint committed Mar 30, 2016
1 parent 9865897 commit 59efcff
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions src/modules/file/file.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
/**
* Implements hook_field_formatter_view().
* @param {String} entity_type
* @param {Object} entity
* @param {Object} field
* @param {Object} instance
* @param {String} langcode
* @param {Object} items
* @param {Object} display
*/
function file_field_formatter_view(entity_type, entity, field, instance, langcode, items, display) {
try {

//console.log(entity_type);
//console.log(entity);
//console.log(field);
//console.log(instance);
//console.log(langcode);
//console.log(items);
//console.log(display);

// Iterate over each item, and place a widget onto the render array.
var content = {};
for (var delta in items) {
if (!items.hasOwnProperty(delta)) { continue; }
var item = items[delta];
switch (display.type) {

case 'file_table':

// Instantiate the table only once.
if (!content['file_table']) {
content['file_table'] = {
theme: 'jqm_table',
header: [{ data: t('Attachment') }, { data: t('Size') }],
rows: [],
attributes: {
border: 1
}
};
}

// Add the row to the table.
content.file_table.rows.push([
l(item.filename, drupalgap_image_path(item.uri), { InAppBrowser: true }),
Math.round(item.filesize/1000).toFixed(2) + ' KB'
]);

break;

default:
console.log('file_field_formatter_view() - unsupported display type: ' + display.type);
break;
}
}
return content;
}
catch (error) { console.log('file_field_formatter_view - ' + error); }
}

/**
* Implements hook_field_formatter_view().
*/
function file_entity_field_formatter_view(entity_type, entity, field, instance, langcode, items, display) {
try {
Expand Down Expand Up @@ -39,4 +85,3 @@ function file_entity_field_formatter_view(entity_type, entity, field, instance,
}
catch (error) { console.log('file_entity_field_formatter_view - ' + error); }
}

0 comments on commit 59efcff

Please sign in to comment.