[Joomla-commits] r18755 - in development/trunk: components/com_weblinks/controllers installation language/en-GB

4 views
Skip to first unread message

eddi...@jcode001.directrouter.com

unread,
Sep 1, 2010, 9:53:15 PM9/1/10
to joomla-...@joomlacode.org
Author: eddieajau
Date: 2010-09-01 20:53:15 -0500 (Wed, 01 Sep 2010)
New Revision: 18755

Modified:
development/trunk/components/com_weblinks/controllers/weblink.php
development/trunk/installation/CHANGELOG
development/trunk/language/en-GB/en-GB.com_weblinks.ini
Log:
Fixed issue [#22170] Unable to Save Weblinks on Edit (Jennifer Marriott, Elin Waring).

Modified: development/trunk/components/com_weblinks/controllers/weblink.php
===================================================================
--- development/trunk/components/com_weblinks/controllers/weblink.php 2010-09-02 01:30:26 UTC (rev 18754)
+++ development/trunk/components/com_weblinks/controllers/weblink.php 2010-09-02 01:53:15 UTC (rev 18755)
@@ -62,18 +62,152 @@

return $model;
}
+ protected function _getReturnPage()
+ {
+ $app = JFactory::getApplication();
+ $context = $this->context.'.';
+
+ if (!($return = $app->getUserState($context.'.return'))) {
+ $return = JRequest::getVar('return', base64_encode(JURI::base()));
+ }
+
+ $return = JFilterInput::getInstance()->clean($return, 'base64');
+ $return = base64_decode($return);
+
+ if (!JURI::isInternal($return)) {
+ $return = JURI::base();
+ }
+
+ return $return;
+ }
+
+ protected function _setReturnPage()
+ {
+ $app = JFactory::getApplication();
+ $context = $this->context.'.';
+
+ $return = JRequest::getVar('return', null, 'default', 'base64');
+
+ $app->setUserState($context.'return', $return);
+ }
+
/**
* Save the record
*/
public function save()
{
- if( parent::save() === true ) {
- $cid = JRequest::getVar( 'jform' );
- $cid = ( int ) $cid[ 'catid' ];
- $this->setRedirect( JRoute::_( 'index.php?option=com_weblinks&view=category&id='.$cid, false ) );
+ // Check for request forgeries.
+ JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
+
+ // Initialise variables.
+ $app = JFactory::getApplication();
+ $context = $this->context.'.';
+ $model = $this->getModel();
+ $task = $this->getTask();
+
+ // Get posted form variables.
+ $data = JRequest::getVar('jform', array(), 'post', 'array');
+ $catid = $data['catid'];
+ // Populate the row id from the session.
+ $data['id'] = (int) $app->getUserState($context.'id');
+
+
+ // Initialise variables.
+ $app = JFactory::getApplication();
+ $context = $this->context.'.';
+ $model = $this->getModel();
+ $task = $this->getTask();
+
+ // Get posted form variables.
+ $data = JRequest::getVar('jform', array(), 'post', 'array');
+
+ // Populate the row id from the session.
+ $data['id'] = (int) $app->getUserState($context.'id');
+ // Validate the posted data.
+ $form = $model->getForm();
+
+ if (!$form) {
+ JError::raiseError(500, $model->getError());
+ return false;
}
+
+ $data = $model->validate($form, $data);
+
+ // Check for validation errors.
+ if ($data === false) {
+ // Get the validation messages.
+ $errors = $model->getErrors();
+
+ // Push up to three validation messages out to the user.
+ for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
+ {
+ if (JError::isError($errors[$i])) {
+ $app->enqueueMessage($errors[$i]->getMessage(), 'notice');
+ }
+ else {
+ $app->enqueueMessage($errors[$i], 'notice');
+ }
+ }
+
+ // Save the data in the session.
+ $app->setUserState($context.'data', $data);
+
+ // Redirect back to the edit screen.
+ $this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=form&layout=edit', false));
+ return false;
+ }
+ // Attempt to save the data.
+ if (!$model->save($data)) {
+ // Save the data in the session.
+ $app->setUserState($context.'data', $data);
+
+ // Redirect back to the edit screen.
+ $this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()), 'notice');
+ $this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=form&layout=edit', false));
+ return false;
+ }
+
+ // Save succeeded, check-in the row.
+ if (!$model->checkin()) {
+ // Check-in failed, go back to the row and display a notice.
+ $message = JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError());
+ $this->setRedirect('index.php?option=com_weblinks&view=form&layout=edit', $message, 'error');
+ return false;
+ }
+
+ $this->setMessage(JText::_('COM_WEBLINKS_WEBLINK_SAVE_SUCCESS'));
+
+ // Redirect the user and adjust session state based on the chosen task.
+ switch ($task)
+ {
+ case 'apply':
+ // Set the row data in the session.
+ $app->setUserState($context.'id', $model->getState('weblink.id'));
+ $app->setUserState($context.'data', null);
+
+ // Redirect back to the edit screen.
+ $this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=form&layout=edit', false));
+ break;
+
+ case 'save2new':
+ // Clear the row id and data in the session.
+ $app->setUserState($context.'id', null);
+ $app->setUserState($context.'data', null);
+
+ // Redirect back to the edit screen.
+ $this->setRedirect(JRoute::_('index.php?option=com_weblinks&task=edit.weblink', false));
+ break;
+
+ default:
+ // Clear the row id and data in the session.
+ $app->setUserState($context.'id', null);
+ $app->setUserState($context.'data', null);
+ $this->setRedirect( JRoute::_( 'index.php?option=com_weblinks&view=category&id='.$catid, false ) );
+ }
+
$this->setMessage(JText::_('COM_WEBLINK_SUBMIT_SAVE_SUCCESS'));
}
+
/**
* Method to edit a object
*
@@ -107,15 +241,12 @@
$model = $this->getModel();

// Check that this is not a new item.
- if ($id > 0)
- {
+ if ($id > 0) {
$item = $model->getItem($id);

// If not already checked out, do so.
- if ($item->checked_out == 0)
- {
- if (!$model->checkout($id))
- {
+ if ($item->checked_out == 0) {
+ if (!$model->checkout($id)) {
// Check-out failed, go back to the list and display a notice.
$message = JText::sprintf('JLIB_APPLICATION_ERROR_CHECKOUT_FAILED', $model->getError());
$this->setRedirect('index.php?option=com_weblinks&view=categories', $message, 'error');
@@ -131,14 +262,15 @@
// ItemID required on redirect for correct Template Style
$redirect = 'index.php?option=com_weblinks&view=form&layout=edit&id='.$id;
if (JRequest::getInt('Itemid') == 0) {
- } else {
+ }
+ else {
$redirect .= '&Itemid='.JRequest::getInt('Itemid');
}
$this->setRedirect($redirect);

return true;
}
-
+
/**
* Method to cancel an edit
*
@@ -160,35 +292,7 @@
$this->setRedirect($this->_getReturnPage());
}

- protected function _getReturnPage()
- {
- $app = JFactory::getApplication();
- $context = $this->context.'.';

- if (!($return = $app->getUserState($context.'.return'))) {
- $return = JRequest::getVar('return', base64_encode(JURI::base()));
- }
-
- $return = JFilterInput::getInstance()->clean($return, 'base64');
- $return = base64_decode($return);
-
- if (!JURI::isInternal($return)) {
- $return = JURI::base();
- }
-
- return $return;
- }
-
- protected function _setReturnPage()
- {
- $app = JFactory::getApplication();
- $context = $this->context.'.';
-
- $return = JRequest::getVar('return', null, 'default', 'base64');
-
- $app->setUserState($context.'return', $return);
- }
-
/**
* Go to a weblink
*
@@ -242,7 +346,8 @@
if ($link->url) {
$modelLink->hit($id);
JFactory::getApplication()->redirect($link->url);
- } else {
+ }
+ else {
return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID'));
}
}

Modified: development/trunk/installation/CHANGELOG
===================================================================
--- development/trunk/installation/CHANGELOG 2010-09-02 01:30:26 UTC (rev 18754)
+++ development/trunk/installation/CHANGELOG 2010-09-02 01:53:15 UTC (rev 18755)
@@ -32,6 +32,7 @@
# Fixed issue [#22211] module - latest news - typo error (Bill Richardson).
# Fixed issue [#22169] After selecting cannot set -use default- (Klas Berlič1, Ian MacLennan).
# Fixed issue [#22052] sample data menu capitalisation (Brian Teeman, Tim Plummer).
+ # Fixed issue [#22170] Unable to Save Weblinks on Edit (Jennifer Marriott, Elin Waring).

01-Sep-2010 Andrew Eddie (and Happy 5th Birthday Joomla!)
# Fixed issue [#22118] The setRedirect method() overwrites an already set messageType (Roland Dalmulder, Artyom Bisyarin).

Modified: development/trunk/language/en-GB/en-GB.com_weblinks.ini
===================================================================
--- development/trunk/language/en-GB/en-GB.com_weblinks.ini 2010-09-02 01:30:26 UTC (rev 18754)
+++ development/trunk/language/en-GB/en-GB.com_weblinks.ini 2010-09-02 01:53:15 UTC (rev 18755)
@@ -21,4 +21,6 @@
COM_WEBLINKS_NO_WEBLINKS="There are no Web links in this category"
COM_WEBLINKS_NUM="# of links:"
COM_WEBLINKS_WEB_LINKS="Web links"
+COM_WEBLINKS_WEBLINK_SAVE_SUCCESS="Web link successfully saved"
JGLOBAL_NEWITEMSLAST_DESC="New Web links default to the last position. Ordering can be changed after this Web link has been saved."
+COM_WEBLINKS_ERR_TABLES_NAME="There is already a Web Link with that name in this category. Please try again."
\ No newline at end of file

_______________________________________________
Joomla-commits mailing list
Joomla-...@joomlacode.org
http://joomlacode.org/mailman/listinfo/joomla-commits

Reply all
Reply to author
Forward
0 new messages