Fix linking files to not-saved entries

This commit is contained in:
Nathan Gray 2014-01-14 10:16:36 +00:00
parent ddc93e9af8
commit 29992a7fee
2 changed files with 47 additions and 26 deletions

View File

@ -140,7 +140,7 @@ class etemplate_widget_link extends etemplate_widget
*/ */
public static function ajax_link($app, $id, Array $links) { public static function ajax_link($app, $id, Array $links) {
// Files need to know full path in tmp directory // Files need to know full path in tmp directory
foreach($links as &$link) { foreach($links as $key => $link) {
if($link['app'] == egw_link::VFS_APPNAME) { if($link['app'] == egw_link::VFS_APPNAME) {
if (is_dir($GLOBALS['egw_info']['server']['temp_dir']) && is_writable($GLOBALS['egw_info']['server']['temp_dir'])) if (is_dir($GLOBALS['egw_info']['server']['temp_dir']) && is_writable($GLOBALS['egw_info']['server']['temp_dir']))
{ {
@ -151,7 +151,7 @@ class etemplate_widget_link extends etemplate_widget
$path = $link['id'].'+'; $path = $link['id'].'+';
} }
$link['tmp_name'] = $path; $link['tmp_name'] = $path;
$link['id'] = $link; $links[$key]['id'] = $link;
} }
} }
$result = egw_link::link($app, $id, $links); $result = egw_link::link($app, $id, $links);

View File

@ -235,7 +235,7 @@ var et2_link_to = et2_inputWidget.extend(
self.filesUploaded(event); self.filesUploaded(event);
// Auto-link uploaded files // Auto-link uploaded files
if(self.options.value.to_id) self.createLink(event); self.createLink(event);
} }
}; };
@ -326,7 +326,7 @@ var et2_link_to = et2_inputWidget.extend(
// Server says it's OK, but didn't store - we'll send this again on submit // Server says it's OK, but didn't store - we'll send this again on submit
// This happens if you link to something before it's saved to the DB // This happens if you link to something before it's saved to the DB
if(typeof success == "object" && success["Array:"]) if(typeof success == "object")
{ {
// Save as appropriate in value // Save as appropriate in value
var i = 0; var i = 0;
@ -334,23 +334,27 @@ var et2_link_to = et2_inputWidget.extend(
{ {
this.options.value = {}; this.options.value = {};
} }
if(typeof this.options.value.to_id != "object") this.options.value.to_id = success;
for(var link in success)
{ {
this.options.value.to_id = [];
}
i = this.options.value.to_id.length;
this.options.value.to_id[i] = success["Array:"].app[0];
// Fake it for the UI
var fake_data = {
// Icon should be in registry // Icon should be in registry
icon: egw.link_get_registry(this.options.value.to_id[i].app,'icon'), if(typeof success[link].icon == 'undefined')
app: this.options.value.to_id[i].app, {
id: this.options.value.to_id[i].id, success[link].icon = egw.link_get_registry(success[link].app,'icon');
// Make it easy to refer back if user deletes before saving // No icon, try by mime type - different place for un-saved entries
widget: this, if(success[link].icon == false && success[link].id.type)
value_index: i {
}; // Triggers icon by mime type, not thumbnail or app
success[link].type = success[link].id.type;
success[link].icon = true;
}
}
// Special handling for file - if not existing, we can't ask for title
if(success[link].app == 'file' && typeof success[link].title == 'undefined')
{
success[link].title = success[link].id.name || '';
}
}
} }
// Look for a link-list with the same ID, refresh it // Look for a link-list with the same ID, refresh it
@ -369,14 +373,31 @@ var et2_link_to = et2_inputWidget.extend(
this, et2_link_list this, et2_link_list
); );
// If there's fake data (entry is not yet saved), updating the list will // If there's an array of data (entry is not yet saved), updating the list will
// not work, so add it in. // not work, so add them in explicitly.
if(list_widget && fake_data) if(list_widget && success)
{ {
egw.link_title(fake_data.app, fake_data.id, function(title) { // Clear list
fake_data.title = title; list_widget.set_value(null);
list_widget._add_link(fake_data);
}); // Add temp links in
for(var link_id in success)
{
var link = success[link_id];
if(typeof link.title == 'undefined')
{
// Callback to server for title
egw.link_title(link.app, link.id, function(title) {
link.title = title;
list_widget._add_link(link);
});
}
else
{
// Add direct
list_widget._add_link(link);
}
}
} }
} }
else else