Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Webclient: polish upload dialog code (#289).

The upload dialog code is moved from Webclient to Files module.
The file upload_dislog.js is deleted.

IMPORTANT: if your plugin makes use of the upload dialog it must be adapted.
To open the dialog:
{{{
    dm4c.get_plugin("de.deepamehta.files").open_upload_dialog(...)
}}}

See ticket 289.
  • Loading branch information...
commit a18231a716b4937ce89b27fca87192393a4c8620 1 parent 264c83a
@jri authored
View
10 modules/dm4-files/src/main/java/de/deepamehta/plugins/files/UploadedFile.java
@@ -12,8 +12,9 @@
* Files are uploaded via the REST API by POSTing <code>multipart/form-data</code> to the <code>/files</code>
* resource.
* <p>
- * Client-side support: the <code>deepamehta-webclient</code> plugin provides an utility method
- * <code>dm4c.upload_dialog.open()</code> that allows the user to choose and upload a file.</p>
+ * Client-side support: the public API of the <code>deepamehta-files</code> plugin provides a method
+ * <code>dm4c.get_plugin("de.deepamehta.files").open_upload_dialog()</code> that allows the user to
+ * choose and upload a file.</p>
* <p>
* At server-side a plugin accesses the upload file via the
* {@link de.deepamehta.core.service.Plugin#executeCommandHook}. ### FIXDOC</p>
@@ -34,11 +35,6 @@ public UploadedFile(FileItem fileItem) {
// -------------------------------------------------------------------------------------------------- Public Methods
- /* ### FIXME: not in use
- public InputStream getInputStream() {
- return fileItem.getInputStream(); // throws IOException
- } */
-
/**
* Returns the original (client-side) file name.
*/
View
50 modules/dm4-files/src/main/resources/web/script/plugin.js
@@ -1,5 +1,7 @@
dm4c.add_plugin("de.deepamehta.files", function() {
+ var self = this
+
// === REST Client Extension ===
dm4c.restc.create_file_topic = function(path) {
@@ -150,7 +152,7 @@ dm4c.add_plugin("de.deepamehta.files", function() {
function do_open_upload_dialog() {
var path = topic.get("dm4.files.path")
- dm4c.upload_dialog.open(path, show_response)
+ self.open_upload_dialog(path, show_response)
function show_response(response) {
alert("Upload response=" + JSON.stringify(response))
@@ -159,6 +161,7 @@ dm4c.add_plugin("de.deepamehta.files", function() {
})
+
// ------------------------------------------------------------------------------------------------------ Public API
/**
@@ -206,6 +209,51 @@ dm4c.add_plugin("de.deepamehta.files", function() {
}
}
+ // ---
+
+ /**
+ * @param path the file repository path (a string) to upload the selected file to. Must begin with "/".
+ * @param callback the function that is invoked once the file has been uploaded and processed at server-side.
+ * One argument is passed to that function: the object (deserialzed JSON)
+ * returned by the (server-side) executeCommandHook. ### FIXDOC
+ */
+ this.open_upload_dialog = (function() {
+
+ // 1) install upload target
+ var upload_target = $("<iframe>", {name: "upload-target"}).hide()
+ $("body").append(upload_target)
+
+ // 2) create upload dialog
+ var upload_form = $("<form>", {
+ method: "post",
+ enctype: "multipart/form-data",
+ target: "upload-target"
+ })
+ .append($('<input type="file">').attr({name: "file", size: 60})) // Note: attr() must be used here.
+ .append($('<input type="submit">').attr({value: "Upload"})) // An attr object as 2nd param doesn't work!
+ //
+ var upload_dialog = dm4c.ui.dialog({title: "Upload File", content: upload_form})
+
+ // 3) create dialog handler
+ return function(path, callback) {
+ upload_form.attr("action", "/files/" + path)
+ upload_dialog.open()
+ // bind handler
+ upload_target.unbind("load") // Note: the previous handler must be removed
+ upload_target.load(upload_complete)
+
+ function upload_complete() {
+ upload_dialog.close()
+ // Note: iframes must be accessed via window.frames
+ var response = $("pre", window.frames["upload-target"].document).text()
+ try {
+ callback(JSON.parse(response))
+ } catch (e) {
+ alert("Upload failed: \"" + response + "\"\n\nException=" + JSON.stringify(e))
+ }
+ }
+ }
+ })()
// ------------------------------------------------------------------------------------------------- Private Classes
View
1  modules/dm4-webclient/src/main/resources/web/index.html
@@ -26,7 +26,6 @@
<script src="/de.deepamehta.webclient/script/gui/split_panel.js"></script>
<script src="/de.deepamehta.webclient/script/gui/toolbar_panel.js"></script>
<script src="/de.deepamehta.webclient/script/gui/page_panel.js"></script>
- <script src="/de.deepamehta.webclient/script/gui/upload_dialog.js"></script>
<script src="/de.deepamehta.webclient/script/plugin_manager.js"></script>
<script src="/de.deepamehta.webclient/script/webclient.js"></script>
</head>
View
42 modules/dm4-webclient/src/main/resources/web/script/gui/upload_dialog.js
@@ -1,42 +0,0 @@
-function UploadDialog() {
-
- var upload_form = $("<form>", {
- method: "post",
- enctype: "multipart/form-data",
- target: "upload-target"
- })
- .append($('<input type="file">').attr({name: "file", size: 60})) // Note: attr() must be used here.
- .append($('<input type="submit">').attr({value: "Upload"})) // An attr object as 2nd param doesn't work!
-
- var upload_dialog = dm4c.ui.dialog({title: "Upload File", content: upload_form})
-
- var upload_target = $("<iframe>", {name: "upload-target"}).hide()
- $("body").append(upload_target)
-
- // -------------------------------------------------------------------------------------------------- Public Methods
-
- /**
- * @param path the file repository path (a string) to upload the selected file to. Must begin with "/".
- * @param callback the function that is invoked once the file has been uploaded and processed at server-side.
- * One argument is passed to that function: the object (deserialzed JSON)
- * returned by the (server-side) executeCommandHook. ### FIXDOC
- */
- this.open = function(path, callback) {
- upload_form.attr("action", "/files/" + path)
- upload_dialog.open()
- // bind handler
- upload_target.unbind("load") // Note: the previous handler must be removed
- upload_target.load(upload_complete)
-
- function upload_complete() {
- upload_dialog.close()
- // Note: iframes must be accessed via window.frames
- var response = $("pre", window.frames["upload-target"].document).text()
- try {
- callback(JSON.parse(response))
- } catch (e) {
- alert("Upload failed: \"" + response + "\"\n\nException=" + JSON.stringify(e))
- }
- }
- }
-}
View
3  modules/dm4-webclient/src/main/resources/web/script/webclient.js
@@ -40,7 +40,6 @@ function Webclient() {
this.toolbar = null // the upper toolbar GUI component (a ToolbarPanel object)
this.canvas = null // the canvas GUI component that displays the topicmap (a TopicmapRenderer object)
this.page_panel = null // the page panel GUI component on the right hand side (a PagePanel object)
- this.upload_dialog = null // the upload dialog (an UploadDialog object)
var type_cache = new TypeCache()
@@ -1268,8 +1267,6 @@ function Webclient() {
dm4c.canvas = new DefaultTopicmapRenderer()
dm4c.split_panel.set_left_panel(dm4c.canvas)
//
- dm4c.upload_dialog = new UploadDialog()
- //
// 2) Setup Load Tracker
var items_to_load = pm.retrieve_plugin_list()
var number_of_loads = items_to_load + 2 // +2 loads: topic types and association types
Please sign in to comment.
Something went wrong with that request. Please try again.