Merge remote branch 'origin/master' into translation-staging

This commit is contained in:
TeamCity 2012-10-09 01:02:02 +13:00
commit 0a3b08799e
12 changed files with 119 additions and 66 deletions

View File

@ -2,18 +2,39 @@
class CMSProfileController extends LeftAndMain { class CMSProfileController extends LeftAndMain {
static $url_segment = 'myprofile'; static $url_segment = 'myprofile';
static $menu_title = 'My Profile';
static $required_permission_codes = false; static $required_permission_codes = false;
static $tree_class = 'Member';
public function index($request) { public function getResponseNegotiator() {
$form = $this->Member_ProfileForm(); $neg = parent::getResponseNegotiator();
return $this->customise(array( $controller = $this;
'Content' => ' ', $neg->setCallback('CurrentForm', function() use(&$controller) {
'Form' => $form return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
))->renderWith('CMSDialog'); });
return $neg;
} }
public function Member_ProfileForm() { public function getEditForm($id = null, $fields = null) {
return new Member_ProfileForm($this, 'Member_ProfileForm', Member::currentUser()); $this->setCurrentPageID(Member::currentUserID());
$form = parent::getEditForm($id, $fields);
$form->Fields()->push(new HiddenField('ID', null, Member::currentUserID()));
$form->Actions()->push(
FormAction::create('save',_t('CMSMain.SAVE', 'Save'))
->addExtraClass('ss-ui-button ss-ui-action-constructive')
->setAttribute('data-icon', 'accept')
->setUseButtonTag(true)
);
$form->Actions()->removeByName('delete');
$form->setValidator(new Member_Validator());
$form->setTemplate('Form');
$form->setAttribute('data-pjax-fragment', null);
if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
$form->addExtraClass('member-profile-form root-form cms-edit-form cms-panel-padded center');
return $form;
} }
public function canView($member = null) { public function canView($member = null) {
@ -32,4 +53,29 @@ class CMSProfileController extends LeftAndMain {
return true; return true;
} }
public function save($data, $form) {
$member = DataObject::get_by_id("Member", $data['ID']);
if(!$member) return $this->httpError(404);
$origLocale = $member->Locale;
$response = parent::save($data, $form);
if($origLocale != $data['Locale']) {
$response->addHeader('X-Reload', true);
$response->addHeader('X-ControllerURL', $this->Link());
}
return $response;
}
/**
* Only show first element, as the profile form is limited to editing
* the current member it doesn't make much sense to show the member name
* in the breadcrumbs.
*/
public function Breadcrumbs($unlinked = false) {
$items = parent::Breadcrumbs($unlinked);
return new ArrayList(array($items[0]));
}
} }

View File

@ -86,7 +86,6 @@ class LeftAndMain extends Controller implements PermissionProvider {
'AddForm', 'AddForm',
'batchactions', 'batchactions',
'BatchActionsForm', 'BatchActionsForm',
'Member_ProfileForm',
); );
/** /**

View File

@ -484,6 +484,8 @@ form.member-profile-form .ui-tabs-nav .ui-corner-all, form.member-profile-form .
.cms .cms-content-fields .field .fieldholder-small { margin-top: 8px; } .cms .cms-content-fields .field .fieldholder-small { margin-top: 8px; }
.cms .cms-content-fields .field .fieldholder-small label { padding-top: 8px; width: 64px; float: left; margin-left: -64px; } .cms .cms-content-fields .field .fieldholder-small label { padding-top: 8px; width: 64px; float: left; margin-left: -64px; }
.cms .cms-content-fields .field table .fieldholder-small { margin-top: 0; } .cms .cms-content-fields .field table .fieldholder-small { margin-top: 0; }
.cms form.member-profile-form #Root .ui-tabs-nav { display: none; }
.cms form.member-profile-form #Root_Main, .cms form.member-profile-form #Root_Permissions { border: none; }
/** -------------------------------------------- "Settings" Form -------------------------------------------- */ /** -------------------------------------------- "Settings" Form -------------------------------------------- */
#CanViewType .optionset li, #CanEditType .optionset li, #CanCreateTopLevelType .optionset li { float: none; width: auto; white-space: nowrap; } #CanViewType .optionset li, #CanEditType .optionset li, #CanCreateTopLevelType .optionset li { float: none; width: auto; white-space: nowrap; }

View File

@ -258,5 +258,13 @@
} }
}); });
$('.cms .profile-link').entwine({
onclick: function() {
$('.cms-container').loadPanel(this.attr('href'));
$('.cms-menu-list li').removeClass('current').close();
return false;
}
});
}); });
}(jQuery)); }(jQuery));

View File

@ -374,6 +374,12 @@ jQuery.noConflict();
// case we'll ignore the response // case we'll ignore the response
if(!data) return; if(!data) return;
// Support a full reload
if(xhr.getResponseHeader('X-Reload') && xhr.getResponseHeader('X-ControllerURL')) {
document.location.href = xhr.getResponseHeader('X-ControllerURL');
return;
}
// Update title // Update title
var title = xhr.getResponseHeader('X-Title'); var title = xhr.getResponseHeader('X-Title');
if(title) document.title = title; if(title) document.title = title;

View File

