mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge remote branch 'origin/master' into translation-staging
This commit is contained in:
commit
0a3b08799e
@ -2,18 +2,39 @@
|
||||
class CMSProfileController extends LeftAndMain {
|
||||
|
||||
static $url_segment = 'myprofile';
|
||||
static $menu_title = 'My Profile';
|
||||
static $required_permission_codes = false;
|
||||
static $tree_class = 'Member';
|
||||
|
||||
public function index($request) {
|
||||
$form = $this->Member_ProfileForm();
|
||||
return $this->customise(array(
|
||||
'Content' => ' ',
|
||||
'Form' => $form
|
||||
))->renderWith('CMSDialog');
|
||||
public function getResponseNegotiator() {
|
||||
$neg = parent::getResponseNegotiator();
|
||||
$controller = $this;
|
||||
$neg->setCallback('CurrentForm', function() use(&$controller) {
|
||||
return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
|
||||
});
|
||||
return $neg;
|
||||
}
|
||||
|
||||
public function Member_ProfileForm() {
|
||||
return new Member_ProfileForm($this, 'Member_ProfileForm', Member::currentUser());
|
||||
|
||||
public function getEditForm($id = null, $fields = null) {
|
||||
$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) {
|
||||
@ -32,4 +53,29 @@ class CMSProfileController extends LeftAndMain {
|
||||
|
||||
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]));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -86,7 +86,6 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
||||
'AddForm',
|
||||
'batchactions',
|
||||
'BatchActionsForm',
|
||||
'Member_ProfileForm',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -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 label { padding-top: 8px; width: 64px; float: left; margin-left: -64px; }
|
||||
.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 -------------------------------------------- */
|
||||
#CanViewType .optionset li, #CanEditType .optionset li, #CanCreateTopLevelType .optionset li { float: none; width: auto; white-space: nowrap; }
|
||||
|
@ -257,6 +257,14 @@
|
||||
return false; // prevent wrapping link event to fire
|
||||
}
|
||||
});
|
||||
|
||||
$('.cms .profile-link').entwine({
|
||||
onclick: function() {
|
||||
$('.cms-container').loadPanel(this.attr('href'));
|
||||
$('.cms-menu-list li').removeClass('current').close();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}(jQuery));
|
||||
|
@ -374,6 +374,12 @@ jQuery.noConflict();
|
||||
// case we'll ignore the response
|
||||
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
|
||||
var title = xhr.getResponseHeader('X-Title');
|
||||
if(title) document.title = title;
|
||||
|
@ -1136,6 +1136,17 @@ form.member-profile-form {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
form.member-profile-form {
|
||||
#Root .ui-tabs-nav {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#Root_Main, #Root_Permissions {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** --------------------------------------------
|
||||
|
32
admin/templates/CMSProfileController_Content.ss
Normal file
32
admin/templates/CMSProfileController_Content.ss
Normal 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>
|
@ -12,7 +12,7 @@
|
||||
<% with CurrentMember %>
|
||||
<span>
|
||||
<% _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 %>
|
||||
</a>
|
||||
</span>
|
||||
|
@ -7,4 +7,5 @@
|
||||
* Removed `SiteTree.MetaTitle` and `SiteTree.MetaKeywords` since they are irrelevant in terms of SEO ([1](http://www.seomoz.org/learn-seo/title-tag), [2](http://www.mattcutts.com/blog/keywords-meta-tag-in-web-search/)) and general page informancy
|
||||
* Deprecated `Profiler` class, use third-party solutions like [xhprof](https://github.com/facebook/xhprof/)
|
||||
* 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
|
@ -284,6 +284,7 @@ Built-in headers are:
|
||||
* `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-Status`: Extended status information, used for an information popover.
|
||||
* `X-Reload`: Force a full page reload based on `X-ControllerURL`
|
||||
|
||||
## Special Links
|
||||
|
||||
|
@ -72,7 +72,7 @@ en:
|
||||
ACCESSALLINTERFACESHELP: 'Overrules more specific access settings.'
|
||||
SAVE: Save
|
||||
CMSProfileController:
|
||||
MENUTITLE: CMSProfileController
|
||||
MENUTITLE: 'My Profile'
|
||||
ChangePasswordEmail.ss:
|
||||
CHANGEPASSWORDTEXT1: 'You changed your password for'
|
||||
CHANGEPASSWORDTEXT2: 'You can now use the following credentials to log in:'
|
||||
|
@ -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
|
||||
* changed
|
||||
|
Loading…
Reference in New Issue
Block a user