Deprecated: Creation of dynamic property BrowserRequest::$method is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php on line 51
Deprecated: Creation of dynamic property BrowserRequest::$protocol is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php on line 54
Deprecated: Creation of dynamic property BrowserRequest::$request_method is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php on line 55
Deprecated: Creation of dynamic property BrowserRequest::$headers is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php on line 56
Deprecated: Creation of dynamic property BrowserRequest::$pathinfo is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php on line 18
Deprecated: Creation of dynamic property BrowserRequest::$requestUri is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php on line 19
Deprecated: Creation of dynamic property BrowserRequest::$scriptName is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php on line 20
Deprecated: Creation of dynamic property BrowserRequest::$queryString is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php on line 21
Deprecated: Creation of dynamic property BengProxyHandler::$_isInitialized is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 20
Deprecated: Creation of dynamic property BengProxyHandler::$requestUri is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 21
Deprecated: Creation of dynamic property BengProxyHandler::$curlHandle is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 22
Deprecated: Creation of dynamic property BengProxyHandler::$response is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 172
Deprecated: Creation of dynamic property BengProxyHandler::$http_response_line is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 135
Deprecated: Creation of dynamic property BengProxyHandler::$code is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 137
Deprecated: Creation of dynamic property BengProxyHandler::$body is deprecated in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 147
Warning: Cannot modify header information - headers already sent by (output started at /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php:51) in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 361
Warning: Cannot modify header information - headers already sent by (output started at /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php:51) in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 370
Warning: Cannot modify header information - headers already sent by (output started at /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php:51) in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 370
Warning: Cannot modify header information - headers already sent by (output started at /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php:51) in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 370
Warning: Cannot modify header information - headers already sent by (output started at /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php:51) in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 370
Warning: Cannot modify header information - headers already sent by (output started at /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php:51) in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 370
Warning: Cannot modify header information - headers already sent by (output started at /home/jdmcoxbk/public_html/.cm4all/include/BrowserRequest.php:51) in /home/jdmcoxbk/public_html/.cm4all/include/BengProxy.php on line 370
/**
High-Level API
*/
(function(window) {
var IMPRINT_APP_CATALOG = Ajax.Document.parse("");
var DESIGN_COLORS = ["bg_color", "alt_bg_color", "text_color", "alt_text_color"];
var MAX_WEBSITE_LINKS = 5;
/**
@namespace
@name cm4all
*/
var cm4all = (window.cm4all = window.cm4all || {});
/**
Provides instances of facebook-page configurations. The returned objects
provide a high-level view on the underlying xml-configurations.
@static
@class
@name cm4all.FacebookPageConfigurationFactory
*/
cm4all.FacebookPageConfigurationFactory = cm4all.FacebookPageConfigurationFactory ||
/**
@lends cm4all.FacebookPageConfigurationFactory#
*/
{
/**
Provides an instance of a high-level configuration object for the
facebook-page with the given id. The returned objects provide a high-level
view on the underlying xml-configurations,so you can easily manipulate
the configuration of the facebook-page without going through the
hassle of navigating within different dom trees.
@static
@param {String} [pageId=cm4all.FacebookPageConfigurationFactory.DEFAULT_PAGE]
An identifier for the facebook-page to get the configuration for.
At the moment there are 2 different facebook-pages you can use here:
- {@link cm4all.FacebookConnector.DEFAULT_PAGE}
- {@link cm4all.FacebookConnector.IMPRINT_PAGE}
@return {jQuery.Promise}
The promise is resolved with the requested {@link FacebookPageConfiguration}
*/
getFacebookPageConfiguration: function(pageId) {
var
result = jQuery.Deferred(),
appCatalogPromise,
catalogPromise,
configurationPromise,
sitetreePromise = jQuery.Deferred(),
sitetree;
switch (pageId) {
case cm4all.FacebookConnector.IMPRINT_PAGE:
configurationPromise = cm4all.FacebookConnector
.getConfiguration({
"pageType": cm4all.FacebookConnector.IMPRINT_PAGE
});
configurationPromise
.done(function(response) {
result.resolve(new FacebookPageConfiguration(pageId,
response.responseXML, IMPRINT_APP_CATALOG));
})
.fail(function() {
result.reject();
});
break;
case cm4all.FacebookConnector.DEFAULT_PAGE:
default:
configurationPromise = cm4all.FacebookConnector
.getConfiguration({
"pageType": cm4all.FacebookConnector.DEFAULT_PAGE
});
appCatalogPromise = cm4all.FacebookConnector.getAppCatalog();
catalogPromise = cm4all.FacebookConnector.getCatalog();
sitetree = new beng.site.Sitetree();
sitetree.load(function() {
sitetreePromise.resolve(sitetree);
});
jQuery.when(configurationPromise, appCatalogPromise, catalogPromise,
sitetreePromise)
.done(function(configuration, appCatalog, catalog, sitetree) {
result.resolve(new DecoratedFacebookPageConfiguration(pageId,
configuration.responseXML, appCatalog.responseXML,
catalog.responseXML, sitetree));
})
.fail(function() {
result.reject();
})
}
return result.promise();
},
/**
Get notified if someone sets a configuration property. All setters on the configuration classes
fire a jQuery custom event on the current window. This method allows you to
bind an event handler to this events. You can alternatively bind to these events
directly by {@link jQuery.bind}. The naming convention for the events is
cm4all/<class>/<setter>@<pageId>
. So if you, for example, want to be
notified each time {@link WebsitePage#setSelected} is called on the default page
(pageid = ""), the event name would be cm4all/WebsitePage/setSelected@
.
@param {String} pageId An identifier for the facebook-page to get the configuration for.
{@see cm4all.FacebookPageConfigurationFactory#getFacebookPageConfiguration}
@param {String} name
The name of the property to be notified about. The format to
identify the property is <class/setter>. So if you want for example
to be notified each time {@link WebsitePage#setSelected} is called,
the name would be WebsitePage/setSelected
@param {Function} handler
The handler-function which is invoked on occurrence of the specified event.
The first argument passed to the handler function is an event-object, the second
argument is the object on which the 'setXXX' method was invoked.
E.g. if you bound to the name WebsitePage/setSelected
you
will get the {@link WebsitePage} object on which the setSelected method was invoked.
*/
bindChangeListener: function(pageId, name, handler) {
jQuery(window).bind("cm4all/" + name + "@" + pageId, handler);
},
/**
Unbind the event-handler for the change events on setters.
@param {String} pageId An identifier for the facebook-page to get the configuration for.
{@see cm4all.FacebookPageConfigurationFactory#getFacebookPageConfiguration}
@param {String} name
The name of the property to be no longer notified about. The format to
identify the property is <class/setter>. So if you want for example
delete the listeners for {@link WebsitePage#setSelected},
the name would be WebsitePage/setSelected
@param {Function} [handler]
The handler function which was formerly bound to the event. If this parameter is omitted,
all functions bound to this event are unbound, even the ones which were bound
directly by calling jQuery.bind
*/
unbindChangeListener: function(pageId, name, handler) {
jQuery(window).unbind("cm4all/" + name + "@" + pageId, handler);
}
};
/**
Provides the configuration methods for a facbook-page without any
content except one or more apps.
@class
@name FacebookPageConfiguration
@private
*/
var FacebookPageConfiguration = Class.create(
/**
@lends FacebookPageConfiguration#
*/
{
/**
@private
*/
initialize: function(pageId, configurationXML, appCatalogXML) {
this.pageId = pageId;
this.configuration = new cm4all.DOM2JSON(configurationXML);
this.appCatalog = new cm4all.DOM2JSON(appCatalogXML);
},
/**
Checks if the current account is connected to the facebook-page.
@return {Boolean}
true if the account is connected to a facebook page
false if the account is not connected to a facebook page
*/
isConnected: function() {
var facebookId = this.configuration.$get("cm_params.main_settings.facebook_id.$");
return Boolean(facebookId);
},
/**
Get all available facebook-apps for the facebook-page.
@return {FacebookApp[]}
An array of available facebook-apps
*/
getApps: function() {
var
facebookAppsJson = [],
facebookApps = [],
i;
facebookAppsJson = this.appCatalog.$get("catalog.widget");
if (!Object.isArray(facebookAppsJson)) {
if (facebookAppsJson) {
facebookAppsJson = [facebookAppsJson];
} else {
facebookAppsJson = [];
}
}
for (i = 0; i < facebookAppsJson.length; i++) {
facebookApps.push(new FacebookApp(this, facebookAppsJson[i],
this.configuration.$get("cm_params.main_settings")));
}
return facebookApps;
},
/**
Provides a url behind which a preview of the facebook-page is available.
@return {String}
A url pointing to a preview of the facebook-page
*/
getPreviewUrl: function() {
return this.configuration.$get("cm_params.main_settings.preview_url.$");
},
/**
Makes the current state of the configuration persistent by sending
it to the facebook webservice.
@return {jQuery.Promise}
The promise is resolved with a freshly initialized {FacebookPageConfiguration}
which reflects the currently effective configuration
*/
save: function() {
var self = this;
var result = jQuery.Deferred();
var setConfiguration = cm4all.FacebookConnector
.setConfiguration({
"configurationXml": this.configuration.$dom
});
setConfiguration
.done(function() {
var getConfiguration = cm4all.FacebookPageConfigurationFactory
.getFacebookPageConfiguration(self.pageId);
getConfiguration
.done(function(facebookPageConfiguration) {
result.resolve(facebookPageConfiguration);
})
.fail(function() {
result.reject();
});
})
.fail(function() {
result.reject();
});
return result.promise();
},
/**
Reload current state of the configuration from the facebook webservice.
@return {jQuery.Promise}
The promise is resolved with a freshly initialized {@link FacebookPageConfiguration}
which reflects the currently effective configuration
*/
reload: function() {
var self = this;
var result = jQuery.Deferred();
var getConfiguration = cm4all.FacebookPageConfigurationFactory
.getFacebookPageConfiguration(self.pageId);
getConfiguration
.done(function() {
result.resolve.apply(this, arguments);
})
.fail(result.reject);
return result.promise();
}
});
/**
Provides the configuration methods for a facbook-page with some
styling, content and one or more apps.
@class
@private
@name DecoratedFacebookPageConfiguration
@augments FacebookPageConfiguration
*/
var DecoratedFacebookPageConfiguration = Class.create(FacebookPageConfiguration,
/**
@lends DecoratedFacebookPageConfiguration#
*/
{
/**
@private
*/
initialize: function($super, pageId, configurationXML, appCatalogXML,
catalogXML, sitetree) {
$super(pageId, configurationXML, appCatalogXML);
this.catalog = new cm4all.DOM2JSON(catalogXML);
this.sitetree = sitetree;
},
/**
Get all available headlines of the facebook-page
@return {Headline[]}
An array of {Headline} objects.
*/
getHeadlines: function() {
var
headlines = [],
headline;
headline = this.configuration.$get("cm_params.page_content.cm_title");
headlines.push(new Headline(this, headline));
headline = this.configuration.$get("cm_params.page_content.cm_subtitle");
headlines.push(new Headline(this, headline));
return headlines;
},
/**
Get the description text for the facebook-page
@return {String}
The description text
*/
getDescription: function() {
return this.configuration.$get("cm_params.page_content.cm_pagetext.$");
},
/**
Set the description text for the facebook-page
@param {String} description
The description text
*/
setDescription: function(description) {
this.configuration.$set("cm_params.page_content.cm_pagetext.$", description);
jQuery(window).trigger("cm4all/DecoratedFacebookPageConfiguration/setDescription@" + this.pageId, this);
},
/**
Get the text that teasers the like button on the facebook-page
@return {String}
The 'become fan' text
*/
getBecomeFanText: function() {
return this.configuration.$get("cm_params.page_content.cm_become_fan_text.$");
},
/**
Set the text that teasers the like button on the facebook-page
@param {String} becomeFanText
The 'become fan' text
*/
setBecomeFanText: function(becomeFanText) {
this.configuration.$set("cm_params.page_content.cm_become_fan_text.$",
becomeFanText);
jQuery(window).trigger("cm4all/DecoratedFacebookPageConfiguration/setBecomeFanText@" + this.pageId, this);
},
/**
Check if the fan-view is activated on the facebook-page.
The fan-view provides special content which is only avaliable if the user has
'liked' the facebook-page.
@return {Boolean}
true if there is special content for fans
false if the content for users who 'liked' the
facebook-page is the same as for users who didn't 'like' the page
*/
isFanViewActive: function() {
return this.configuration.$get("cm_params.main_settings.fangate.$") === "1";
},
/**
Set if the fan-view is activated on the facebook-page.
The fan-view provides special content which is only avaliable if the user has
'liked' the facebook-page.
@param {Boolean} [fanViewActive=true]
true A user who has 'liked' the page is presented with special content
false The content of the facebook-page is the same whether the user has
'liked' the page or not
*/
setFanViewActive: function(fanViewActive) {
this.configuration.$set("cm_params.main_settings.fangate.$",
fanViewActive === false ? "0" : "1");
jQuery(window).trigger("cm4all/DecoratedFacebookPageConfiguration/setFanViewActive@" + this.pageId, this);
},
/**
Provides a url behind which a preview of what the facebook-page looks
like if the user 'liked' the page is available.
@return {String}
A url pointing to a preview of the 'liked' facebook-page
*/
getFanViewPreviewUrl: function() {
return this.configuration.$get("cm_params.main_settings.preview_url_liked.$");
},
/**
Get the links to website pages that are available for the facebook-page
@return {WebsiteLink[]} An object to select/get a link to a
website page
*/
getWebsiteLinks: function() {
var
websiteLinks = [],
i;
var currentPages = this.configuration.$get("cm_params.page_content.pagelinks.link");
if (!Object.isArray(currentPages)) {
if (currentPages) {
currentPages = [currentPages];
} else {
currentPages = [];
}
}
for (i = 0; i < MAX_WEBSITE_LINKS; i++) {
if (!currentPages[i]) {
currentPages[i] = this.configuration.$set("cm_params.page_content.pagelinks.link[" + i + "]", {});
}
websiteLinks.push(new WebsiteLink(this, currentPages[i]));
}
return websiteLinks;
},
/**
Get the available designs for the facebook-page
@return {FacebookDesign[]}
All available designs for the facebook-page
*/
getDesigns: function() {
var
designsJson,
designs = [],
i;
designsJson = this.catalog.$get("catalog.available_page_templates.template");
if (!Object.isArray(designsJson)) {
if (designsJson) {
designsJson = [designsJson];
} else {
designsJson = [];
}
}
for (i = 0; i < designsJson.length; i++) {
designs.push(new FacebookDesign(this, designsJson[i]));
}
return designs;
}
});
/**
A simple object holding a string value
@private
@class
@name SimpleValue
*/
var SimpleValue = Class.create(
/**
@lends SimpleValue#
*/
{
name: "SimpleValue",
/**
@private
*/
initialize: function(facebookPageConfiguration, value) {
this.facebookPageConfiguration = facebookPageConfiguration;
this.value = value;
},
/**
Get the value
@return {String}
The value
*/
getValue: function() {
return this.value.$get("$");
},
/**
Set the value
@param {String} value
The value
*/
setValue: function(value) {
this.value.$set("$", value);
jQuery(window).trigger("cm4all/" + this.name + "/setValue@" + this.facebookPageConfiguration.pageId, this);
}
});
/**
A representation of a headline in the facebook-page
@private
@class
@name Headline
@augments SimpleValue
*/
var Headline = Class.create(SimpleValue,
/**
@lends Headline#
*/
{
name: "Headline"
});
/**
A representation of a color in the facebook-page
@private
@class
@name Color
@augments SimpleValue
*/
var Color = Class.create(SimpleValue,
/**
@lends Color#
*/
{
name: "Color"
});
/**
A representation of a image url in the facebook-page
@private
@class
@name ImageUrl
@augments SimpleValue
*/
var ImageUrl = Class.create(SimpleValue,
/**
@lends ImageUrl#
*/
{
name: "ImageUrl",
/**
Get the value
@return {String}
The value
*/
getValue: function() {
return this.value.$get("path.$");
},
/**
Set the value
@param {String} value
The value
*/
setValue: function(value) {
this.value.$set("path.$", value);
jQuery(window).trigger("cm4all/" + this.name + "/setValue@" + this.facebookPageConfiguration.pageId, this);
}
});
/**
A representation of a website link in the facebook-page.
@private
@class
@name WebsiteLink
*/
var WebsiteLink = Class.create(
/**
@lends WebsiteLink#
*/
{
/**
@private
*/
initialize: function(decoreatedFacebookPageConfiguration, link) {
this.decoreatedFacebookPageConfiguration = decoreatedFacebookPageConfiguration;
this.link = link;
},
/**
Get the text label for the link.
@return {String}
*/
getLabel: function() {
return this.link.$get("text.$");
},
/**
Set the text label for the link
@param {String} label
*/
setLabel: function(label) {
this.link.$set("text.$", label);
jQuery(window).trigger("cm4all/WebsiteLink/setLabel@" + this.decoreatedFacebookPageConfiguration.pageId, this);
},
/**
Get all available linkable pages
@return {WebsitePage[]}
An array of {WebsitePage} representing all website pages that
can be linked.
*/
getPages: function() {
var
pages = this.decoreatedFacebookPageConfiguration.sitetree.getPages(),
websitePages = [],
i;
for (i = 0; i < pages.length; i++) {
websitePages.push(new WebsitePage(this, pages[i]));
}
return websitePages;
},
/**
Make sure the current link element exists in the dom, create it if it doesn't exist yet
@private
*/
ensureLink: function() {
var links, i;
if (!this.link) {
links = this.decoreatedFacebookPageConfiguration.configuration.$get("cm_params.page_content.pagelinks.link");
if (!links) {
this.link = this.decoreatedFacebookPageConfiguration.configuration
.$set("cm_params.page_content.pagelinks.link", {});
} else {
i = 1;
if (Object.isArray(links)) {
i = links.length;
}
this.link = this.decoreatedFacebookPageConfiguration.configuration
.$set("cm_params.page_content.pagelinks.link[" + i + "]", {});
}
}
}
});
/**
A representation of a single webpage.
@private
@class
@name WebsitePage
*/
var WebsitePage = Class.create(
/**
@lends WebsitePage#
*/
{
/**
@private
*/
initialize: function(websiteLink, page) {
this.websiteLink = websiteLink;
this.page = page;
},
/**
Get the navigation level this page belongs to starting from level 0
(top-level navigation)
@return {Number}
The navigation level of this webpage
*/
getLevel: function() {
return this.page.getDepth();
},
/**
Get the label (the navigation text) for this page
@return {String}
The label (navigation text)
*/
getLabel: function() {
return this.page.getNavigationText();
},
/**
Check if the page is selected for the {@link WebsiteLink} this object
belongs to.
@return {Boolean}
true The page is selected for the current link.
false The page is not selected for the current link.
*/
isSelected: function() {
return (this.websiteLink.link.$get("page_id.$") === this.page.getPageId());
},
/**
Select a page to be linked to by the {@link WebsiteLink} this object
belongs to.
@param {Boolean} [selected=true]
true The page is selected for the current link.
false The page is not selected for the current link.
*/
setSelected: function(selected) {
this.websiteLink.ensureLink();
if (selected !== false) {
this.websiteLink.link.$set("page_id.$", this.page.getPageId());
this.websiteLink.link.$set("href.$",
beng.editor.editorNG.getProvisioningData().provisioning
.viewUrl + "/page.php/" + this.page.getPageId());
} else {
this.websiteLink.link.$set("page_id", null);
this.websiteLink.link.$set("href", null);
}
jQuery(window).trigger("cm4all/WebsitePage/setSelected@" + this.websiteLink.pageId, this);
}
});
/**
A representation of a facebook-app (a.k.a. widget) that can be included in a facebook-page
@private
@class
@name FacebookApp
*/
var FacebookApp = Class.create(
/**
@lends FacebookApp#
*/
{
/**
@private
*/
initialize: function(facebookPageConfig, appConfig, settingsConfig) {
this.facebookPageConfig = facebookPageConfig;
this.appConfig = appConfig;
this.settingsConfig = settingsConfig;
},
/**
Get the url pointing to a thumbnail representing this app for display
in a selection mechanism.
@return {String}
The url of a thumbnail for this app
*/
getThumbnailUrl: function() {
var wcid = this.appConfig.$get("@wcid");
var descriptor = beng.WidgetManager.getDescriptor(wcid);
return "/.cm4all/widgetres/" + wcid + "/" + descriptor.thumbnail;
},
/**
Get a label (a human readable name) for this app.
@return {String}
A human readable name for this app
*/
getLabel: function() {
return this.appConfig.$get("@title");
},
/**
Get a short description of this app suitable for explaining to
the user what this app actually does.
@return {String}
A short description for this app
*/
getDescription: function() {
return this.appConfig.$get("description.$");
},
/**
Check if this app is to be used in the facebook-page.
@return {Boolean}
true The app will be part of the content of this facebook-page.
false The app is not used in this facebook-page.
*/
isSelected: function() {
return this.settingsConfig.$get("app_element.@wcid") ===
this.appConfig.$get("@wcid");
},
/**
Set this app to be used in the facebook-page
@param {Boolean} [selected=true]
true The app will be part of the content of this facebook-page.
false The app is not used in this facebook-page.
*/
setSelected: function(selected) {
if (selected !== false) {
this.settingsConfig.$set("app_element.@wcid", this.appConfig.$get("@wcid"));
} else {
this.settingsConfig.$set("app_element.@wcid", null);
}
jQuery(window).trigger("cm4all/FacebookApp/setSelected@" + this.facebookPageConfig.pageId, this);
},
/**
Get the {@link beng.WidgetInstance} that is providing this app.
@return {jQuery.Promise}
The {jQuery.Promise} is resolved with an instance of {@link beng.WidgetInstance}
*/
getWidgetInstance: function() {
var result = jQuery.Deferred();
var wcid = this.appConfig.$get("@wcid");
var accountId = this.settingsConfig.$get("account_id.$");
beng.WidgetManager
.loadInstances(wcid, function(widgets) {
if (widgets.length > 0) {
result.resolve(widgets[0]);
} else {
beng.WidgetManager.create(wcid, {
initParams: {
"account_id": accountId
},
queryParams: {
"documentId": EXTERNAL
},
onSuccess: function(widget) {
result.resolve(widget);
},
onError: function() {
result.reject();
}
});
}
});
return result.promise();
}
});
/**
A representation of a design for the facebook-page.
@private
@class
@name FacebookDesign
*/
var FacebookDesign = Class.create(
/**
@lends FacebookDesign#
*/
{
/**
@private
*/
initialize: function(decoratedFacebookConfig, design) {
this.decoratedFacebookConfig = decoratedFacebookConfig;
this.design = design;
},
/**
Get the url pointing to a thumbnail representing this design for display
in a selection mechanism.
@return {String}
The url of a thumbnail for this design.
*/
getThumbnailUrl: function() {
return this.design.$get("template_icon.$");
},
/**
Get a label (a human readable name) for this design.
@return {String}
A human readable name for this design.
*/
getLabel: function() {
return this.design.$get("template_name.$");
},
/**
Check if this design is to be used for the facebook-page.
@return {Boolean}
true The design will be used for this facebook-page.
false The design will not be used for this facebook-page.
*/
isSelected: function() {
return (this.design.$get("template_id.$") ===
this.decoratedFacebookConfig.configuration
.$get("cm_params.main_settings.template_id.$"));
},
/**
Set if this design is to be used for the facebook-page.
@param {Boolean} [selected=true]
true The design will be used for this facebook-page.
false The design will not be used for this facebook-page.
*/
setSelected: function(selected) {
selected = selected !== false;
this.decoratedFacebookConfig.configuration
.$set("cm_params.main_settings.template_id.$",
selected ? this.design.$get("template_id.$") : "");
jQuery(window).trigger("cm4all/FacebookDesign/setSelected@" + this.decoratedFacebookConfig.pageId, this);
},
/**
Get the configurable colors for this design.
@return {Color[]}
A list of colors that can be changed in this design.
*/
getColors: function() {
var
designColors = this.design.$get("options.colors"),
userColors = this.decoratedFacebookConfig.configuration
.$get("cm_params.page_content.colors"),
colors = [],
color,
i;
for (i = 0; i < DESIGN_COLORS.length; i++) {
if (designColors) {
color = designColors.$get(DESIGN_COLORS[i]);
}
if (color) {
color = userColors.$get(DESIGN_COLORS[i]) || color;
colors.push(new Color(this.decoratedFacebookConfig, color))
}
}
return colors;
},
/**
Get the configurable images for this design.
@return {ImageUrl[]}
A list of images that can be changed in this design.
*/
getImageUrls: function() {
var
maxImages = Number(this.design.$get("options.images.max_image_count.$")),
userImages = this.decoratedFacebookConfig.configuration
.$get("cm_params.page_content.images.img"),
images = [],
i;
if (!Object.isArray(userImages)) {
if (userImages) {
userImages = [userImages];
} else {
userImages = [];
}
}
for (i = 0; i < maxImages; i++) {
if (!userImages[i]) {
userImages[i] = this.decoratedFacebookConfig.configuration
.$set("cm_params.page_content.images.img[" + i + "]", {});
}
images.push(new ImageUrl(this.decoratedFacebookConfig, userImages[i]));
}
return images;
}
});
})(window);
/**
Low-Level API
*/
(function(window) {
var CONFIGURATION_URL = "?subaction=configure";
var CONNECT_WINDOW_DIMENSIONS = "width=550,height=360";
var commonWidget;
var facebookPageFinishUrl;
var facebookAppRegistryUrl;
var facebookAppRegistryUrlStatic;
var getTextContent = function(element) {
if (!element) {
return;
}
return (typeof element.textContent === "undefined") ? element.text : element.textContent;
};
var cm4all = (window.cm4all = window.cm4all || {});
/**
@static
@class
@name cm4all.FacebookConnector
*/
cm4all.FacebookConnector = cm4all.FacebookConnector || {
/**
@lends cm4all.FacebookConnector#
*/
/**
@static
@constant
*/
IMPRINT_PAGE: "_imprint",
/**
@static
@constant
*/
DEFAULT_PAGE: "",
/**
@static
@constant
*/
ERROR_PREMATURE_CLOSE: -1,
/**
@static
@constant
*/
ERROR_CANNOT_GET_CONNECTURL: -2,
/**
Initializes the FacbookConnector with instance-specific
values. This must not be called manually, since it is
automatically called by the widget include itself.
@static
@param {Object} bengProxyOptions
@param {String}
bengProxyOptions.base
@param {String}
bengProxyOptions.session
@param {String}
bengProxyOptions.frame
@param {String}
bengProxyOptions.path
@param {Object} options
@param {String}
options.facebookPageFinishUrl
@param {String}
options.facebookAppRegistryUrl
@param {Boolean}
options.facebookAppRegistryUrlStatic
*/
init: function(bengProxyOptions, options) {
window.cm4all.FacebookConnector.init = Prototype.emptyFunction;
/*
guard
against
double
initialization
*/
commonWidget = new Common.Widget(Object.extend({
"classId": "cm4all.com.widgets.FacebookPage"
}, bengProxyOptions));
facebookPageFinishUrl = options.facebookPageFinishUrl;
facebookAppRegistryUrl = options.facebookAppRegistryUrl;
facebookAppRegistryUrlStatic = options.facebookAppRegistryUrlStatic;
},
/**
@description Opens the 'Connect to facebook' dialog
@param {Object} options
@param {Function}
options.onSuccess Callback function to be called if the
connection to facebook was successful
@param {Function}
options.onError Callback function to be called if the
connection to facebook was not successful
@param {Object} requestParameter
Additional request parameter for the API call
@param {String} [requestParameter.perm_type]
the permission type to connect to.
Currently possible values:
- not set : The default facebook-page connect dialog
imprint : The imprint connect dialog
@return {jQuery.Promise}
The {jQuery.Promise} is resolved without any data.
The {jQuery.Promise} is rejected with an error code as first
parameter.
*/
connect: function(options) {
options = options || {};
var result = jQuery.Deferred();
var txnid = "fbw" + String((new Date().getTime() / 10000) + Math.random()).replace(/\./, "");
var popupWindow = window.open("about:blank", "cm4allfacebookpageconnect", CONNECT_WINDOW_DIMENSIONS);
jQuery(window).bind("beforeunload", function() {
popupWindow.close();
});
popupWindow.focus();
var params = {
"type": "get_permissions_dialog_url"
};
Object.extend(params, options.requestParameter)
var timeout = window.setTimeout(function() {
if (popupWindow.closed) {
if (jQuery(window).data(txnid)) {
jQuery(window).removeData(txnid);
result.reject(cm4all.FacebookConnector.ERROR_PREMATURE_CLOSE);
options.onError.call(window, cm4all.FacebookConnector.ERROR_PREMATURE_CLOSE);
}
} else {
timeout = window.setTimeout(arguments.callee, 1000);
}
}, 1000);
jQuery(window).data(txnid, function(exit) {
jQuery(window).removeData(txnid);
/*
function is called from facebook-finish-page.html with exit
code as parameter
*/
if (exit === 0) {
if (options.onSuccess) {
result.resolve();
options.onSuccess.call(window);
}
} else {
result.reject(exit);
if (options.onError) {
options.onError.call(window, exit);
}
}
});
params["finish_url"] = window.location.href.replace(/^(.*\/\/[^\/]*[\/]?).*/, "$1" + facebookPageFinishUrl + "?txnid=" + txnid);
commonWidget.doRequest(CONFIGURATION_URL, {
"method": "POST",
"onSuccess": function(response) {
var isOk = response.responseXML.getElementsByTagName("state"),
url, args = arguments;
if (isOk.length > 0 && getTextContent(isOk[0]) === "ok") {
url = response.responseXML.getElementsByTagName("msg");
if (url.length > 0) {
popupWindow.document.location.href = getTextContent(url[0]) + (new RegExp("\\?").test(getTextContent(url[0])) ? "&" : "?") + "locale=" + getTopWindow().locale;
return;
}
}
window.clearTimeout(timeout);
popupWindow.close();
result.reject(ERROR_CANNOT_GET_CONNECTURL, response);
if (options.onError) {
options.onError.apply(window, args);
}
},
"onFailure": function(response) {
var args = arguments;
window.clearTimeout(timeout);
popupWindow.close();
if (options.onError) {
result.reject(ERROR_CANNOT_GET_CONNECTURL, response);
options.onError.apply(window, args);
}
}
}, params);
return result.promise();
},
/**
Returns the current configuration xml as provided by the
facebook-page webservice
@param {Function}
options.onSuccess Callback function to be called if the
connection to the facebook-page webservice was successful.
The arguments of the function are the ones provided by the
prototype.js Ajax.Response
@param {Function}
options.onError Callback function to be called if the
connection to the facebook-page webservice was was not
successful The arguments of the function are the ones
provided by the prototype.js Ajax.Response
@return {jQuery.Promise}
The {jQuery.Promise} is resolved with the parameters returned by
{Common.Widget#doRequest} in case of success
The {jQuery.Promise} is rejected with the parameters returned by
{Common.Widget#doRequest} in case of failure
*/
getConfiguration: function(options) {
options = options || {};
options.pageType = options.pageType || this.DEFAULT_PAGE
var result = jQuery.Deferred();
var params = {
"type": "pull" + options.pageType
};
commonWidget.doRequest(CONFIGURATION_URL, {
"method": "POST",
"onSuccess": function(response) {
result.resolve(response);
if (options.onSuccess) {
options.onSuccess.apply(this, arguments);
}
},
"onFailure": function(response) {
result.reject(response);
if (options.onError) {
options.onError.apply(this, arguments);
}
}
}, params);
return result.promise();
},
/**
Sends the configuration xml to the facebook-page
webservice
@param {Object} options
@param {Function}
options.configurationXml The configuration document to
send to the facebook-page webservce
@param {Function}
options.onSuccess Callback function to be called if the
connection to the facebook-page webservice was successful.
The arguments of the function are the ones provided by the
prototype.js Ajax.Response
@param {Function}
options.onError Callback function to be called if the
connection to the facebook-page webservice was was not
successful The arguments of the function are the ones
provided by the prototype.js Ajax.Response
@return {jQuery.Promise}
The {jQuery.Promise} is resolved with the parameters returned by
{Common.Widget#doRequest} in case of success
The {jQuery.Promise} is rejected with the parameters returned by
{Common.Widget#doRequest} in case of failure
*/
setConfiguration: function(options) {
options = options || {};
options.pageType = options.pageType || this.DEFAULT_PAGE
var result = jQuery.Deferred();
var params = {
"type": "push" + options.pageType
};
params["data"] = options.configurationXml;
commonWidget.doRequest(CONFIGURATION_URL, {
"method": "POST",
"contentType": "application/x-www-form-urlencoded",
"encoding": "utf-8",
"onSuccess": function(response) {
result.resolve(response);
if (options.onSuccess) {
options.onSuccess.apply(this, arguments);
}
},
"onFailure": function(response) {
result.reject(response);
if (options.onError) {
options.onError.apply(this, arguments);
}
}
}, params);
return result.promise();
},
/**
Returns the current catalog xml as provided by the
facebook-page webservice. the catalog xml contains
information about the available facebook-design templates
@param {Function}
options.onSuccess Callback function to be called if the
connection to the facebook-page webservice was successful.
The arguments of the function are the ones provided by the
prototype.js Ajax.Response
@param {Function}
options.onError Callback function to be called if the
connection to the facebook-page webservice was was not
successful The arguments of the function are the ones
provided by the prototype.js Ajax.Response
@return {jQuery.Promise}
The {jQuery.Promise} is resolved with the parameters returned by
{Common.Widget#doRequest} in case of success
The {jQuery.Promise} is rejected with the parameters returned by
{Common.Widget#doRequest} in case of failure
*/
getCatalog: function(options) {
options = options || {};
var result = jQuery.Deferred();
var params = {
"type": "show_catalog"
};
commonWidget.doRequest(CONFIGURATION_URL, {
"method": "POST",
"onSuccess": function(response) {
result.resolve(response);
if (options.onSuccess) {
options.onSuccess.apply(this, arguments);
}
},
"onFailure": function(response) {
result.reject(response);
if (options.onError) {
options.onError.apply(this, arguments);
}
}
}, params);
return result.promise();
},
/**
Returns the current app-catalog xml. the catalog xml contains
information about the available facebook-apps
@param {Function}
options.onSuccess Callback function to be called if the
connection to the service was successful.
The arguments of the function are the ones provided by the
prototype.js Ajax.Response
@param {Function}
options.onError Callback function to be called if the
connection to the service was was not
successful The arguments of the function are the ones
provided by the prototype.js Ajax.Response
@return {jQuery.Promise}
The {jQuery.Promise} is resolved with the parameters returned by
{Common.Widget#doRequest} in case of success
The {jQuery.Promise} is rejected with the parameters returned by
{Common.Widget#doRequest} in case of failure
*/
getAppCatalog: function(options) {
options = options || {};
var result = jQuery.Deferred();
var url = facebookAppRegistryUrlStatic ? facebookAppRegistryUrl : createBengRequestUrl(facebookAppRegistryUrl, {
"content-type": "text/xml"
}, {}, {});
new Ajax.Request(url, {
"method": "GET",
"onSuccess": function(response) {
result.resolve(response);
if (options.onSuccess) {
options.onSuccess.apply(this, arguments);
}
},
"onFailure": function(response) {
result.reject(response);
if (options.onError) {
options.onError.apply(this, arguments);
}
},
"_skip_error_handling": true
});
return result.promise();
},
/**
Returns the url of the facebook-page
@param {Object} options
@param {Function}
options.onSuccess Callback function to be called if the
connection to the facebook-page webservice was successful.
The arguments of the function is the url provided by the
webservice
@param {Function}
options.onError Callback function to be called if the
connection to the facebook-page webservice was was not
successful The arguments of the function are the ones
provided by the prototype.js Ajax.Response
@return {jQuery.Promise}
The {jQuery.Promise} is resolved with the parameters returned by
{Common.Widget#doRequest} in case of success
The {jQuery.Promise} is rejected with the parameters returned by
{Common.Widget#doRequest} in case of failure
*/
getPageUrl: function(options) {
options = options || {};
var result = jQuery.Deferred();
var params = {
"type": "get_facebook_page_url"
};
commonWidget.doRequest(CONFIGURATION_URL, {
"method": "POST",
"onSuccess": function(response) {
var xml = response.responseXML,
state, url, text;
if (xml) {
state = xml.getElementsByTagName("state");
if (state && state.length > 0 && getTextContent(state[0]) === "ok") {
url = xml.getElementsByTagName("msg");
if (url && url.length > 0) {
text = getTextContent(url[0]);
result.resolve(text)
options.onSuccess(text);
return;
}
}
}
result.reject(response);
if (options.onError) {
options.onError.apply(this, arguments);
}
},
"onFailure": function(response) {
result.reject(response);
if (options.onError) {
options.onError.apply(this, arguments);
}
}
}, params);
return result.promise();
}
};
})(window);