PK
vA$77^jb b ) content/flock/common/accountManagement.js// BEGIN FLOCK GPL
//
// Copyright Flock Inc. 2005-2007
// http://flock.com
//
// This file may be used under the terms of of the
// GNU General Public License Version 2 or later (the "GPL"),
// http://www.gnu.org/licenses/gpl.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// END FLOCK GPL
Cc = Components.classes;
Ci = Components.interfaces;
var gService = null;
/*
* Coop stuff
*/
var faves_coop = Cc["@flock.com/singleton;1"]
.getService(Ci.flockISingleton)
.getSingleton("chrome://flock/content/common/load-faves-coop.js")
.wrappedJSObject;
function onLoad() {
// Populates the service list
serviceList = $("serviceList");
// Do we need to select a given service first?
var params = window.arguments[0];
// Load the accounts for the first service
var services = getFlockWebServices()
for (var i = 0; i < services.length; i++) {
var contractID = services[i][0];
var svc = services[i][1];
var accountitem = document.createElement("listitem");
accountitem.setAttribute('label', svc.title);
accountitem.setAttribute('value', contractID);
accountitem.setAttribute('image', svc.icon);
accountitem.setAttribute('class', 'listitem-iconic');
// accountitem.setAttribute('onclick', 'loadService("'+contractID+'")');
accountitem.svc = svc;
serviceList.appendChild(accountitem);
}
if (params && params.serviceid)
loadService(params.serviceid);
updateButtons();
}
function getServiceConfirmation(aUrn) {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("flock.service.confirmation.");
var value = null;
try{
value = prefs.getBoolPref (aUrn);
} catch(e) {
return true; // default value is to ask the user
}
return value;
}
function setServiceConfirmation(aUrn, aValue) {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("flock.service.confirmation.");
prefs.setBoolPref (aUrn, aValue);
}
function loadService(aContractID) {
gService = Cc[aContractID].getService(Ci.flockIWebService);
var accountList = $('accountList');
$("accounts-label").value = "Accounts on "+gService.title+":";
// Clean the account list
while (accountList.getRowCount() > 0) {
accountList.removeItemAt(0);
}
// Populate the account list
var enum = faves_coop.accounts_root.children.enumerate();
while (enum.hasMoreElements()) {
var account = enum.getNext();
if (!account) continue; // getNext() can return NULL when hasMoreElements() is TRUE.
if (account.serviceId == aContractID) {
var accountitem = document.createElement("listitem");
var label = account.name;
if (account.service.logoutOption) {
if (account.isAuthenticated) {
label += " - logged in";
} else {
label += " - logged out";
}
} else {
label += " - configured";
}
accountitem.setAttribute('label', label);
accountitem.setAttribute('value', account.id());
accountitem.setAttribute('style', 'font-style: italic;');
accountList.appendChild(accountitem);
}
}
// Select the first account or show the login instructions
if (accountList.getRowCount() > 0) {
$('accountDeck').selectedIndex = 0;
accountList.selectedIndex = 0;
}
else {
$('accountDeck').selectedIndex = 1;
$('login-link').setAttribute('onclick', 'openUILinkIn("'+gService.url+'", "window");window.close();');
$('login-link').textContent = gService.url;
}
// update the loginDetect button
var loginDetect = getServiceConfirmation(gService.urn);
$('dont-logindetect').setAttribute('checked', !loginDetect);
}
function updateService() {
var cid = $('serviceList').selectedItem.value;
loadService(cid);
updateButtons();
}
function updateButtons() {
var noselection = ($('accountList').selectedItem == null);
$('logout-button').setAttribute('disabled', noselection);
$('forget-button').setAttribute('disabled', noselection);
if (!noselection) {
var id = $('accountList').selectedItem.value;
var account = faves_coop.get(id);
$('logout-button').setAttribute('disabled', !account.service.logoutOption);
try {
// Account selected AND service implements flockISocialWebService
gService.QueryInterface(Ci.flockISocialWebService);
$('showInSidebar-check').setAttribute('disabled', 'false');
$('showInSidebar-check').setAttribute('checked', account.showInSidebar);
}
catch(e) {
// Account selected, but service doesn't implement flockISocialWebService
$('showInSidebar-check').setAttribute('disabled', 'true');
$('showInSidebar-check').setAttribute('checked', 'false');
}
}
else {
// No account selected
$('showInSidebar-check').setAttribute('disabled', true);
$('showInSidebar-check').setAttribute('checked', false);
}
}
function forgetAccount() {
var svc = $('serviceList').selectedItem.svc;
var cid = $('serviceList').selectedItem.value;
var id = $('accountList').selectedItem.value;
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
if (prompts.confirm(window, "Forget Account", "This action will remove this account completely! Are you sure this is what you want to do?")) {
svc.getAccount(id).logout(null);
svc.removeAccount(id);
loadService(cid);
}
}
function logoutAccount() {
var svc = $('serviceList').selectedItem.svc;
var cid = $('serviceList').selectedItem.value;
var id = $('accountList').selectedItem.value;
var acct = svc.getAccount(id);
acct.logout(null);
loadService(cid);
}
function toggleShowInSidebar(aChecked) {
var id = $('accountList').selectedItem.value;
var account = faves_coop.get(id);
account.showInSidebar = aChecked;
}
function toggleLoginDetection(aChecked) {
var svc = $('serviceList').selectedItem.svc;
setServiceConfirmation(svc.urn, !aChecked);
}
var getFlockWebServices = function() {
var CATMAN = Cc['@mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager);
var webServices = new Array();
var e = CATMAN.enumerateCategory('flockWebService');
while (e.hasMoreElements()) {
try {
var entry = e.getNext().QueryInterface(Ci.nsISupportsCString);
if (!entry) { continue; }
var contractID = CATMAN.getCategoryEntry('flockWebService', entry.data);
var svc = Cc[contractID].getService(Ci.flockIWebService);
webServices.push([contractID, svc]);
} catch (e) {
dump(e);
}
}
dump('Found '+webServices.length+' flock web services');
return webServices;
}
PK
'$7sy y * content/flock/common/accountManagement.xul
%flockAccountDTD;
]>
PK
6tR( ! content/flock/common/aggregate.js/*
BEGIN FLOCK GPL
Copyright Flock Inc. 2005-2007
http://flock.com
This file may be used under the terms of of the
GNU General Public License Version 2 or later (the "GPL"),
http://www.gnu.org/licenses/gpl.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
END FLOCK GPL
*/
/* in this world, a stream is a generator */
var PQ = function(compare) {
this.compare = compare;
this.data = new Array();
this.size = 0;
}
PQ.prototype.down = function(parent) {
var element = this.data[parent];
var child = parent<<1;
while (child <= this.size) {
if ((child < this.size) &&
(this.compare(this.data[child+1],this.data[child]) > 0)) child++
if (this.compare(element, this.data[child]) < 0) {
this.data[parent] = this.data[child];
parent = child;
child = parent<<1;
} else break;
}
this.data[parent] = element;
}
PQ.prototype.up = function(child) {
var element = this.data[child];
var parent = child>>1;
while (parent >= 1) {
if (this.compare(this.data[parent], element) < 0) {
this.data[child] = this.data[parent];
child = parent;
parent = child>>1;
} else break;
}
this.data[child] = element;
}
PQ.prototype.push = function(val) {
this.size++;
this.data[this.size] = val;
this.up(this.size)
}
PQ.prototype.pop = function() {
var val = this.data[1];
this.data[1] = this.data[this.size];
this.size--;
this.down(1)
this.data.pop()
return val;
}
function filterStream (stream, filter) {
var next = null;
function fillNext () {
while (stream.hasMoreElements ()) {
var item = stream.getNext ();
if (!filter (item)) {
continue;
}
next = item;
return;
}
next = null;
}
return {
hasMoreElements: function filterStream_hasMoreElements () {
if (next) return true;
fillNext ();
return (next != null);
},
getNext: function filterStream_getNext () {
if (!next) {
fillNext ();
}
var r = next;
next = null;
return r;
}
}
}
function groupAggStreams( rdfStreamNodes, faves_coop ) {
// this function creates two aggregations aggSeen, aggUnseen
// filtering unseen and seen respectively from their output
// then wraps the aggregators so all of aggUnseen is consumed
// before aggSeen is consumed
var streamsUnseen = []; // the enumerators that will be consumed by the
// aggregator that show only the unseen items
var streamsSeen = []; // enumerators used to show seen items
for (var i in rdfStreamNodes) {
streamsUnseen[i] = faves_coop.get(rdfStreamNodes[i]).children.enumerateBackwards();
streamsSeen[i] = faves_coop.get(rdfStreamNodes[i]).children.enumerateBackwards();
}
var aggSeen = filterStream( aggregateStreams( streamsSeen ), function(item) {
return !item.unseen;
});
var aggUnseen = filterStream( aggregateStreams( streamsUnseen ), function(item) {
return item.unseen;
});
return {
hasMoreElements: function groupStream_hasMoreElements () {
return aggUnseen.hasMoreElements() || aggSeen.hasMoreElements();
},
getNext: function groupStream_getNext () {
return aggUnseen.getNext() || aggSeen.getNext();
}
}
}
function fancyPantsEnumer( node, coop ) {
const flockIStreamUtils = Components.interfaces.flockIStreamUtils;
const SU = Components.classes['@flock.com/stream-utils;1']
.createInstance(flockIStreamUtils);
var se = SU.enumerateStreams(coop.datasource, coop.get(node).resource(), true,
flockIStreamUtils.STREAMS_UNSEEN |
flockIStreamUtils.STREAMS_SEEN);
var enumerator = {
_coop: coop,
_se: se,
getNext: function() {
var n = this._se.getNext();
return this._coop.get_from_resource(n);
},
hasMoreElements: function() {
return this._se.hasMoreElements();
}
};
return enumerator;
}
function aggStreams( rdfStreamNodes, faves_coop ) {
var streams = [];
for (var i in rdfStreamNodes) {
streams[i] = fancyPantsEnumer( rdfStreamNodes[i], faves_coop );
}
return aggregateStreams(streams);
}
function aggregateStreams (streams) {
var myFunc = function (x,y) { return x.element.datevalue - y.element.datevalue; };
return customAggregateStreams(myFunc, streams);
}
function aggregatePhotoStreams (streams) {
// var myFunc = function (x,y) { return x.element.id - y.element.id; };
// return customAggregateStreams(myFunc, streams);
return aggregateStreams(streams);
}
function customAggregateStreams (myFunc, streams) {
var pq = new PQ (myFunc);
// initialize the priority queue
for (var i in streams) {
if (!streams[i].hasMoreElements ()) {
continue;
}
pq.push ({element: streams[i].getNext(), stream: streams[i]});
}
// return an enumerator
return {
hasMoreElements: function aggregateStreams_hasMoreElements () {
return pq.size > 0;
},
getNext: function aggregateStreams_getNext () {
// get the next item
var item = pq.pop();
if (!item) {
// the queue is empty
return null;
}
if (item.stream.hasMoreElements ()) {
// add the next item from that stream to the queue
pq.push ({element: item.stream.getNext(), stream: item.stream});
}
// return our element
return item.element;
}
}
}
// streamWalker walks the RDF graph collecting a list of streams
// it starts at a node, and recurses adding items with rdf type
// "livemarks"
function streamWalker(aDataSource, aNode) {
const RDFS = Components.classes['@mozilla.org/rdf/rdf-service;1']
.getService(Components.interfaces.nsIRDFService);
const RDFCU = Components.classes['@mozilla.org/rdf/container-utils;1']
.getService(Components.interfaces.nsIRDFContainerUtils);
const RDF_TYPE = RDFS.GetResource('http://www.w3.org/1999/02/22-rdf-syntax-ns#type');
const RDF_LIVEMARK = RDFS.GetResource('http://home.netscape.com/NC-rdf#Livemark'); // rdf type livemark == flock stream
var streams = {}; // streams contained within aNode (using a hash to remove duplicates)
var queue = [aNode]; // removing tail recursion using a queue
while (queue.length > 0) {
aNode = queue.pop();
aNode.QueryInterface( Components.interfaces.nsIRDFResource );
if (aDataSource.HasAssertion( aNode, RDF_TYPE, RDF_LIVEMARK, true )) {
streams[ aNode.ValueUTF8 ] = 1;
} else {
// sequences that aren't livemarks should be recursed into
// (eg, streams inside folders/people/containers should be added)
if (RDFCU.IsSeq (aDataSource, aNode)) {
try {
var children = RDFCU.MakeSeq( aDataSource, aNode ).GetElements();
while (children && children.hasMoreElements()) {
child = children.getNext();
queue.push( child );
}
} catch (e) {}
}
}
}
return [i for (i in streams)]; // wonder if this javascript 1.7 feature works?
}
PK
6+7yq q content/flock/common/coop.js// vim: ts=2 sw=2 expandtab ai
//
// BEGIN FLOCK GPL
//
// Copyright Flock Inc. 2005-2007
// http://flock.com
//
// This file may be used under the terms of of the
// GNU General Public License Version 2 or later (the "GPL"),
// http://www.gnu.org/licenses/gpl.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// END FLOCK GPL
//
// Ian's second Object RDF Mapping
// look at cooptest.js
// TODO:
// * lazy loading of properties (with caching)
// * too much is done in ctor - it should be more static - things put into
// the protototype.
// * real exception class, not strings
const CC = Components.classes;
const CI = Components.interfaces;
const IOS = CC["@mozilla.org/network/io-service;1"]
.getService(CI.nsIIOService);
const RDFS = CC["@mozilla.org/rdf/rdf-service;1"]
.getService(CI.nsIRDFService);
const RDFCU = CC["@mozilla.org/rdf/container-utils;1"]
.getService(CI.nsIRDFContainerUtils);
const RDF_TYPE = RDFS.GetResource("http://flock.com/rdf#CoopType");
/*
var coop_logger = CC["@flock.com/logger;1"].createInstance(CI.flockILogger);
coop_logger.init("coop");
*/
function CoopType(aORM, aType, aFields, aFieldTypes, aFieldDefaults, aFieldMultiple, aContainer, aContainerName) {
this.mORM = aORM;
this.mType = aType;
this.mTypeResource = RDFS.GetResource(aType);
this.fields = aFields;
this.field_types = aFieldTypes;
this.field_defaults = aFieldDefaults;
this.field_multiple = aFieldMultiple;
this.container = aContainer;
this.container_name = aContainerName;
this.baseClasses = [];
this.destroyNotifiers = [];
var ormtype = this;
function init_instance(type, instance, uri, field_values, resource) {
if (!uri) {
var get_id = type.mORM.mTypes[type.mType].ctor.get_id;
if (get_id && field_values) {
uri = get_id(field_values);
}
if (!uri) {
uri = RDFS.GetAnonymousResource().ValueUTF8;
}
}
if (!resource)
resource = RDFS.GetResource(uri);
if (type.container) {
var container = null;
// initialise the container
if (type.container &&
!RDFCU.IsContainer(type.mORM.datasource, resource)) {
switch (type.container) {
case 'Seq':
RDFCU.MakeSeq(type.mORM.datasource, resource);
break;
case 'Bag':
RDFCU.MakeBag(type.mORM.datasource, resource);
break;
case 'Alt':
RDFCU.MakeAlt(type.mORM.datasource, resource);
break;
default:
throw 'invalid container type';
break;
}
}
// provide an API
function container_enumerator() { }
container_enumerator.init_container = function() {
container = CC["@mozilla.org/rdf/container;1"]
.createInstance(CI.flockIRDFContainer);
container.Init(type.mORM.datasource, resource);
}
container_enumerator.count = function() {
if (!container) this.init_container();
return container.GetCount();
}
container_enumerator.add = function container_enum_add(child) {
if (!container) this.init_container();
if (instance.onBeforeAdd) instance.onBeforeAdd(child);
try {
container.AppendElement(child.__Coop_resource);
} catch (ex) {
dump("Coop: "+ex+"\n");
}
if (instance.onAdd) instance.onAdd(child);
}
container_enumerator.insertAt = function container_enum_insertAt(child, position) {
if (!container) this.init_container();
// /!\ the first element is 1, not 0 /!\
try {
// coop_logger.info("Insert "+child.__Coop_uri+" at position "+position);
container.InsertElementAt(child.__Coop_resource, position, true);
} catch(ex) {
// coop_logger.error(ex);
dump("Coop: "+ex+"\n");
}
}
container_enumerator.remove = function container_enum_remove(child) {
if (!container) this.init_container();
if (instance.onBeforeRemove) instance.onBeforeRemove();
container.RemoveElement(child.__Coop_resource, false);
if (instance.onRemove) instance.onRemove();
}
container_enumerator.enumerate = function container_enum_enumerate() {
if (!container) this.init_container();
var enumerator = {
hasMoreElements: function container_enum_hasMoreElements() {
return this.elements.hasMoreElements();
},
getNext: function container_enum_getNext() {
var el = this.elements.getNext();
el.QueryInterface(CI.nsIRDFResource);
return type.mORM.get_from_resource(el);
}
}
enumerator.elements = container.GetElements();
return enumerator;
}
container_enumerator.enumerateBackwards = function container_enum_enumBackwards() {
if (!container) this.init_container();
var enumerator = {
hasMoreElements: function container_backEnum_hasMoreElements() {
return this.elements.hasMoreElements();
},
getNext: function container_backEnum_getNext() {
var el = this.elements.getNext();
el.QueryInterface(CI.nsIRDFResource);
return type.mORM.get_from_resource(el);
}
}
enumerator.elements = container.GetElementsBackwards();
return enumerator;
}
container_enumerator.indexOf = function container_enum_indexOf(child) {
if (!container) this.init_container();
return container.IndexOf(child.__Coop_resource);
}
container_enumerator.has = function container_enum_has(child) {
if (!container) this.init_container();
return container.IndexOf(child.__Coop_resource) >= 0;
}
container_enumerator.addOnce = function container_enum_addOnce(child) {
if (!container) this.init_container();
if (this.indexOf(child) < 0) this.add(child);
}
container_enumerator.empty = function container_empty() {
var myenum = this.enumerateBackwards();
while (myenum.hasMoreElements()) {
var child = myenum.getNext();
this.remove(child);
}
}
instance[type.container_name] = container_enumerator;
}
// set up the fields
function set_up_field(f) {
if (type.field_multiple[f]) {
var field_type = type.field_types[f] || Coop.string;
var field_rsrc = type.fields[f];
var field_enumerator = function field_enum_ctor() { }
if (!type.read_only) {
field_enumerator.add = function field_enum_add(child) {
type.mORM.datasource.Assert(resource, field_rsrc,
field_type.toRdf(child, type.mORM), true);
}
field_enumerator.remove = function field_enum_remove(child) {
type.mORM.datasource.Unassert(resource, field_rsrc,
field_type.toRdf(child, type.mORM));
}
field_enumerator.addOnce = function field_enum_addOnce(child) {
if (!type.mORM.datasource.HasAssertion(resource,
field_rsrc,
field_type.toRdf(child, type.mORM),
true))
{
this.add(child);
}
}
field_enumerator.has = function field_enum_has(child) {
return type.mORM.datasource.HasAssertion(resource, field_rsrc,
field_type.toRdf(child, type.mORM), true);
}
field_enumerator.removeAll = function field_enum_removeAll() {
var enum_ = this.enumerate();
while (enum_.hasMoreElements()) {
var child = enum_.getNext();
this.remove(child);
}
}
}
field_enumerator.enumerate = function field_enum_enumerate() {
var elements = type.mORM.datasource.GetTargets(resource,
field_rsrc, true);
var enumerator = {
hasMoreElements: function field_enum_hasMoreElements() {
return elements.hasMoreElements();
},
getNext: function field_enum_getNext() {
var el = elements.getNext();
return field_type.toJs(el, type.mORM);
}
}
return enumerator;
}
instance.__defineGetter__(f, function() {
return field_enumerator;
});
instance.__defineSetter__(f, function(v) {
throw "can't set multiple property: "+f+' to: '+v;
});
// FIXME: handle read-only
} else {
if (!type.read_only) {
instance.__defineSetter__(f, function instance_field_setter(v) {
type.put_field(resource, f, v);
});
} else {
instance.__defineSetter__(f, function instance_field_setter() {
throw "can't set property on read-only object";
});
}
instance.__defineGetter__(f, function instance_field_getter() {
return type.get_field(resource, f);
});
}
}
for (var f in type.fields) {
set_up_field(f);
}
// JMC - Assert the CoopType first, so that observers responding to the other
// types can perform a coop "get"
var firstTime = false;
var type_target = type.mORM.datasource.GetTarget(resource, RDF_TYPE, true);
if (!type_target) {
type.mORM.datasource.Assert(resource, RDF_TYPE, type.mTypeResource, true);
firstTime = true;
}
if (!field_values) field_values = {};
var f;
for (f in type.fields) {
if (field_values[f] && type.field_multiple[f]) {
// FIXME: initializer for a multiple field? eh?
throw 'multiple field initializer not supported yet';
}
if (field_values[f] == null) {
// Make sure default value ends up in here
if (!type_target && type.field_defaults[f] != null
&& instance[f] == null) {
instance[f] = type.field_defaults[f];
}
} else {
instance[f] = field_values[f];
}
}
if (!type.read_only) {
instance.destroy = function coop_obj_destroy() { type.destroy(uri, instance); }
}
instance.isA = function coop_obj_isA(aCoopType) { return type.isA(aCoopType); }
instance.isInstanceOf = function coop_obj_isInstanceOf(aCoopType) { return type.isInstanceOf(aCoopType); }
// fixme: shouldn't this just be a read-only field?
instance.id = function coop_obj_id() { return uri; }
instance.resource = function coop_obj_resource() { return resource; }
instance.getParent = function coop_obj_getParent() {
var arcs = type.mORM.datasource.ArcLabelsIn(resource);
while (arcs && arcs.hasMoreElements()) {
var testresource = arcs.getNext();
if (testresource && testresource.QueryInterface)
testresource = testresource.QueryInterface(CI.nsIRDFResource);
if (testresource &&
testresource.QueryInterface &&
RDFCU.IsOrdinalProperty(testresource))
{
var source = type.mORM.datasource.GetSource(testresource,
resource,
true);
source.QueryInterface(CI.nsIRDFResource);
var finalresource = type.mORM.get_from_resource(source);
return finalresource;
}
}
return null;
}
instance.getParents = function coop_obj_getParents() {
var result = [];
var arcs = type.mORM.datasource.ArcLabelsIn(resource);
while (arcs && arcs.hasMoreElements()) {
var testresource = arcs.getNext();
if (testresource && testresource.QueryInterface)
testresource = testresource.QueryInterface(CI.nsIRDFResource);
if (testresource && testresource.QueryInterface && RDFCU.IsOrdinalProperty(testresource)) {
var sources = type.mORM.datasource.GetSources(testresource, resource, true);
while (sources && sources.hasMoreElements()) {
var source = sources.getNext().QueryInterface(CI.nsIRDFResource);
var finalresource = type.mORM.get_from_resource(source);
result.push(finalresource);
}
}
}
return result;
}
instance.__Coop_uri = uri; // FIXME can't we use a closure & id()
instance.__Coop_resource = resource; // JMC - Is this bad, will we leak?
if (firstTime && instance.onCreate) instance.onCreate();
}
// JMC - Optimize for ctor getting a resource, instead of just an uri
this.ctor = function coop_obj_ctor(arg1, arg2, arg3) {
// FIXME: allow overrides at construct time
var uri, fields;
if (arg3) {
uri = arg1;
init_instance(ormtype, this, uri, fields, arg3);
return;
}
if (arg2) {
uri = arg1;
fields = arg2;
} else {
if (typeof (arg1) == 'string') {
uri = arg1;
} else {
fields = arg1;
uri = null;
}
}
// FIXME: for readonly - don't allow initial fields
init_instance(ormtype, this, uri, fields, arg3);
}
this.ctor.all_ids = function all_ids() {
// FIXME: deal with inheritance
var sources = ormtype.mORM.datasource.GetSources(RDF_TYPE, ormtype.mTypeResource, true);
var results = [];
while (sources.hasMoreElements()) {
var source = sources.getNext().QueryInterface(CI.nsIRDFResource);
results.push(source);
}
return {
hasMoreElements: function coop_obj_allIds_hasMoreElements() { return results.length > 0; },
getNext: function coop_obj_allIds_getNext() { return results.shift(); }
};
}
this.ctor.all = function all() {
// FIXME: deal with inheritance
var ids = ormtype.ctor.all_ids();
return {
hasMoreElements: function coop_obj_all_hasMoreElements() { return ids.hasMoreElements(); },
getNext: function coop_obj_all_getNext() { return ormtype.mORM.get_from_resource(ids.getNext()); }
};
}
this.ctor.find = function find(aQuery) {
// FIXME: special queries for rdfsql - faster pussycat, search! search!
// FIXME: we need to be able to order the keys to match in a query
var realResults = [];
var firstprop = true;
for (var propname in aQuery) {
var results = [];
// coop_logger.info("Coop Find: looking at property" + propname + " for value of " + aQuery[propname]);
var type = ormtype.field_types[propname] || Coop.string;
var sources = ormtype.mORM.datasource.GetSources(ormtype.fields[propname],
type.toRdf(aQuery[propname], ormtype.mORM), true);
while (sources.hasMoreElements()) {
var source = sources.getNext().QueryInterface(CI.nsIRDFResource);
if (!ormtype.mORM.datasource.HasAssertion(source, RDF_TYPE,
ormtype.mTypeResource, true)) {
continue;
}
results.push(source.ValueUTF8);
}
if (firstprop) {
realResults = results;
firstprop = false;
}
// JMC - Loop backwards through the realResults,
// if they don't exist in results, then pop them
var interSection = [];
for (var i=0 ; i < realResults.length; i++)
{
if (results.indexOf(realResults[i]) > -1)
{
interSection.push(realResults[i]);
}
}
realResults = interSection;
}
var finalResults = [];
for (var i =0; i -1) return true;
if (aCoopType.mType && this.baseClasses.indexOf(aCoopType.mType) > -1) return true;
return false;
}
function Coop(aDataSource, aSchema, aDefaultProperties) {
this.datasource = aDataSource;
this.mTypes = {};
if (aDefaultProperties) {
this.mDefaultType = new CoopType(this, 'urn:coop:internal:default',
aDefaultProperties.fields, aDefaultProperties.field_types,
aDefaultProperties.field_defaults, aDefaultProperties.field_multiple,
aDefaultProperties.container, aDefaultProperties.container_name);
} else {
this.mDefaultType = null;
}
if (aSchema) {
this.addSchema(aSchema);
}
}
Coop.prototype.addSchema = function (aSchema) {
var loader = CC["@mozilla.org/moz/jssubscript-loader;1"]
.getService(CI.mozIJSSubScriptLoader);
var context = {Coop: Coop, coop: this};
loader.loadSubScript(aSchema, context);
}
Coop.prototype.add_type = function Coop_add_type(aType, aProperties) {
var inherits_from = aProperties['inherits_from'];
if (inherits_from) {
inherits_from = this.mTypes[inherits_from];
} else if (this.mDefaultType) {
inherits_from = this.mDefaultType;
}
var k;
var fields = {};
if (inherits_from) {
for (k in inherits_from.fields) {
fields[k] = inherits_from.fields[k];
}
}
if (aProperties.fields) {
for (k in aProperties.fields) {
fields[k] = RDFS.GetResource(aProperties.fields[k]);
}
}
var field_types = {};
if (inherits_from) {
for (k in inherits_from.field_types) {
field_types[k] = inherits_from.field_types[k];
}
}
if (aProperties.field_types) {
for (k in aProperties.field_types) {
field_types[k] = aProperties.field_types[k];
}
}
var field_defaults = {};
if (inherits_from) {
for (k in inherits_from.field_defaults) {
field_defaults[k] = inherits_from.field_defaults[k];
}
}
if (aProperties.field_defaults) {
for (k in aProperties.field_defaults) {
field_defaults[k] = aProperties.field_defaults[k];
}
}
var field_multiple = {};
if (inherits_from) {
for (k in inherits_from.field_multiple) {
field_multiple[k] = inherits_from.field_multiple[k];
}
}
if (aProperties.field_multiple) {
for (k in aProperties.field_multiple) {
field_multiple[k] = aProperties.field_multiple[k];
}
}
var container = aProperties.container ||
(inherits_from && inherits_from.container);
var container_name = null;
if (aProperties.container_name) {
container_name = aProperties.container_name;
} else if (inherits_from && inherits_from.container_name) {
container_name = inherits_from.container_name;
} else {
container_name = 'children';
}
/*
var constructor = null;
if (aProperties.constructor) {
constructor = aProperties.constructor;
} else if (inherits_from && inherits_from.constructor) {
constructor = inherits_from.constructor;
}
*/
this.mTypes[aType] =
new CoopType(this, aType,
fields, field_types, field_defaults, field_multiple,
container, container_name);
// JMC - Move this into the ctor with everything else
if (aProperties['inherits_from']) {
this.mTypes[aType].baseClasses.push(aProperties['inherits_from']);
for (basetype in inherits_from.baseClasses) {
this.mTypes[aType].baseClasses.push(inherits_from.baseClasses[basetype]);
}
}
return this.mTypes[aType].ctor;
}
Coop.prototype.get_from_resource = function Coop_get_from_resource(aResource) {
var type_target = this.datasource.GetTarget(aResource, RDF_TYPE, true);
// coop_logger.debug('get_from_resource: aResource = '+aResource.ValueUTF8);
if (!type_target) return null;
// coop_logger.debug('get_from_resource: type_target = '+type_target.ValueUTF8);
aResource.QueryInterface(CI.nsIRDFResource);
return new this.mTypes[type_target.ValueUTF8].ctor(aResource.ValueUTF8, null, aResource);
}
Coop.prototype.get = function Coop_get(aURI) {
try {
if (!aURI) {
return null;
}
return this.get_from_resource(RDFS.GetResource(aURI));
} catch (ex) {
dump("COOP Died trying to get " + aURI + "\n" + ex + "\n");
return null;
}
}
// standard types
INVALID_XML_CHARACTERS = /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD]/g;
Coop.string = {
toJs: function string_toJS(node, orm) {
return node.QueryInterface(CI.nsIRDFLiteral).Value;
},
toRdf: function string_toRdf(value, orm) {
try {
if (value == null) value = "";
value = value.toString(); // force it to a string
return RDFS.GetLiteral(value.replace(INVALID_XML_CHARACTERS, ''));
} catch (ex) {
// coop_logger.error(ex);
dump("Coop: "+ex+"\n");
return null;
}
}
}
Coop.resource = {
toJs: function resource_toJS(node, orm) {
return node.QueryInterface(CI.nsIRDFResource).ValueUTF8;
},
toRdf: function resource_toRdf(value, orm) {
return RDFS.GetResource(value);
}
}
Coop.date = {
toJs: function date_toJs(node, orm) {
return new Date(node.QueryInterface(CI.nsIRDFDate).Value / 1000);
},
// FIXME: I should not need this 1000* here, but for some reason I get the wrong date
// without it
toRdf: function date_toRdf(value, orm) {
return RDFS.GetDateLiteral(1000 * value.getTime());
}
}
Coop.boolean = {
toJs: function boolean_toJs(node, orm) {
return (node.QueryInterface(CI.nsIRDFLiteral).Value == "true");
},
toRdf: function boolean_toRdf(value, orm) {
return RDFS.GetLiteral(value ? "true" : "false");
}
}
Coop.integer = {
toJs: function integer_toJs(node, orm) {
return node.QueryInterface(CI.nsIRDFInt).Value;
},
toRdf: function integer_toRdf(value, orm) {
return RDFS.GetIntLiteral(value);
}
}
Coop.stringinteger = {
toJs: function stringinteger_toJs(node, orm) {
return parseInt(node.QueryInterface(CI.nsIRDFLiteral).Value);
},
toRdf: function stringinteger_toRdf(value, orm) {
return RDFS.GetLiteral(value);
}
}
Coop.object = {
toJs: function object_toJs(node, orm) {
return orm.get_from_resource(node.QueryInterface(CI.nsIRDFResource));
},
toRdf: function object_toRdf(value, orm) {
return value.__Coop_resource;
}
}
// TODO: implement compare and toString
PK
vA$7> > % content/flock/common/confirmDialog.js// BEGIN FLOCK GPL
//
// Copyright Flock Inc. 2005-2007
// http://flock.com
//
// This file may be used under the terms of of the
// GNU General Public License Version 2 or later (the "GPL"),
// http://www.gnu.org/licenses/gpl.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// END FLOCK GPL
Cc = Components.classes;
Ci = Components.interfaces;
var serviceMgr = Cc["@flock.com/webservice-manager;1"].getService(Ci.flockIWebServiceManager);
var gParams;
/*
* Coop stuff
*/
var faves_coop = Cc["@flock.com/singleton;1"]
.getService(Ci.flockISingleton)
.getSingleton("chrome://flock/content/common/load-faves-coop.js")
.wrappedJSObject;
function onLoad() {
gParams = window.arguments[0].QueryInterface(Components.interfaces.nsIDialogParamBlock);
var name = gParams.GetString(0);
var icon = gParams.GetString(1);
$('favicon').setAttribute('src', icon);
$('title').setAttribute('value', 'Enable '+name+' in Flock!');
}
function onAccept() {
dump("==== We're returning "+$("result-group").value+" ===\n");
gParams.SetString(2, $("result-group").value);
return true;
}
PK
'$7iED &