[Zope-CVS] CVS: Packages/Moztop/moztop/content/ContentObjects/Image - Upload.js:1.2 Upload.xul:1.2
Stephan Richter
srichter@cbu.edu
Thu, 16 Jan 2003 07:46:46 -0500
Update of /cvs-repository/Packages/Moztop/moztop/content/ContentObjects/Image
In directory cvs.zope.org:/tmp/cvs-serv17005/moztop/content/ContentObjects/Image
Modified Files:
Upload.js Upload.xul
Log Message:
- Image Upload is now working! Yeah!
=== Packages/Moztop/moztop/content/ContentObjects/Image/Upload.js 1.1 => 1.2 ===
--- Packages/Moztop/moztop/content/ContentObjects/Image/Upload.js:1.1 Thu Jan 16 04:55:38 2003
+++ Packages/Moztop/moztop/content/ContentObjects/Image/Upload.js Thu Jan 16 07:46:43 2003
@@ -17,14 +17,100 @@
******************************************************************************/
+/* Retrieve path of active content object. */
+function getActiveContentObjectPath() {
+ doc = getDocumentOfWindowWithId("moztop-main-window");
+ var tabs = doc.getElementById("active-contents-tabs");
+ return tabs.selectedItem.getAttribute('label')
+}
+
+/* XML-RPC setup stuff. */
+function getClient() {
+ return Components.classes['@mozilla.org/xml-rpc/client;1']
+ .createInstance(Components.interfaces.nsIXmlRpcClient);
+}
+
+var xmlRpcClient;
+function getXmlRpc() {
+ if (!xmlRpcClient) xmlRpcClient = getClient();
+ return xmlRpcClient;
+}
+var file = null;
+
+/* Handle choosing a File. */
function handleFilePicker() {
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
- fp.init(window, "Select a File", nsIFilePicker.modeOpen);
- var res=fp.show();
- // if (res==nsIFilePicker.returnOK){
- // var thefile=fp.file;
- // }
+ fp.appendFilters(nsIFilePicker.filterImages);
+ fp.init(window, "Select an Image File", nsIFilePicker.modeOpen);
+ var res = fp.show();
+ if (res == nsIFilePicker.returnOK){
+ file = fp.file;
+ textbox = document.getElementById('field_upload');
+ textbox.value = file.path;
+ }
}
+
+var SaveListener = {
+ onResult: function(client, ctxt, result) {
+ refresh();
+ alert('Uploaded');
+ },
+ onFault: function(client, ctxt, fault) {
+ alert('Fault! ' + fault + '\n');
+ },
+ onError: function(client, ctxt, status, errorMsg) {
+ alert('Error! <(' + status.toString(16) + ') ' + errorMsg + '>\n');
+ }
+};
+
+/* Uploading the file to the server. */
+function uploadFile() {
+ path = getActiveContentObjectPath();
+ var xmlRpc = getXmlRpc();
+ xmlRpc.init(XMLRPC_BASE + path + '/');
+
+ /* Okay, converting our file object to a stream, so that the XmlRpcClient
+ can handle it. */
+ perm = Components.interfaces.nsIFileChannel.NS_RDONLY;
+ fio = Components.classes["@mozilla.org/network/file-io;1"]
+ .createInstance(Components.interfaces.nsIFileIO);
+ fio.init(file, perm, -1);
+ fio.open();
+
+ xmlRpc.asyncCall(SaveListener, null, 'upload', [fio.inputStream], 1);
+}
+
+/* Load image info */
+var LoadListener = {
+ onResult: function(client, ctxt, result) {
+ result = result.QueryInterface(
+ Components.interfaces.nsIDictionary);
+
+ size = result.getValue('size').QueryInterface(
+ Components.interfaces.nsISupportsCString);
+ document.getElementById("field_size").value = size;
+
+ content_type = result.getValue('content_type').QueryInterface(
+ Components.interfaces.nsISupportsCString);
+ document.getElementById(
+ "field_content_type").value = content_type;
+ },
+ onFault: function(client, ctxt, fault) {
+ alert('Fault! ' + fault + '\n');
+ },
+ onError: function(client, ctxt, status, errorMsg) {
+ alert('Error! <(' + status.toString(16) + ') ' + errorMsg + '>\n');
+ }
+};
+
+/* Refresh the info. */
+function refresh() {
+ path = getActiveContentObjectPath();
+ var xmlRpc = getXmlRpc();
+ xmlRpc.init(XMLRPC_BASE + path + '/');
+ xmlRpc.asyncCall(LoadListener, null, 'getImageInfo', [], 0);
+}
+
=== Packages/Moztop/moztop/content/ContentObjects/Image/Upload.xul 1.1 => 1.2 ===
--- Packages/Moztop/moztop/content/ContentObjects/Image/Upload.xul:1.1 Thu Jan 16 04:55:38 2003
+++ Packages/Moztop/moztop/content/ContentObjects/Image/Upload.xul Thu Jan 16 07:46:43 2003
@@ -5,6 +5,7 @@
<window
orient="vertical"
+ onload="refresh();"
xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript"
@@ -25,20 +26,20 @@
<label id="field_size" value="? x ?; 1kB" />
</row>
<row>
- <label control="field_title" value="Title"/>
- <textbox id="field_title" flex="1"/>
+ <label control="field_content_type" value="Content Type"/>
+ <textbox id="field_content_type" value="image/png" flex="1"/>
</row>
<row>
<label control="field_upload" value="File to Upload"/>
<box orient="horizontal">
- <textbox id="field_upload" flex="1"/>
+ <textbox id="field_upload" value="" flex="1"/>
<button onclick="handleFilePicker();" label="File..." />
</box>
</row>
</rows>
</grid>
<box orient="horizontal">
- <button onclick="save()" label="Save" />
+ <button onclick="uploadFile()" label="Upload" />
<button onclick="refresh()" label="Refresh" />
<spring flex="100%" />
</box>