[CS-Project-svn_notify] SF.net SVN: cs-project: [775] trunk
Brought to you by:
crazedsanity
From: <cra...@us...> - 2008-02-04 21:33:32
|
Revision: 775 http://cs-project.svn.sourceforge.net/cs-project/?rev=775&view=rev Author: crazedsanity Date: 2008-02-04 13:33:29 -0800 (Mon, 04 Feb 2008) Log Message: ----------- AJAX-ified preference updates. Modified Paths: -------------- trunk/includes/content/settings.inc trunk/templates/content/settings/index.content.tmpl Modified: trunk/includes/content/settings.inc =================================================================== --- trunk/includes/content/settings.inc 2008-02-04 20:14:52 UTC (rev 774) +++ trunk/includes/content/settings.inc 2008-02-04 21:33:29 UTC (rev 775) @@ -10,6 +10,12 @@ * Last Updated: $Date$ */ + +$prefObj = new pref($page->db, $_SESSION['uid']); +$GLOBALS['objects']['pref'] = $prefObj; + +addAjax(); + require_once(dirname(__FILE__) .'/../../lib/adminUserClass.php'); require_once(dirname(__FILE__) .'/../../lib/prefClass.php'); @@ -100,31 +106,7 @@ $goHere = "/content/settings"; } break; - - - - case 'set_preference': { - $pref = new pref($page->db, $_SESSION['uid']); - $result = $pref->update_user_pref($_POST['prefTypeId'], $_POST['prefType'][$_POST['prefTypeId']]); - if($result == 1) { - $messageArr = array( - 'title' => "Preference Updated", - 'message' => "Your preference was successfully stored.", - 'type' => "status" - ); - } - else { - $messageArr = array( - 'title' => "Error Updating Preference", - 'message' => "There was an error while attempting to update your preference ($result).", - 'type' => "error" - ); - } - set_message_wrapper($messageArr); - } - break; - DEFAULT: } @@ -132,6 +114,7 @@ conditional_header($goHere); exit; } + exit; } elseif(isset($_GET['action'])) { @@ -169,7 +152,6 @@ //TODO: when they don't have the pref, select the default! //show 'em their preferences. - $prefObj = new pref($page->db, $_SESSION['uid']); $allPrefs = $prefObj->list_all_prefs(); $userPrefs = $prefObj->get_user_prefs(); @@ -314,4 +296,44 @@ } } } + + +function ajax__update_preference($prefId, $newValue) { + $page = $GLOBALS['objects']['page']; + $prefObj = $GLOBALS['objects']['pref']; + $objResponse = new xajaxResponse(); + + $prefData = $prefObj->list_all_prefs(array('pref_type_id' => $prefId)); + #debug_print($prefData,1); + #exit; + + + //update the preference. + $result = $prefObj->update_user_pref($prefId, $newValue); + + $properSelectedName = $prefData['optionList'][$newValue]['name']; + + if($result == 1) { + $messageArr = array( + 'title' => "Preference Updated", + 'message' => "Your preference for <b>". $prefData['display_name'] ."</b> was successfully " . + "stored (<i>". $properSelectedName ."</i>).", + 'type' => "status" + ); + } + else { + $messageArr = array( + 'title' => "Error Updating Preference", + 'message' => "There was an error while attempting to update your preference ($result).", + 'type' => "error" + ); + } + $page->set_message_wrapper($messageArr); + $objResponse->addAssign('MAIN_error_message', 'innerHTML', $page->process_set_message()); + + $objResponse->addAssign('pref_currentSetting_'. $prefId, 'innerHTML', $properSelectedName); + + return($objResponse); + +}//end ajax__update_preference() ?> Modified: trunk/templates/content/settings/index.content.tmpl =================================================================== --- trunk/templates/content/settings/index.content.tmpl 2008-02-04 20:14:52 UTC (rev 774) +++ trunk/templates/content/settings/index.content.tmpl 2008-02-04 21:33:29 UTC (rev 775) @@ -63,13 +63,14 @@ <select name="prefType[%%pref_type_id%%]"> %%row_optionList%% <!-- BEGIN pref_optionList --> - <option %%selectedString%% value="%%value%%" onClick="document.prefTable.prefTypeId.value='%%pref_type_id%%';document.prefTable.submit();">%%display%% (%%effective_value%%)</option> + <option %%selectedString%% value="%%value%%" + onClick="xajax_ajax__update_preference(%%pref_type_id%%, %%value%%);">%%display%% (%%effective_value%%)</option> <!-- END pref_optionList --> </select> </td> <td style="background-color:%%rowColor%%"> - %%currentSetting%% + <div id="pref_currentSetting_%%pref_type_id%%">%%currentSetting%%</div> <div class="note">(Default value: %%default_value%%)</div> </td> </tr> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |