gecko-dev/mailnews/base/resources/content/subscribe.js

265 lines
6.0 KiB
JavaScript
Raw Normal View History

2000-03-21 03:16:39 +00:00
var gSubscribeTree = null;
var okCallback = null;
2000-03-21 03:16:39 +00:00
var gChangeTable = {};
var gServerURI = null;
var RDF = null;
var gSubscribeDS = null;
var gStatusBar = null;
var gNameField = null;
function Stop()
{
dump("Stop()\n");
dump("we need to stop the news url that is running.\n");
}
var Bundle = srGetStrBundle("chrome://messenger/locale/subscribe.properties");
function SetServerTypeSpecificTextValues()
{
var serverType = GetMsgFolderFromUri(gServerURI).server.type;
dump("serverType="+serverType+"\n");
/* set the server specific ui elements */
var element = document.getElementById("foldertextlabel");
var stringName = "foldertextfor-" + serverType;
var stringval = Bundle.GetStringFromName(stringName);
element.setAttribute('value',stringval);
stringName = "foldersheaderfor-" + serverType;
stringval = Bundle.GetStringFromName(stringName);
element = document.getElementById("foldersheaderlabel");
element.setAttribute('value',stringval);
}
function onServerClick(event)
{
var item = event.target;
gServerURI = item.id;
SetServerTypeSpecificTextValues();
SetUpTree();
}
function SetUpServerMenu()
{
dump("SetUpServerMenu()\n");
var serverMenu = document.getElementById("serverMenu");
var menuitems = serverMenu.getElementsByAttribute("id", gServerURI);
serverMenu.selectedItem = menuitems[0];
SetServerTypeSpecificTextValues();
}
var MySubscribeListener = {
OnStopPopulating: function() {
dump("root subscribe tree at: "+ gServerURI +"\n");
gSubscribeTree.setAttribute('ref',gServerURI);
// Turn progress meter off.
gStatusBar.setAttribute("mode","normal");
}
};
function SetUpTree()
2000-03-28 04:03:25 +00:00
{
dump("SetUpTree()\n");
gSubscribeTree.setAttribute('ref',null);
var folder = GetMsgFolderFromUri(gServerURI);
var server = folder.server;
try {
subscribableServer = server.QueryInterface(Components.interfaces.nsISubscribableServer);
2000-03-28 04:03:25 +00:00
subscribableServer.subscribeListener = MySubscribeListener;
// Turn progress meter on.
gStatusBar.setAttribute("mode","undetermined");
subscribableServer.populateSubscribeDatasource(null /* eventually, a nsIMsgWindow */);
}
catch (ex) {
dump("failed to populate subscribe ds: " + ex + "\n");
}
2000-03-28 04:03:25 +00:00
}
function SubscribeOnLoad()
{
2000-03-18 17:27:40 +00:00
dump("SubscribeOnLoad()\n");
2000-03-28 04:03:25 +00:00
gSubscribeTree = document.getElementById('subscribetree');
gStatusBar = document.getElementById('statusbar-icon');
gNameField = document.getElementById('namefield');
doSetOKCancel(subscribeOK,subscribeCancel);
// look in arguments[0] for parameters
if (window.arguments && window.arguments[0]) {
if ( window.arguments[0].title ) {
top.window.title = window.arguments[0].title;
}
if ( window.arguments[0].okCallback ) {
top.okCallback = window.arguments[0].okCallback;
}
}
if (window.arguments[0].preselectedURI) {
var uri = window.arguments[0].preselectedURI;
dump("subscribe: got a uri," + uri + "\n");
folder = GetMsgFolderFromUri(uri);
gServerURI = folder.server.serverURI;
}
else {
dump("subscribe: no uri\n");
var serverMenu = document.getElementById("serverMenu");
var menuitems = serverMenu.getElementsByTagName("menuitem");
gServerURI = menuitems[1].id;
}
SetUpServerMenu();
SetUpTree();
RDF = Components.classes["component://netscape/rdf/rdf-service"].getService();
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
gSubscribeDS = RDF.GetDataSource("rdf:subscribe");
}
function subscribeOK()
{
dump("in subscribeOK()\n")
if (top.okCallback) {
2000-03-21 03:16:39 +00:00
top.okCallback(top.gServerURI,top.gChangeTable);
}
return true;
}
function subscribeCancel()
{
dump("in subscribeCancel()\n");
Stop();
return true;
}
function SetState(uri,name,state,stateStr)
{
dump("SetState(" + uri +"," + name + "," + state + "," + stateStr + ")\n");
if (!uri || !stateStr) return;
try {
var src = RDF.GetResource(uri, true);
var prop = RDF.GetResource("http://home.netscape.com/NC-rdf#Subscribed", true);
var oldLiteral = gSubscribeDS.GetTarget(src, prop, true);
dump("oldLiteral="+oldLiteral+"\n");
oldValue = oldLiteral.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
dump("oldLiteral.Value="+oldValue+"\n");
if (oldValue != stateStr) {
var newLiteral = RDF.GetLiteral(stateStr);
gSubscribeDS.Change(src, prop, oldLiteral, newLiteral);
StateChanged(name,state);
}
2000-03-28 04:03:25 +00:00
}
catch (ex) {
dump("failed: " + ex + "\n");
2000-03-21 01:03:25 +00:00
}
}
function StateChanged(name,state)
2000-03-21 03:16:39 +00:00
{
dump("StateChanged(" + name + "," + state + ")\n");
dump("start val=" +gChangeTable[name] + "\n");
2000-03-21 03:16:39 +00:00
if (gChangeTable[name] == undefined) {
dump(name+" not in table yet\n");
gChangeTable[name] = state;
2000-03-21 03:16:39 +00:00
}
else {
var oldValue = gChangeTable[name];
dump(name+" already in table\n");
if (oldValue != state) {
gChangeTable[name] = undefined;
}
2000-03-21 03:16:39 +00:00
}
dump("end val=" +gChangeTable[name] + "\n");
2000-03-21 03:16:39 +00:00
}
2000-03-21 01:03:25 +00:00
function SetSubscribeState(state)
{
dump("SetSubscribedState()\n");
var stateStr;
if (state) {
stateStr = 'true';
}
else {
stateStr = 'false';
}
try {
2000-03-21 01:03:25 +00:00
dump("subscribe button clicked\n");
2000-03-21 03:16:39 +00:00
var groupList = gSubscribeTree.selectedItems;
2000-03-21 01:03:25 +00:00
for (i=0;i<groupList.length;i++) {
group = groupList[i];
uri = group.getAttribute('id');
dump(uri + "\n");
name = group.getAttribute('name');
dump(name + "\n");
SetState(uri,name,state,stateStr);
2000-03-21 01:03:25 +00:00
}
}
catch (ex) {
dump("SetSubscribedState failed: " + ex + "\n");
}
}
function ReverseStateFromNode(node)
{
var stateStr;
var state;
if (node.getAttribute('Subscribed') == "true") {
stateStr = "false";
state = false;
}
else {
stateStr = "true";
state = true;
}
var uri = node.getAttribute('id');
var name = node.getAttribute('name');
SetState(uri, name, state, stateStr);
}
function ReverseState(uri)
{
dump("ReverseState("+uri+")\n");
}
function SubscribeOnClick(event)
{
if (event.clickCount == 2) {
ReverseStateFromNode(event.target.parentNode.parentNode);
}
else {
var targetclass = event.target.getAttribute('class');
if (targetclass != 'tree-cell-twisty') {
var name = event.target.parentNode.parentNode.getAttribute('name');
gNameField.setAttribute('value',name);
}
}
}
2000-03-28 04:03:25 +00:00
function RefreshList()
{
dump("refresh list\n");
}