Automatically link files when selected - if entry has no ID, they wait until save

This commit is contained in:
Nathan Gray 2012-04-24 16:33:56 +00:00
parent 19ab4d3f4c
commit 67813fd767
3 changed files with 35 additions and 14 deletions

View File

@ -210,7 +210,33 @@ class etemplate_widget_link extends etemplate_widget
{ {
$form_name = self::form_name($cname, $this->id); $form_name = self::form_name($cname, $this->id);
$value = $value_in = self::get_array($content, $form_name); $value = $value_in =& self::get_array($content, $form_name);
// Look for files
$files = self::get_array($content, self::form_name($cname, $this->id . '_file'));
if(is_array($files) && !(is_array($value) && $value['to_id']))
{
$value = array();
if (is_dir($GLOBALS['egw_info']['server']['temp_dir']) && is_writable($GLOBALS['egw_info']['server']['temp_dir']))
{
$path = $GLOBALS['egw_info']['server']['temp_dir'] . '/';
}
else
{
$path = '';
}
foreach($files as $name => $attrs)
{
$value['to_id'][] = array(
'app' => egw_link::VFS_APPNAME,
'id' => array(
'name' => $attrs['name'],
'type' => $attrs['type'],
'tmp_name' => $path.$name
)
);
}
}
$valid =& self::get_array($validated, $form_name, true); $valid =& self::get_array($validated, $form_name, true);
$valid = $value; $valid = $value;
} }

View File

@ -342,6 +342,10 @@ console.warn(event,name,error);
.css("display", "block") .css("display", "block")
.text(this.egw().lang("Server error")); .text(this.egw().lang("Server error"));
} }
if(this.options.onFinishOne && typeof this.options.onFinishOne == 'function')
{
return this.options.onFinishOne(event,response,name,number,total);
}
return true; return true;
}, },

View File

@ -150,12 +150,15 @@ var et2_link_to = et2_inputWidget.extend({
multiple: true, multiple: true,
id: this.id + '_file', id: this.id + '_file',
onFinish: function(event, file_count) { onFinish: function(event, file_count) {
event.data = self;
self.filesUploaded(event); self.filesUploaded(event);
// Auto-link uploaded files
if(self.options.value.to_id) self.createLink(event);
} }
}; };
this.file_upload = et2_createWidget("file", file_attrs,this); this.file_upload = et2_createWidget("file", file_attrs,this);
return true; return true;
}, },
@ -167,18 +170,6 @@ var et2_link_to = et2_inputWidget.extend({
var self = this; var self = this;
this.link_button.show(); this.link_button.show();
// Add some comment fields
this.file_upload.progress.children().each(function() {
var comment = jQuery(document.createElement("input"))
.appendTo(this).hide();
self.link_entry.set_blur(self.egw().lang("Comment..."),comment);
var comment_icon = jQuery(document.createElement("span"))
.appendTo(this)
.addClass("ui-icon ui-icon-comment")
.click(function() {comment_icon.hide(); comment.toggle();})
});
}, },
/** /**