[Zope-CVS] CVS: Packages/Moztop/moztop/content/Content/Image - MetaData.js:1.1 MetaData.xul:1.1 Preview.js:1.1 Preview.xul:1.1 Security.xul:1.1 Upload.js:1.1 Upload.xul:1.1

Paul Everitt paul@zope.com
Sat, 15 Feb 2003 05:44:25 -0500


Update of /cvs-repository/Packages/Moztop/moztop/content/Content/Image
In directory cvs.zope.org:/tmp/cvs-serv15538/Image

Added Files:
	MetaData.js MetaData.xul Preview.js Preview.xul Security.xul 
	Upload.js Upload.xul 
Log Message:
Rearranging directories, landing first cut at XBL

=== Added File Packages/Moztop/moztop/content/Content/Image/MetaData.js ===
/*****************************************************************************
*
* Copyright (c) 2002, 2003 Zope Corporation and Contributors.
* All Rights Reserved.
*
* This software is subject to the provisions of the Zope Public License,
* Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
* WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
******************************************************************************
Meta Data Tab specific Javascript functions. With them you can load and save
the meta data.

$Id: MetaData.js,v 1.1 2003/02/15 10:44:24 paul Exp $

******************************************************************************/

/* 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;
}

/* XML-RPC listener for loading meta data. */
var LoadListener = {
    onResult: function(client, ctxt, result) {
        result = result.QueryInterface(
	    Components.interfaces.nsIDictionary);
	title = result.getValue('title').QueryInterface(
	    Components.interfaces.nsISupportsCString);
	document.getElementById("field_title").value = title;

	desc = result.getValue('description').QueryInterface(
	    Components.interfaces.nsISupportsCString);
	document.getElementById("field_description").value = desc;

	created = result.getValue('created').QueryInterface(
	    Components.interfaces.nsISupportsCString);
	document.getElementById("field_created").value = created;

	modified = result.getValue('modified').QueryInterface(
	    Components.interfaces.nsISupportsCString);
	document.getElementById("field_modified").value = modified;
    },
    onFault: function(client, ctxt, fault) {
        alert('Fault! ' + fault + '\n');
    },
    onError: function(client, ctxt, status, errorMsg) {
        alert('Error! <(' + status.toString(16) + ') ' + errorMsg + '>\n');
    }
};

/* Load meta data from server. */
function loadMetaData() {
    path = getActiveContentObjectPath();
    var xmlRpc = getXmlRpc();
    xmlRpc.init(XMLRPC_BASE + path + '/');
    xmlRpc.asyncCall(LoadListener, null, 'getMetaData', [], 0);
}


/* XML-RPC listener for saving meta data. */
var SaveListener = {
    onResult: function(client, ctxt, result) {
	loadMetaData();
    },
    onFault: function(client, ctxt, fault) {
        alert('Fault! ' + fault + '\n');
    },
    onError: function(client, ctxt, status, errorMsg) {
        alert('Error! <(' + status.toString(16) + ') ' + errorMsg + '>\n');
    }
};

/* Save meta data to server. */
function saveMetaData() {
    path = getActiveContentObjectPath();
    var xmlRpc = getXmlRpc();
    xmlRpc.init(XMLRPC_BASE + path + '/');
    var title = xmlRpc.createType(xmlRpc.STRING, {});
    title.data = document.getElementById("field_title").value;
    var desc = xmlRpc.createType(xmlRpc.STRING, {});
    desc.data = document.getElementById("field_description").value;
    xmlRpc.asyncCall(SaveListener, null, 'setMetaData', [title, desc], 2);
}


=== Added File Packages/Moztop/moztop/content/Content/Image/MetaData.xul ===
<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://moztop/skin" type="text/css"?>

