Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Bancha/Bancha into i18n-support
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandschuetz committed Sep 3, 2012
2 parents 37a30f6 + bd0a306 commit 4f9da60
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Controller/BanchaController.php
Expand Up @@ -93,7 +93,7 @@ public function index($metadataFilter='') {
}

$api = array(
'url' => $this->request->webroot.'bancha.php',
'url' => $this->request->webroot.'bancha-dispatcher.php',
'namespace' => Configure::read('Bancha.Api.stubsNamespace'),
'type' => 'remoting',
'metadata' => array_merge(
Expand Down
6 changes: 3 additions & 3 deletions Test/Case/Controller/BanchaControllerTest.php
Expand Up @@ -24,7 +24,7 @@ public function testIndexNoMetadata()
{
$response = $this->testAction('/bancha-api.js');
$api = json_decode(substr($response, strpos($response, '=')+1));
$this->assertEquals('/bancha.php', substr($api->url,-11,11)); //strip the absolute path, otherwise it doesn't probably work in the terminal
$this->assertEquals('/bancha-dispatcher.php', substr($api->url,-22,22)); //strip the absolute path, otherwise it doesn't probably work in the terminal
$this->assertEquals('Bancha.RemoteStubs', $api->namespace);
$this->assertEquals('remoting', $api->type);
$this->assertTrue(isset($api->metadata->_UID));
Expand All @@ -40,7 +40,7 @@ public function testIndexOneMetadata()
{
$response = $this->testAction('/bancha-api/models/User.js');
$api = json_decode(substr($response, strpos($response, '=')+1));
$this->assertEquals('/bancha.php', substr($api->url,-11,11)); //strip the absolute path, otherwise it doesn't probably work in the terminal
$this->assertEquals('/bancha-dispatcher.php', substr($api->url,-22,22)); //strip the absolute path, otherwise it doesn't probably work in the terminal
$this->assertEquals('Bancha.RemoteStubs', $api->namespace);
$this->assertEquals('remoting', $api->type);
$this->assertTrue(isset($api->metadata->_UID));
Expand All @@ -58,7 +58,7 @@ public function testIndexAllMetadata()
{
$response = $this->testAction('/bancha-api/models/all.js');
$api = json_decode(substr($response, strpos($response, '=')+1));
$this->assertEquals('/bancha.php', substr($api->url,-11,11)); //strip the absolute path, otherwise it doesn't probably work in the terminal
$this->assertEquals('/bancha-dispatcher.php', substr($api->url,-22,22)); //strip the absolute path, otherwise it doesn't probably work in the terminal
$this->assertEquals('Bancha.RemoteStubs', $api->namespace);
$this->assertEquals('remoting', $api->type);

Expand Down
File renamed without changes.
49 changes: 39 additions & 10 deletions webroot/js/Bancha.js
Expand Up @@ -426,13 +426,21 @@ Ext.define('Bancha', {
init: function() {
var remoteApi,
regex,
defaultErrorHandle,
scripts,
foundApi = false,
apiPath,
response,
result;

// IFDEBUG

// show all initialize errors as message
defaultErrorHandle = Ext.Error.handle;
Ext.Error.handle = function(err) {
Ext.Msg.alert('Bancha Error', err.msg);
};

if(Ext.versions.extjs && !Ext.isReady) {
Ext.Error.raise({
plugin: 'Bancha',
Expand Down Expand Up @@ -584,28 +592,49 @@ Ext.define('Bancha', {
async: false
});
try {
result = Ext.decode(response.responseText);
result = Ext.decode(response.responseText, true);
} catch(e) {
Ext.Error.raise({
plugin: 'Bancha',
msg: [
'<b>Bancha Configuration Error:</b><br />',
'There is an error in your <i>app/webroot/bancha-dispatcher.php</i> file, ',
'see <a href="'+remoteApi.url+'">'+remoteApi.url+'</a>.'
].join('')
});
// handle below
}
if(response.status!==200 || !Ext.isObject(result) || !result.BanchaDispatcherIsSetup) {

// this might be just an update issue
// check if the old name (bancha.php) still works
response = Ext.Ajax.request({
url: remoteApi.url.replace(/bancha-dispatcher\.php/, 'bancha.php')+'?setup-check=true',
async: false
});
try {
result = Ext.decode(response.responseText, true);
} catch(e) {
// There are many errors, let the user first rename the Bancha dispatcher and then fix the other
}
if(response.status===200 && Ext.isObject(result) && result.BanchaDispatcherIsSetup) {
// old bancha dispatcher is still available
Ext.Error.raise({
plugin: 'Bancha',
msg: [
'<b>Bancha Update Error:</b><br />',
'Since 1.1.0 the Bancha Dispatcher got renamed from "bancha.php" to "bancha-dispatcher.php".<br /><br />',
'<b>Please rename the file <i>app/webroot/bancha.php</i> to <i>bancha-dispatcher.php</i><br />'
].join('')
});
}

Ext.Error.raise({
plugin: 'Bancha',
msg: [
'<b>Bancha Configuration Error:</b><br />',
'Bancha expects the Bancha Dispatcher to be reachable at <a href="'+remoteApi.url+'">'+remoteApi.url+'</a>.<br /><br />',
'<b>Probably you just forgot to copy the file <i>Bancha/_app/webroot/bancha.php</i> into your app at <i>app/webroot/bancha.php</i><br />',
'<b>Probably you just forgot to copy the file <i>Bancha/_app/webroot/bancha-dispatcher.php</i> into your app at <i>app/webroot/bancha-dispatcher.php</i><br />',
'Please do this and then reload the page.</b>'
].join('')
});
}

// reset to default error handler
Ext.Error.handle = defaultErrorHandle;

// ENDIF

this.initialized = true;
Expand Down
8 changes: 4 additions & 4 deletions webroot/setup-check.html
Expand Up @@ -241,17 +241,17 @@
}

// try to check bancha dispatcher
BanchaSetup.loadScript('../bancha.php?setup-check=true',BanchaSetup.checkSetup_onBanchaDispatcherIsLoaded);
BanchaSetup.loadScript('../bancha-dispatcher.php?setup-check=true',BanchaSetup.checkSetup_onBanchaDispatcherIsLoaded);

},
checkSetup_onBanchaDispatcherIsLoaded: function(isLoaded,ajaxResponse) {

// check if Bancha Dispatcher is copied to webroot
BanchaSetup.writeLog(isLoaded,'Ping Bancha Dispatcher', [
'<b>'+ajaxResponse.status+': Could not find Bancha Dispatcher</b><br/><br/>',
'Please copy the Bancha Dispatcher from <i>plugins/Bancha/_app/webroot/bancha.php</i> ',
'Please copy the Bancha Dispatcher from <i>plugins/Bancha/_app/webroot/bancha-dispatcher.php</i> ',
'into <i>app/webroot/</i>.<br/><br/>',
'If you still have this problem check the output of <a href="../bancha.php" target="_blank">',
'If you still have this problem check the output of <a href="../bancha-dispatcher.php" target="_blank">',
'Bancha Dispatcher page</a>. Note, the Dispatcher works correctly if you can see the error ',
'messsage "Missing POST Data: ...". This is expected!<br /><br />',
'If there is no obvious clue, please <a href="https://github.com/Bancha/Bancha/issues" ',
Expand All @@ -266,7 +266,7 @@
works = response.BanchaDispatcherIsSetup===true;
BanchaSetup.writeLog(works,'Bancha Dispatcher works', [
'<br /><b>Could not validate the Bancha Dispatcher!!!</b><br /><br />',
'Please copy the official Bancha Dispatcher from <i>Plugin/Bancha/_app/webroot/bancha.php</i> ',
'Please copy the official Bancha Dispatcher from <i>Plugin/Bancha/_app/webroot/bancha-dispatcher.php</i> ',
'into <i>app/webroot/</i>. <br /><br />If you did so: '+BanchaSetup.bugReportText
].join(''));
if(works===false) {
Expand Down

0 comments on commit 4f9da60

Please sign in to comment.