@ -1136,6 +1136,17 @@ form.member-profile-form {
} }
} }
} }
form.member-profile-form {
#Root .ui-tabs-nav {
display: none;
}
#Root_Main, #Root_Permissions {
border: none;
}
}
} }
/** -------------------------------------------- /** --------------------------------------------

View File

@ -0,0 +1,32 @@
<div id="settings-controller-cms-content" class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content CurrentForm">
<div class="cms-content-header north">
<% with EditForm %>
<div class="cms-content-header-info">
<h2>
<% with Controller %>
<% include CMSBreadcrumbs %>
<% end_with %>
</h2>
</div>
<% if Fields.hasTabset %>
<% with Fields.fieldByName('Root') %>
<div class="cms-content-header-tabs">
<ul>
<% loop Tabs %>
<li<% if extraClass %> class="$extraClass"<% end_if %>><a href="#$id">$Title</a></li>
<% end_loop %>
</ul>
</div>
<% end_with %>
<% end_if %>
<% end_with %>
</div>
<div class="cms-content-fields center ui-widget-content" data-layout-type="border">
$EditForm
</div>
</div>

View File

@ -12,7 +12,7 @@
<% with CurrentMember %> <% with CurrentMember %>
<span> <span>
<% _t('LeftAndMain_Menu.ss.Hello','Hi') %> <% _t('LeftAndMain_Menu.ss.Hello','Hi') %>
<a href="{$AbsoluteBaseURL}admin/myprofile" class="profile-link ss-ui-dialog-link" data-popupclass="edit-profile-popup"> <a href="{$AbsoluteBaseURL}admin/myprofile" class="profile-link">
<% if FirstName && Surname %>$FirstName $Surname<% else_if FirstName %>$FirstName<% else %>$Email<% end_if %> <% if FirstName && Surname %>$FirstName $Surname<% else_if FirstName %>$FirstName<% else %>$Email<% end_if %>
</a> </a>
</span> </span>

View File

@ -8,3 +8,4 @@
* Deprecated `Profiler` class, use third-party solutions like [xhprof](https://github.com/facebook/xhprof/) * Deprecated `Profiler` class, use third-party solutions like [xhprof](https://github.com/facebook/xhprof/)
* Removed defunct or unnecessary debug GET parameters: * Removed defunct or unnecessary debug GET parameters:
`debug_profile`, `debug_memory`, `profile_trace`, `debug_javascript`, `debug_behaviour` `debug_profile`, `debug_memory`, `profile_trace`, `debug_javascript`, `debug_behaviour`
* Removed `Member_ProfileForm`, use `CMSProfileController` instead

View File

@ -284,6 +284,7 @@ Built-in headers are:
* `X-Controller`: PHP class name matching a menu entry, which is marked active * `X-Controller`: PHP class name matching a menu entry, which is marked active
* `X-ControllerURL`: Alternative URL to record in the HTML5 browser history * `X-ControllerURL`: Alternative URL to record in the HTML5 browser history
* `X-Status`: Extended status information, used for an information popover. * `X-Status`: Extended status information, used for an information popover.
* `X-Reload`: Force a full page reload based on `X-ControllerURL`
## Special Links ## Special Links

View File

@ -72,7 +72,7 @@ en:
ACCESSALLINTERFACESHELP: 'Overrules more specific access settings.' ACCESSALLINTERFACESHELP: 'Overrules more specific access settings.'
SAVE: Save SAVE: Save
CMSProfileController: CMSProfileController:
MENUTITLE: CMSProfileController MENUTITLE: 'My Profile'
ChangePasswordEmail.ss: ChangePasswordEmail.ss:
CHANGEPASSWORDTEXT1: 'You changed your password for' CHANGEPASSWORDTEXT1: 'You changed your password for'
CHANGEPASSWORDTEXT2: 'You can now use the following credentials to log in:' CHANGEPASSWORDTEXT2: 'You can now use the following credentials to log in:'

View File

@ -1469,59 +1469,6 @@ class Member_GroupSet extends ManyManyList {
} }
} }
/**
* Form for editing a member profile.
* @package framework
* @subpackage security
*/
class Member_ProfileForm extends Form {
public function __construct($controller, $name, $member) {
Requirements::block(FRAMEWORK_DIR . '/admin/css/layout.css');
$fields = $member->getCMSFields();
$fields->push(new HiddenField('ID','ID',$member->ID));
$actions = new FieldList(
FormAction::create('dosave',_t('CMSMain.SAVE', 'Save'))
->addExtraClass('ss-ui-button ss-ui-action-constructive')
->setAttribute('data-icon', 'accept')
->setUseButtonTag(true)
);
$validator = new Member_Validator();
parent::__construct($controller, $name, $fields, $actions, $validator);
$this->addExtraClass('member-profile-form');
$this->loadDataFrom($member);
}
public function dosave($data, $form) {
// don't allow ommitting or changing the ID
if(!isset($data['ID']) || $data['ID'] != Member::currentUserID()) {
return $this->controller->redirectBack();
}
$SQL_data = Convert::raw2sql($data);
$member = DataObject::get_by_id("Member", $SQL_data['ID']);
if($SQL_data['Locale'] != $member->Locale) {
$form->addErrorMessage("Generic", _t('Member.REFRESHLANG'),"good");
}
$form->saveInto($member);
$member->write();
$message = _t('Member.PROFILESAVESUCCESS', 'Successfully saved.');
$form->sessionMessage($message, 'good');
$this->controller->redirectBack();
}
}
/** /**
* Class used as template to send an email saying that the password has been * Class used as template to send an email saying that the password has been
* changed * changed