<window
    xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    onload="loadMetaData();">

  <script type="application/x-javascript" 
          src="chrome://moztop/content/setup.js"/>
  <script type="application/x-javascript" 
          src="chrome://moztop/content/global.js"/>
  <script type="application/x-javascript" src="MetaData.js"/>

  <groupbox>
    <caption label="Edit"/>

    <grid flex="1">
      <columns>
        <column/>
        <column flex="1"/>
      </columns>
      <rows>
        <row>
          <label control="field_title" value="Title"/>
          <textbox id="field_title" flex="1"/>
        </row>
        <row>
          <label control="field_description" value="Description"/>
          <textbox id="field_description" flex="1"/>
        </row>
        <row>
          <label value="Created on:" />
	  <label id="field_created" value="01/01/2003" />
        </row>
        <row>
          <label value="Last modified on:" />
	  <label id="field_modified" value="01/01/2003" />
        </row>
      </rows>
    </grid>
    <box orient="horizontal">
      <button onclick="saveMetaData()" label="Save" />
      <button onclick="loadMetaData()" label="Refresh" />
      <spring flex="100%" />
    </box>
  </groupbox>

</window>

=== Added File Packages/Moztop/moztop/content/Content/Image/Preview.js ===
/*****************************************************************************
*
* Copyright (c) 2002, 2003 Zope Corporation and Contributors.
* All Rights Reserved.
*
* This software is subject to the provisions of the Zope Public License,
* Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
* WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
******************************************************************************
Preview Tab specific Javascript functions. 

$Id: Preview.js,v 1.1 2003/02/15 10:44:24 paul Exp $

******************************************************************************/

/* 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')
}

/* Load preview in IFrame */
function loadPreview() {
    iframe = document.getElementById('preview-frame');
    iframe.setAttribute('src', HTML_BASE + getActiveContentObjectPath());
}


=== Added File Packages/Moztop/moztop/content/Content/Image/Preview.xul ===
<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://moztop/skin" type="text/css"?>

<window
   orient = "vertical"
   onload = "loadPreview();"
   xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/x-javascript" 
          src="chrome://moztop/content/setup.js"/>
  <script type="application/x-javascript" 
          src="chrome://moztop/content/global.js"/>
  <script type="application/x-javascript" src="Preview.js"/>

   <iframe id="preview-frame" flex="1"/>
   <box orient="horizontal">
     <button onclick="loadPreview();" label="Reload Content" />
     <spring flex="100%" />
   </box>

</window>

=== Added File Packages/Moztop/moztop/content/Content/Image/Security.xul ===
<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://moztop/skin" type="text/css"?>

<window
   xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <label value="Security" />
    <image src="chrome://moztop/content/moztop.png" />

</window>

=== Added File Packages/Moztop/moztop/content/Content/Image/Upload.js ===
/*****************************************************************************
*
* Copyright (c) 2002, 2003 Zope Corporation and Contributors.
* All Rights Reserved.
*
* This software is subject to the provisions of the Zope Public License,
* Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
* WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
******************************************************************************
Upload Tab specific Javascript functions. 

$Id: Upload.js,v 1.1 2003/02/15 10:44:24 paul Exp $

******************************************************************************/

/* 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.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);
}



=== Added File Packages/Moztop/moztop/content/Content/Image/Upload.xul ===
<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://moztop/skin" type="text/css"?>

<window
   orient="vertical"
   onload="refresh();"
   xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/x-javascript" 
          src="chrome://moztop/content/setup.js"/>
  <script type="application/x-javascript" 
          src="chrome://moztop/content/global.js"/>
  <script type="application/x-javascript" src="Upload.js"/>


    <grid>
      <columns>
        <column/>
        <column flex="1"/>
      </columns>
      <rows>
        <row>
          <label value="Size:" />
	  <label id="field_size" value="? x ?; 1kB" />
        </row>
        <row>
          <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" value="" flex="1"/>
	    <button onclick="handleFilePicker();" label="File..." />
	  </box>
        </row>
      </rows>
    </grid>
    <box orient="horizontal">
      <button onclick="uploadFile()" label="Upload" />
      <button onclick="refresh()" label="Refresh" />
      <spring flex="100%" />
    </box>


</window>