Permalink
Browse files

implementation of the server config error check and the error popup c…

…lient side
  • Loading branch information...
1 parent 30f3a94 commit cd6a3e549b3f9ebaa55b602f1957c15af1e870e5 @kerphi committed Oct 25, 2012
Showing with 71 additions and 24 deletions.
  1. +2 −0 README.md
  2. +2 −2 check.php
  3. +57 −22 client/jquery.phpfreechat.init.js
  4. +10 −0 client/jquery.phpfreechat.js
View
@@ -100,6 +100,8 @@ or this code for `carbon` theme:
* `loaded` [Function:null]: a callback executed when pfc's interface is totaly loaded
* `loadTestData` [Bool:false]: used for unit tests. It load test data into the interface.
* `use_post_wrapper` [Bool:true]: used to wrap PUT and DELETE http methods by special POST http methods (useful with a badly configured server)
+* `check_server_config` [Bool:true]: when true, the first AJAX request is used to verify that server config is ok and display errors in a popup
+
Client side parameters can be given to phpfreechat client side jquery plugin as a javascript object.
View
@@ -6,8 +6,8 @@
$status = array();
// check that server/data/ folder is writable
-if (!is_writable(dirname(__FILE__).'/data/')) {
- $status[] = basename(dirname(dirname(__FILE__))).'/server/data/ folder is not writable by your Web server. Please adjust folder permissions to 777.';
+if (!is_writable(dirname(__FILE__).'/server/data/')) {
+ $status[] = basename(dirname(__FILE__)).'/server/data/ folder is not writable by your Web server. Please adjust folder permissions to 777.';
}
// check that php version dependency is respected
@@ -31,32 +31,56 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
pfc.loadHTML();
pfc.loadResponsiveBehavior();
- // try to authenticate
- //pfc.logout(function (err) { pfc.login(); });
- pfc.login();
+ if (pfc.options.check_server_config) {
+ $.ajax({
+ type: 'GET',
+ url: pfc.options.serverCheckUrl
+ }).done(function (errors) {
+ if (errors && errors.length > 0) {
+ pfc.showErrorsPopup(errors);
+ } else {
+ pfc.startChatLogic();
+ }
+ }).error(function () {
+ pfc.showErrorsPopup([ 'Unknown error' ]);
+ });
+ } else {
+ pfc.startChatLogic();
+ }
- // when logged in
- $(pfc.element).bind('pfc-login', function (evt, pfc, userdata) {
- pfc.uid = userdata.id;
- pfc.users[userdata.id] = userdata;
- pfc.cid = 'xxx'; // static channel id for the first 2.x version
-
- if (pfc.options.focus_on_connect) {
- // give focus to input textarea when auth
- $('div.pfc-compose textarea').focus();
- }
-
- pfc.join(pfc.cid);
- });
- // when logged out
- $(pfc.element).bind('pfc-logout', function (evt, pfc, userdata) {
- pfc.uid = null;
- pfc.clearUserList();
- });
}
+ /**
+ * Start to authenticate and to prepare chat dynamic
+ */
+ pfc.startChatLogic = function () {
+ // try to authenticate
+ //pfc.logout(function (err) { pfc.login(); });
+ pfc.login();
+
+ // when logged in
+ $(pfc.element).bind('pfc-login', function (evt, pfc, userdata) {
+ pfc.uid = userdata.id;
+ pfc.users[userdata.id] = userdata;
+ pfc.cid = 'xxx'; // static channel id for the first 2.x version
+
+ if (pfc.options.focus_on_connect) {
+ // give focus to input textarea when auth
+ $('div.pfc-compose textarea').focus();
+ }
+
+ pfc.join(pfc.cid);
+ });
+
+ // when logged out
+ $(pfc.element).bind('pfc-logout', function (evt, pfc, userdata) {
+ pfc.uid = null;
+ pfc.clearUserList();
+ });
+ };
+
/**
* Check backlink in the page
*/
@@ -74,7 +98,7 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
return false;
}
return true;
- }
+ };
/**
* Load HTML used by the interface in the browser DOM
@@ -243,6 +267,17 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
setTimeout(function () { $(pfc.element).trigger('pfc-loaded', [ pfc ]) }, 0);
};
+ /**
+ * Function used to display errors list in the overlay popup
+ */
+ pfc.showErrorsPopup = function (errors) {
+ var popup = $('<ul class="pfc-errors"></ul>');
+ errors.forEach(function (err) {
+ popup.append($('<li></li>').text(err));
+ });
+ pfc.modalbox.open(popup);
+ };
+
/**
* For mobile ergonomics
**/
@@ -16,6 +16,9 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
// phpfreechat package.json url
packageUrl: '../package.json',
+ // phpfreechat check.php url
+ serverCheckUrl: '../check.php',
+
// callback executed when interface is loaded
loaded: null,
@@ -36,13 +39,20 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
// set it to true if PUT and DELETE http methods are not allowed by the server
use_post_wrapper: true,
+
+ // when true, the first AJAX request is used to verify that server config is ok
+ check_server_config: true
};
function Plugin(element, options) {
// adjust the packageUrl parameter if serverUrl is specified
if (options && options.serverUrl) {
defaults.packageUrl = options.serverUrl + '/../package.json';
}
+ // same for serverCheckUrl
+ if (options && options.serverUrl) {
+ defaults.serverCheckUrl = options.serverUrl + '/../check.php';
+ }
// plugin attributs
this.element = element;

0 comments on commit cd6a3e5

Please sign in to comment.