diff --git a/etemplate/inc/class.etemplate_widget_link.inc.php b/etemplate/inc/class.etemplate_widget_link.inc.php index 873134d601..601cea8592 100644 --- a/etemplate/inc/class.etemplate_widget_link.inc.php +++ b/etemplate/inc/class.etemplate_widget_link.inc.php @@ -230,9 +230,6 @@ class etemplate_widget_link extends etemplate_widget $link = egw_vfs::concat($app_path,egw_vfs::basename($target)); egw_vfs::symlink($target,$link); } - - // Return js to refresh opener and close popup - return 'window.close();'; } public function ajax_delete($value) { diff --git a/etemplate/js/et2_widget_link.js b/etemplate/js/et2_widget_link.js index 9ec33db45f..536c0cd9af 100644 --- a/etemplate/js/et2_widget_link.js +++ b/etemplate/js/et2_widget_link.js @@ -119,7 +119,8 @@ var et2_link_to = et2_inputWidget.extend( return this.link_div[0]; } else if (_sender._type == 'file') { return this.file_div[0]; - + } else if (_sender._type == 'vfs-select') { + return this.filemanager_button[0]; } }, @@ -152,40 +153,8 @@ var et2_link_to = et2_inputWidget.extend( et2_link_entry.prototype.set_blur(this.egw().lang("Comment..."),this.comment); // Filemanager link popup - var self = this; - this.filemanager_button = $j(document.createElement("img")) - .attr("src", this.egw().image("filemanager/navbar")) - .addClass("et2_button et2_button_icon") - .appendTo(this.div) - .click(this, function(e) { - // Open the filemanager select in a popup - var values = e.data.options.value; - var popup = e.data.egw().open_link( - '/index.php?menuaction=filemanager.filemanager_select.select&mode=open-multiple&method=etemplate_widget_link::link_existing&label=link&id=' + values.to_app + ":" + values.to_id, - 'link_existing', - '640x580' - ); - if(popup) - { - // Update on close doesn't always (ever, in chrome) work, so poll - var poll = self.egw().window.setInterval( - function() { - if(popup.closed) { - self.getRoot().iterateOver( - function(widget) { - if(widget.id == self.id) { - widget._get_links(); - } - }, - self, et2_link_list - ); - self.egw().window.clearInterval(poll); - } - },1000); - - } - }); - + this.filemanager_button = $j(document.createElement("div")).appendTo(this.div); + // Need a div for file upload widget this.file_div = $j(document.createElement("div")).appendTo(this.div); @@ -208,6 +177,24 @@ var et2_link_to = et2_inputWidget.extend( }; this.link_entry = et2_createWidget("link-entry", link_entry_attrs,this); + // Filemanager select + var select_attrs = { + method: 'etemplate_widget_link::link_existing', + method_id: function() { return self.options.value.to_app + ':' + self.options.value.to_id;}, + button_label: egw.lang('Link') + } + this.vfs_select = et2_createWidget("vfs-select", select_attrs,this); + $j(this.vfs_select.getDOMNode()).change( function() { + self.getRoot().iterateOver( + function(widget) { + if(widget.id == self.id) { + widget._get_links(); + } + }, + self, et2_link_list + ); + }); + // File upload var file_attrs = { multiple: true, diff --git a/etemplate/js/et2_widget_vfs.js b/etemplate/js/et2_widget_vfs.js index 02e1fe7f45..0b7a8f2195 100644 --- a/etemplate/js/et2_widget_vfs.js +++ b/etemplate/js/et2_widget_vfs.js @@ -555,3 +555,157 @@ var et2_vfsUpload = et2_file.extend( } }); et2_register_widget(et2_vfsUpload, ["vfs-upload"]); + + +var et2_vfsSelect = et2_inputWidget.extend( +{ + // Allowed mode options + modes: ['open','open-multiple','saveas','select-dir'], + + attributes: { + "mode": { + name: "Dialog mode", + type: "string", + description: "One of {open|open-multiple|saveas|select-dir}", + default: "open-multiple" + }, + "method": { + name: "Server side callback", + type: "string", + description: "Server side callback to process selected value(s) in app.class.method or class::method format. The first parameter will be Method ID, the second the file list." + }, + "method_id": { + name: "Method ID", + type: "any", + description: "optional parameter passed to server side callback. Can be a string or a function.", + default: "" + }, + "path": { + name: "Path", + type: "string", + description:"Start path in VFS. Leave unset to use the last used path." + }, + "mime": { + name: "Mime type", + type: "string", + description: "Limit display to the given mime-type" + }, + "button_label": { + name: "Button label", + description: "Set the label on the dialog's OK button.", + default: "open" + }, + "value": { + "type": "any", // Object + "description": "Array of paths (strings)" + } + }, + + /** + * Constructor + * + * @param _parent + * @param _attrs + * @memberOf et2_vfsSelect + */ + init: function(_parent, _attrs) { + // _super.apply is responsible for the actual setting of the params (some magic) + this._super.apply(this, arguments); + + // Allow no child widgets + this.supportedWidgetClasses = []; + + this.button = $j(document.createElement("img")) + .attr("src", this.egw().image("filemanager/navbar")) + .addClass("et2_button et2_button_icon") + this.setDOMNode(egw.userData.apps.filemanager ? this.button[0]:document.createElement('span')); + }, + + click: function(e) { + + // No permission + if(typeof egw.userData.apps.filemanager == 'undefined') return; + + var self = this; + + var attrs = { + menuaction: 'filemanager.filemanager_select.select', + mode: this.options.mode, + method: this.options.method, + label: this.options.button_label, + id: typeof this.options.method_id == "function" ? this.options.method_id.call(): this.options.method_id + }; + if(this.options.path) + { + attrs.path = this.options.path; + } + if(this.options.mime) + { + attrs.mime = this.options.mime; + }; + + // Open the filemanager select in a popup + var popup = this.egw().open_link( + this.egw().link('/index.php', attrs), + 'link_existing', + '640x580' + ); + if(popup) + { + // Update on close doesn't always (ever, in chrome) work, so poll + var poll = self.egw().window.setInterval( + function() { + if(popup.closed) { + self.egw().window.clearInterval(poll); + + // Update path to where the user wound up + var path = popup.etemplate2.getByApplication('filemanager')[0].widgetContainer.getArrayMgr("content").getEntry('path') || ''; + self.options.path = path; + + // Get the selected files + var files = popup.selected_files || []; + self.value = files; + + // Fire a change event so any handlers run + $j(self.node).change(); + } + },1000 + ); + } + }, + + /** + * Set the dialog's mode. + * Valid options are in et2_vfsSelect.modes + * + */ + set_mode: function(mode) { + // Check mode + if(jQuery.inArray(mode, this.modes) < 0) + { + this.egw().debug("warn", "Invalid mode for '%s': %s Valid options:", this.id,mode, this.modes); + return; + } + this.options.mode = mode; + }, + + /** + * Set the label on the dialog's OK button. + */ + set_button_label: function(label) + { + this.options.button_label = label; + }, + + /** + * Set the ID passed to the server side callback + */ + set_method_id: function(id) { + this.options.method_id = id; + }, + + get_value: function() { + return this.value; + } +}); +et2_register_widget(et2_vfsSelect, ["vfs-select"]); \ No newline at end of file diff --git a/filemanager/inc/class.filemanager_select.inc.php b/filemanager/inc/class.filemanager_select.inc.php index df1048f73c..05e7e62d94 100644 --- a/filemanager/inc/class.filemanager_select.inc.php +++ b/filemanager/inc/class.filemanager_select.inc.php @@ -183,11 +183,11 @@ class filemanager_select break; } - if ($content['method'] != 'ckeditor_return') + if ($content['method'] && $content['method'] != 'ckeditor_return') { $js = ExecMethod2($content['method'],$content['id'],$files); } - else + else if ($content['method'] == 'ckeditor_return') { $download_url = egw_vfs::download_url(egw_vfs::concat($content['path'],$content['name'])); if ($download_url[0] == '/') $download_url = egw::link($download_url); @@ -196,8 +196,22 @@ class filemanager_select htmlspecialchars($download_url)."',". "'');\nwindow.close();"; } - header('Content-type: text/html; charset='.translation::charset()); - echo "\n
\n\n\n\n"; + if(egw_json_response::isJSONResponse()) + { + $response = egw_json_response::get(); + if($js) + { + $response->script($js); + } + // Ahh! + // The vfs-select widget looks for this + $response->script('this.selected_files = '.json_encode($files) . '; this.close();'); + } + else + { + header('Content-type: text/html; charset='.translation::charset()); + echo "\n\n\n\n\n"; + } common::egw_exit(); } } @@ -228,7 +242,7 @@ class filemanager_select { $content['path'] = filemanager_ui::get_home_dir(); } - $tpl = new etemplate('filemanager.select'); + $tpl = new etemplate_new('filemanager.select'); $et2 = class_exists('etemplate_widget', false) && is_a($tpl, 'etemplate_widget'); if (!($files = egw_vfs::find($content['path'],array( @@ -259,9 +273,9 @@ class filemanager_select 'name' => $name, 'path' => $path, 'mime' => $mime, - 'onclick' => $is_dir ? "return select_goto('".addslashes($path)."'".($et2?',widget':'').");" : - ($content['mode'] != 'open-multiple' ? "return select_show('".addslashes($name)."');" : - "return select_toggle('".addslashes($name)."');"), + 'onclick' => $is_dir ? "return app.filemanager.select_goto('".addslashes($path)."'".($et2?',widget':'').");" : + ($content['mode'] != 'open-multiple' ? "return app.filemanager.select_show('".addslashes($name)."');" : + "return app.filemanager.select_toggle('".addslashes($name)."');"), ); if ($is_dir && $content['mode'] == 'open-multiple') { @@ -273,45 +287,6 @@ class filemanager_select } $readonlys['button[createdir]'] = !egw_vfs::is_writable($content['path']); - $content['js'] = ' -'; // scroll to end of path $GLOBALS['egw']->js->set_onload("var p = document.getElementById('exec[path][c". (count(explode('/',$content['path']))-1) ."]'); if (p) p.scrollIntoView();"); diff --git a/filemanager/js/app.js b/filemanager/js/app.js index c01e49c89f..f420e75faa 100644 --- a/filemanager/js/app.js +++ b/filemanager/js/app.js @@ -643,5 +643,40 @@ app.filemanager = AppJS.extend( } } } + }, + + /** + * Functions for the select dialog + */ + select_goto: function(to,widget) + { + if (widget) + { + var path = null; + // Cannot do this, there are multiple widgets named path + // widget.getRoot().getWidgetById("path"); + widget.getRoot().iterateOver(function(widget) { + if(widget.id == "path") path = widget; + },null, et2_textbox); + if(path) + { + path.set_value(to); + path.getInstanceManager().postSubmit(); + } + } + return false; + }, + + select_show: function(file) + { + var editfield = document.getElementById("exec[name]"); + editfield.value = file; + return false; + }, + select_toggle: function(file) + { + checkbox = document.getElementById("exec[dir][selected]["+file+"]"); + if (checkbox) checkbox.checked = !checkbox.checked; + return false; } }); diff --git a/filemanager/templates/default/select.xet b/filemanager/templates/default/select.xet index d2beddc746..00e50bda6b 100644 --- a/filemanager/templates/default/select.xet +++ b/filemanager/templates/default/select.xet @@ -34,9 +34,8 @@