Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.89 KB | None | 0 0
  1. [code] //---------------------------
  2. public function loadCargoDialogFbjsAction() {
  3. $config = Zend_Registry::get('config');
  4. $userNamespace = new Zend_Session_Namespace('User');
  5. $dlgPrefixValue = $userNamespace->dialogPrefixValue++;
  6. $dlgPrefixString = sprintf('DIALOG%010d', $dlgPrefixValue);
  7.  
  8. $this->_helper->layout()->disableLayout();
  9. $this->_helper->viewRenderer->setNoRender();
  10.  
  11. $loadableCargo = $this->getRequest()->getPost('loadableCargo');
  12.  
  13. require_once 'City.php';
  14. $cityModel = new City();
  15.  
  16. $cityRow = $cityModel->getCityByName($loadableCargo['city']);
  17.  
  18. $cityImage = $cityRow['image'];
  19. $cityImageCaption = $cityRow['caption'];
  20. $cityAnthem = $cityRow['audio_clip'];
  21. $cityAbstract = htmlspecialchars($cityRow['abstract']); //"Cardiff (Welsh, Caerdydd) is the capital of Wales in the United Kingdom and is in the south of the country. Though it had a reputation of being a rough, industrial city, Cardiff has changed dramatically in recent years. It is now a lively and modern capital city, gaining popularity with tourists interested in its history and culture. Once overlooked, it is now one of the United Kingdom's tourism hot spots. Summer is by far the best time to visit, as many of the attractions are outdoors. Its population is roughly 350,000, with 1.5 million living within 20 miles of the city.";
  22.  
  23. /*
  24. <!--
  25. <div id="city_image" style="float: right">
  26. <img src="'. $config->url->absolute->public .'/images/' . $cityImage . '" title="'. $cityAbstract .'" /><br />
  27. <span style="margin-bottom: 6px;">' . wordwrap($cityImageCaption, 38, '<br />') . '</span>
  28. </div>
  29. -->
  30. */
  31. /*
  32. <br style="clear: both" /><br />
  33. Listen to a sample of '. $nation . ''s national anthem:<br />
  34. <fb:mp3 src="' . $config->url->absolute->public . '/audio/'. $cityAnthem .'" title="'. $anthemTitle .'" />
  35. */
  36. $anthemPiece = explode('_', str_replace('.mp3', '', $cityAnthem));
  37. $nextTitle = '';
  38. if(count($anthemPiece) > 2) { $nextTitle = ucfirst($anthemPiece[3]); }
  39. $nation = ucfirst($anthemPiece[2]). ' ' .$nextTitle;
  40. if($nation[strlen($nation) - 1] == 's') { trim($nation, 's'); }
  41. $anthemTitle = ucwords(implode(' ', $anthemPiece));
  42.  
  43. $width = (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) ? 'style="height: 183px" ' : '';
  44. $fbjs =
  45. '<div id="load_cargo_select">
  46. <div id="city_image" style="float: right">
  47. <img '. $width .'src="'. $config->url->absolute->public .'/images/' . $cityImage . '" title="'. $cityAbstract .'" /><br />
  48. <span style="margin-bottom: 6px;">' . wordwrap($cityImageCaption, 38, '<br />') . '</span><br /><br />
  49. Listen to a sample of '. $nation . ''s<br />national anthem:<br />
  50. <fb:mp3 width="200" src="' . $config->url->absolute->public . '/audio/'. $cityAnthem .'" title="'. $anthemTitle .'" />
  51. </div>
  52. <form id="load_cargo_select_form" action="" method="POST">
  53. <p>Your train has stopped in the city of ' . $loadableCargo['city'] . '</p>
  54. <p>' . $loadableCargo['city'] . ' produces the following goods:</p>
  55. <ul>';
  56. if(count($loadableCargo['city_goods']) <= 0) {
  57. $fbjs .= '<li>None</li>';
  58. } else {
  59. foreach($loadableCargo['city_goods'] as $goods) {
  60. $fbjs .= '<li>' . $goods['name'] . '</li>';
  61. }
  62. }
  63. $fbjs .=
  64. '</ul>
  65. <p>Your train is hauling the following goods:</p>
  66. <ul>';
  67. if(count($loadableCargo['train_goods']) <= 0) {
  68. $fbjs .= '<li>None</li>';
  69. } else {
  70. foreach($loadableCargo['train_goods'] as $goods) {
  71. $fbjs .= '<li>' . $goods['name'] . '</li>';
  72. }
  73. }
  74. $fbjs .=
  75. '</ul>
  76. <p>What would you like to do?</p>
  77. <br />
  78. <input style="width: 200px" type="button" id="'.$dlgPrefixString.'-load-new-submit" name="load-cargo-new" value="Load new goods" onclick="return false;" />
  79. <br /><br />
  80. <input style="width: 200px" type="button" id="'.$dlgPrefixString.'-discard-existing-submit" name="load-cargo-discard" value="Discard existing goods" onclick="return false;" />
  81. <input type="hidden" id="dlg-prefix-string" value="'.$dlgPrefixString.'" />
  82. </form>
  83. <br style="clear: both; height: 0px;" />
  84. </div>';
  85.  
  86. echo $fbjs;
  87. }[/code]
  88.  
  89. [code]tutStep = [
  90. . . .
  91. // 41
  92. { event: 'CLICK_LOAD_NEW_GOODS',
  93. cont: false,
  94. text: 'Our train is currently stopped in Bremen which produces autos (among other goods). Dublin has a demand for autos, so we want to load some autos onboard our train. The "Load new goods" button does this. Click this button now.',
  95. arrow: { parent: 'load_cargo_select', dir: 'left', x: 50, y: 30 }
  96. },
  97. . . .
  98. ];
  99.  
  100. function loadCargo() {
  101. //consoleLog('Entering loadCargo()');
  102. var actionPrompt = document.getElementById('action-prompt');
  103. actionPrompt.setTextValue('Loading cargo...');
  104. var ajax = new Ajax();
  105. ajax.responseType = Ajax.JSON;
  106. ajax.ondone = function(data) {
  107. //consoleLog('Entering ondone for load-cargo');
  108. //debugger;
  109. ajax.responseType = Ajax.FBML;
  110. ajax.ondone = function(fbjsData) {
  111. //consoleLog('Entering ondone for load-cargo-dialog-fbjs');
  112. //debugger;
  113. if(data.loadableCargo.length == 0) {
  114. //consoleLog('Calling moveTrainManual()');
  115. moveTrainManual();
  116. } else {
  117. //consoleLog('Instantiating loadCargoDialog');
  118. if(loadCargoDialog == null) {
  119. loadCargoDialog = new Dialog();
  120. //if browser is IE, move dialog up 50px to compensate for bug that causes it to shift down the screen
  121. if(isIE) {
  122. //loadCargoDialog.setStyle('position', 'relative');
  123. //loadCargoDialog.setStyle('top', '-50px');
  124. }
  125. loadCargoDialog.showChoice('Load Cargo', '<div id="load-cargo-main">'+fbjsData+'</div>', 'Minimize', 'Pass');
  126. } else {
  127. if(isIE) {
  128. //loadCargoDialog.setStyle('position', 'relative');
  129. //loadCargoDialog.setStyle('top', '-50px');
  130. }
  131. loadCargoDialog.showChoice('Load Cargo', fbjsData, 'Minimize', 'Pass');
  132. }
  133. var dlgPrefixString = document.getElementById('dlg-prefix-string').getValue();
  134. //var dlgPrefixString = dlgPrefixElem.getValue();
  135. //consoleLog('Setting dlgBtnNew');
  136. var dlgBtnNew = document.getElementById(dlgPrefixString+'-load-new-submit');
  137. dlgBtnNew.cityId = data.loadableCargo.city_id;
  138. dlgBtnNew.trainId = data.loadableCargo.train_id;
  139. dlgBtnNew.prefixString = dlgPrefixString;
  140. dlgBtnNew.loadCargoDialog = loadCargoDialog;
  141. dlgBtnNew.addEventListener('click', cargoEventHandler); //loadNewCargo);
  142. //consoleLog('Setting dlgBtnDiscard');
  143. var dlgBtnDiscard = document.getElementById(dlgPrefixString+'-discard-existing-submit');
  144. dlgBtnDiscard.cityId = data.loadableCargo.city_id;
  145. dlgBtnDiscard.trainId = data.loadableCargo.train_id;
  146. dlgBtnDiscard.prefixString = dlgPrefixString;
  147. dlgBtnDiscard.loadCargoDialog = loadCargoDialog;
  148. dlgBtnDiscard.addEventListener('click', discardExistingCargo);
  149. loadCargoDialog.onconfirm = function() {
  150. //consoleLog('Entering loadCargoDialog.onconfirm');
  151. // Submit the form if it exists, then hide the dialog.
  152. loadCargoDialog.hide();
  153. actionPrompt = document.getElementById('action-prompt');
  154. actionPrompt.setInnerXHTML('<span><div id="action-text">'+
  155. 'The "Load cargo" dialog has been minimized'+
  156. '</div>'+
  157. '<div id="action-end">'+
  158. '<form action="" method="POST">'+
  159. '<input type="button" value="Maximize" id="next-phase" onclick="loadCargo();" />'+
  160. '</form>'+
  161. '</div></span>');
  162. actionButton = document.getElementById('next-phase');
  163. actionButton.setValue('Maximize');
  164. actionButton.addEventListener('click', loadCargoEventHandler);
  165. //consoleLog('Exiting loadCargoDialog.onconfirm');
  166. };
  167. loadCargoDialog.oncancel = function() {
  168. if(tutStep[tutIndex]['event'] == 'CLICK_CITY_DUBLIN_MOVE_TRAIN') {
  169. showTutorial();
  170. }
  171. //consoleLog('Entering loadCargoDialog.oncancel');
  172. moveTrainManual();
  173. //consoleLog('Exiting loadCargoDialog.oncancel');
  174. }
  175. }
  176. //consoleLog('Exiting ondone for load-cargo-dialog-fbjs');
  177. }
  178. ajax.onerror = function() {
  179. var dialog = new Dialog().showMessage('Request taking too long', 'The system is taking too long to process this request. Please try refreshing the page. If this does not work, please Contact Us with a description of your problem. We are sorry for the inconvenience.');
  180. }
  181. ajax.post(baseURL + '/turn/load-cargo-dialog-fbjs', data);
  182. //consoleLog('Exiting ondone for load-cargo');
  183. }
  184. ajax.onerror = function() {
  185. var dialog = new Dialog().showMessage('Request taking too long', 'The system is taking too long to process this request. Please try refreshing the page. If this does not work, please Contact Us with a description of your problem. We are sorry for the inconvenience.');
  186. }
  187. ajax.post(baseURL + '/turn/load-cargo');
  188. //consoleLog('Exiting loadCargo');
  189. }
  190.  
  191. function showTutorial() {
  192. //debugger;
  193. var ajax = new Ajax();
  194. ajax.responseType = Ajax.JSON;
  195. var param = { 'tutorial-index': tutIndex };
  196. ajax.ondone = function() {};
  197. ajax.post(baseURL + '/turn/update-tutorial-index', param);
  198. var tutorialContent = document.getElementById('tutorial-content');
  199. tutorialContent.setInnerXHTML('<span>'+tutStep[tutIndex]['text']+'</span>');
  200. if(tutStep[tutIndex]['height'] > 0) {
  201. var tutorialDlg = document.getElementById('tutorial-dlg');
  202. tutorialDlg.setStyle('height', tutStep[tutIndex]['height'] + 'px');
  203. }
  204. if(tutStep[tutIndex]['position'] && tutStep[tutIndex]['position']['x'] > 0) {
  205. var tutorialDlg = document.getElementById('tutorial-dlg');
  206. tutorialDlg.setStyle('left', tutStep[tutIndex]['position']['x'] + 'px');
  207. tutorialDlg.setStyle('top', tutStep[tutIndex]['position']['y'] + 'px');
  208. }
  209. var dlgButton = document.getElementById('btn-tut-continue');
  210. if(tutStep[tutIndex]['cont'] == false) {
  211. dlgButton.setStyle('display', 'none');
  212. } else {
  213. dlgButton.setStyle('display', 'inline');
  214. }
  215. if(tutIndex > 0) {
  216. removeArrow(tutStep[tutIndex - 1]['arrow']['parent']);
  217. }
  218. tutorialArrow(tutStep[tutIndex]['arrow']['x'], tutStep[tutIndex]['arrow']['y'], tutStep[tutIndex]['arrow']['parent'], tutStep[tutIndex]['arrow']['dir']);
  219. tutIndex++;
  220. }
  221.  
  222. function tutorialArrow(x, y, parent, dir) {
  223. if(parent == null) { return; }
  224. //new Dialog().showMessage('test', 'x='+x+', y='+y+', trainData='+dump(trainData, 3));
  225. var arrow = document.createElement('div');
  226. arrow.setClassName('arrow');
  227. //y -= trainMarkerHeight;
  228. //x -= parseInt(trainMarkerWidth/2);
  229. var arrowId = 'tutorial-arrow';
  230. arrow.setId(arrowId);
  231. arrow.setStyle('position', 'absolute');
  232. arrow.setStyle('left', x + 'px');
  233. arrow.setStyle('top', y + 'px');
  234. arrow.setStyle('zIndex', 9999);
  235.  
  236. var arrowImg = document.createElement('img');
  237. switch(dir) {
  238. case 'up':
  239. arrowImg.setSrc(publicURL + '/images/arrow-up.png');
  240. break;
  241. case 'down':
  242. arrowImg.setSrc(publicURL + '/images/arrow-down.png');
  243. break;
  244. case 'left':
  245. arrowImg.setSrc(publicURL + '/images/arrow-left.png');
  246. break;
  247. case 'right':
  248. arrowImg.setSrc(publicURL + '/images/arrow-right.png');
  249. break;
  250. }
  251. arrow.appendChild(arrowImg);
  252.  
  253. if(tutStep[tutIndex]['arrow']['prepend_appid'] == true) {
  254. parent = 'app'+appId+'_'+parent;
  255. //debugger;
  256. }
  257. //new Dialog().showMessage('', 'parent='+parent);
  258. var parentObj = document.getElementById(parent);
  259.  
  260. //NOTE: THIS IS THE LINE THAT GENERATES THE FIREBUG ERROR (parentObj is null)
  261. parentObj.appendChild(arrow);
  262. flashArrow();
  263. }
  264.  
  265. function removeArrow(parent) {
  266. var map = document.getElementById(parent);
  267. var arrow = document.getElementById("tutorial-arrow");
  268. if(arrow) {
  269. map.removeChild(arrow);
  270. }
  271. }[/code]
Add Comment
Please, Sign In to add comment