Browse Source

Update to FlashComponent

euromark 11 years ago
parent
commit
20bf0f9d7a

+ 2 - 2
Controller/Component/CalendarComponent.php

@@ -62,7 +62,7 @@ class CalendarComponent extends Component {
 		$current = date('Y');
 
 		if (empty($month) || $year < $current - $span || $year > $current + $span) {
-			$this->Controller->Common->flashMessage(__d('tools', 'invalid date'), 'error');
+			$this->Controller->Flash->message(__d('tools', 'invalid date'), 'error');
 			$this->Controller->redirect(array('action' => 'index'));
 		}
 
@@ -74,7 +74,7 @@ class CalendarComponent extends Component {
 		}
 
 		if ($month < 1 || $month > 12) {
-			$this->Controller->Common->flashMessage(__d('tools', 'invalid date'), 'error');
+			$this->Controller->Flash->message(__d('tools', 'invalid date'), 'error');
 			$this->Controller->redirect(array('action' => 'index'));
 		}
 		return true;

+ 5 - 5
Controller/QloginController.php

@@ -35,7 +35,7 @@ class QloginController extends ToolsAppController {
 		}
 
 		if (empty($entry)) {
-			$this->Common->flashMessage(__d('tools', 'Invalid Key'), 'error');
+			$this->Flash->message(__d('tools', 'Invalid Key'), 'error');
 			return $this->Common->autoRedirect($default);
 		}
 
@@ -47,10 +47,10 @@ class QloginController extends ToolsAppController {
 			if ($this->Common->manualLogin($uid)) {
 				$this->Session->write('Auth.User.Login.qlogin', true);
 				if (!Configure::read('Qlogin.suppressMessage')) {
-					$this->Common->flashMessage(__d('tools', 'You successfully logged in via qlogin'), 'success');
+					$this->Flash->message(__d('tools', 'You successfully logged in via qlogin'), 'success');
 				}
 			} else {
-				$this->Common->flashMessage($this->Auth->loginError, 'error');
+				$this->Flash->message($this->Auth->loginError, 'error');
 				$url = $default;
 				trigger_error($this->Auth->loginError . ' - uid ' . $uid);
 			}
@@ -70,7 +70,7 @@ class QloginController extends ToolsAppController {
 			$this->Qlogin->set($this->request->data);
 			if ($this->Qlogin->validates()) {
 				$id = $this->Qlogin->generate($this->Qlogin->data['Qlogin']['url'], $this->Qlogin->data['Qlogin']['user_id']);
-				$this->Common->flashMessage('New Key: ' . h($id), 'success');
+				$this->Flash->message('New Key: ' . h($id), 'success');
 				$url = $this->Qlogin->urlByKey($id);
 				$this->set(compact('url'));
 				$this->request->data = array();
@@ -105,7 +105,7 @@ class QloginController extends ToolsAppController {
 		$this->request->allowMethod(array('post', 'delete'));
 		$this->Token = ClassRegistry::init('Tools.Token');
 		$this->Token->deleteAll(array('type' => 'qlogin'));
-		$this->Common->flashMessage(__d('tools', 'Success'), 'success');
+		$this->Flash->message(__d('tools', 'Success'), 'success');
 		return $this->Common->autoRedirect(array('action' => 'index'));
 	}
 

+ 4 - 6
Controller/TinyUrlsController.php

@@ -51,7 +51,7 @@ class TinyUrlsController extends ToolsAppController {
 
 		if (!empty($message)) {
 			$type = !empty($entry['TinyUrl']['flash_type']) ? $entry['TinyUrl']['flash_type'] : 'success';
-			$this->Common->flashMessage($message, $type);
+			$this->Flash->message($message, $type);
 		}
 		$this->TinyUrl->up($entry['TinyUrl']['id'], array('field' => 'used', 'modify' => true, 'timestampField' => 'last_used'));
 		return $this->redirect($url, 301);
@@ -67,7 +67,7 @@ class TinyUrlsController extends ToolsAppController {
 			$this->TinyUrl->set($this->request->data);
 			if ($this->TinyUrl->validates()) {
 				$id = $this->TinyUrl->generate($this->TinyUrl->data['TinyUrl']['url']);
-				$this->Common->flashMessage('New Key: ' . h($id), 'success');
+				$this->Flash->message('New Key: ' . h($id), 'success');
 				$url = $this->TinyUrl->urlByKey($id);
 				$this->set(compact('url'));
 				$this->request->data = array();
@@ -93,11 +93,9 @@ class TinyUrlsController extends ToolsAppController {
 	 * @return void
 	 */
 	public function admin_reset() {
-		if (!$this->Common->isPosted()) {
-			throw new MethodNotAllowedException();
-		}
+		$this->request->allowMethod('post');
 		$this->TinyUrl->truncate();
-		$this->Common->flashMessage(__d('tools', 'Done'), 'success');
+		$this->Flash->message(__d('tools', 'Done'), 'success');
 		return $this->Common->autoRedirect(array('action' => 'index'));
 	}
 

+ 1 - 1
Test/Case/Controller/Component/AjaxComponentTest.php

@@ -114,7 +114,7 @@ class AjaxComponentTest extends CakeTestCase {
 		$this->Controller->startupProcess();
 		$this->assertTrue($this->Controller->Components->Ajax->respondAsAjax);
 
-		$this->Controller->Common->flashMessage('A message', 'success');
+		$this->Controller->Flash->message('A message', 'success');
 		$session = $this->Controller->Session->read('messages');
 		$expected = array(
 			'success' => array('A message')

+ 2 - 2
Test/Case/Controller/Component/CommonComponentTest.php

@@ -148,7 +148,7 @@ class CommonComponentTest extends CakeTestCase {
 	 * @return void
 	 */
 	public function testTransientFlashMessage() {
-		$is = $this->Controller->Common->transientFlashMessage('xyz', 'success');
+		$is = $this->Controller->Flash->transientMessage('xyz', 'success');
 		//$this->assertTrue($is);
 
 		$res = Configure::read('messages');
@@ -164,7 +164,7 @@ class CommonComponentTest extends CakeTestCase {
 	 */
 	public function testFlashMessage() {
 		$this->Controller->Session->delete('messages');
-		$is = $this->Controller->Common->flashMessage('efg');
+		$is = $this->Controller->Flash->message('efg');
 
 		$res = $this->Controller->Session->read('messages');
 		$this->assertTrue(!empty($res));

+ 1 - 1
Test/Case/View/Helper/CommonHelperTest.php

@@ -29,7 +29,7 @@ class CommonHelperTest extends MyCakeTestCase {
 	 * @return void
 	 */
 	public function testFlashMessage() {
-		$result = $this->Common->flashMessage(h('Foo & bar'), 'success');
+		$result = $this->Flash->message(h('Foo & bar'), 'success');
 		$expected = '<div class="flash-messages flashMessages"><div class="message success">Foo &amp;amp; bar</div></div>';
 		$this->assertEquals($expected, $result);
 	}