From e3a27ea7da84ab4412c340a4a367299a1e628f53 Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Mon, 8 Oct 2012 15:02:01 +1300 Subject: [PATCH] CMS member profile now is no longer in a popup (#7880) --- admin/code/CMSProfileController.php | 64 ++++++++++++++++--- admin/code/LeftAndMain.php | 1 - admin/css/screen.css | 2 + admin/javascript/LeftAndMain.Menu.js | 8 +++ admin/javascript/LeftAndMain.js | 6 ++ admin/scss/_style.scss | 11 ++++ .../templates/CMSProfileController_Content.ss | 32 ++++++++++ admin/templates/Includes/LeftAndMain_Menu.ss | 2 +- docs/en/changelogs/3.1.0.md | 3 +- docs/en/reference/cms-architecture.md | 1 + lang/en.yml | 8 ++- security/Member.php | 53 --------------- 12 files changed, 123 insertions(+), 68 deletions(-) create mode 100644 admin/templates/CMSProfileController_Content.ss diff --git a/admin/code/CMSProfileController.php b/admin/code/CMSProfileController.php index d55dd311c..ae5a525c0 100644 --- a/admin/code/CMSProfileController.php +++ b/admin/code/CMSProfileController.php @@ -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])); + } + } diff --git a/admin/code/LeftAndMain.php b/admin/code/LeftAndMain.php index c660bae7f..e8195d9da 100644 --- a/admin/code/LeftAndMain.php +++ b/admin/code/LeftAndMain.php @@ -86,7 +86,6 @@ class LeftAndMain extends Controller implements PermissionProvider { 'AddForm', 'batchactions', 'BatchActionsForm', - 'Member_ProfileForm', ); /** diff --git a/admin/css/screen.css b/admin/css/screen.css index 2fca2a3f5..8c89a3628 100644 --- a/admin/css/screen.css +++ b/admin/css/screen.css @@ -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; } diff --git a/admin/javascript/LeftAndMain.Menu.js b/admin/javascript/LeftAndMain.Menu.js index 4654780b9..549e53aa9 100644 --- a/admin/javascript/LeftAndMain.Menu.js +++ b/admin/javascript/LeftAndMain.Menu.js @@ -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)); diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index 50dec931e..f22e1b8d2 100644 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -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; diff --git a/admin/scss/_style.scss b/admin/scss/_style.scss index d5fedf3fc..2a2aa744f 100644 --- a/admin/scss/_style.scss +++ b/admin/scss/_style.scss @@ -1136,6 +1136,17 @@ form.member-profile-form { } } } + + form.member-profile-form { + #Root .ui-tabs-nav { + display: none; + } + + #Root_Main, #Root_Permissions { + border: none; + } + } + } /** -------------------------------------------- diff --git a/admin/templates/CMSProfileController_Content.ss b/admin/templates/CMSProfileController_Content.ss new file mode 100644 index 000000000..1d26dec9e --- /dev/null +++ b/admin/templates/CMSProfileController_Content.ss @@ -0,0 +1,32 @@ +
+ +
+ <% with EditForm %> +
+

+ <% with Controller %> + <% include CMSBreadcrumbs %> + <% end_with %> +

+
+ <% if Fields.hasTabset %> + <% with Fields.fieldByName('Root') %> +
+
    + <% loop Tabs %> + class="$extraClass"<% end_if %>>$Title + <% end_loop %> +
+
+ <% end_with %> + <% end_if %> + <% end_with %> +
+ +
+ + $EditForm + +
+ +
diff --git a/admin/templates/Includes/LeftAndMain_Menu.ss b/admin/templates/Includes/LeftAndMain_Menu.ss index 815c0a507..be2407fa7 100644 --- a/admin/templates/Includes/LeftAndMain_Menu.ss +++ b/admin/templates/Includes/LeftAndMain_Menu.ss @@ -12,7 +12,7 @@ <% with CurrentMember %> <% _t('LeftAndMain_Menu.ss.Hello','Hi') %> - + <% if FirstName && Surname %>$FirstName $Surname<% else_if FirstName %>$FirstName<% else %>$Email<% end_if %> diff --git a/docs/en/changelogs/3.1.0.md b/docs/en/changelogs/3.1.0.md index 378b2079b..86a409ab2 100644 --- a/docs/en/changelogs/3.1.0.md +++ b/docs/en/changelogs/3.1.0.md @@ -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` \ No newline at end of file + `debug_profile`, `debug_memory`, `profile_trace`, `debug_javascript`, `debug_behaviour` + * Removed `Member_ProfileForm`, use `CMSProfileController` instead \ No newline at end of file diff --git a/docs/en/reference/cms-architecture.md b/docs/en/reference/cms-architecture.md index c20fdf067..bc729cb20 100644 --- a/docs/en/reference/cms-architecture.md +++ b/docs/en/reference/cms-architecture.md @@ -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 diff --git a/lang/en.yml b/lang/en.yml index 53a80cb0e..41a3d81c1 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -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:' @@ -259,7 +259,7 @@ en: many_many_Members: Members GroupImportForm: Help1: '

Import one or more groups in CSV format (comma-separated values). Show advanced usage

' - Help2: "
\n

Advanced usage

\n \n
" + Help2: "
\n

Advanced usage

\n \n
" ResultCreated: 'Created {count} groups' ResultDeleted: 'Deleted %d groups' ResultUpdated: 'Updated %d groups' @@ -410,7 +410,7 @@ en: TWODIGITYEAR: 'Two-digit year' MemberImportForm: Help1: '

Import users in CSV format (comma-separated values). Show advanced usage

' - Help2: "
\n

Advanced usage

\n \n
" + Help2: "
\n

Advanced usage

\n \n
" ResultCreated: 'Created {count} members' ResultDeleted: 'Deleted %d members' ResultNone: 'No changes' @@ -423,6 +423,7 @@ en: ModelAdmin: DELETE: Delete DELETEDRECORDS: 'Deleted {count} records.' + EMPTYBEFOREIMPORT: 'Clear Database before import' IMPORT: 'Import from CSV' IMPORTEDRECORDS: 'Imported {count} records.' NOCSVFILE: 'Please browse for a CSV file to import' @@ -473,6 +474,7 @@ en: SINGULARNAME: 'Permission Role Code' Permissions: PERMISSIONS_CATEGORY: 'Roles and access permissions' + UserPermissionsIntro: 'Assigning groups to this user will adjust the permissions they have. See the groups section for details of permissions on individual groups.' PhoneNumberField: VALIDATION: 'Please enter a valid phone number' RelationComplexTableField.ss: diff --git a/security/Member.php b/security/Member.php index c2b9ee368..ae69dc037 100644 --- a/security/Member.php +++ b/security/Member.php @@ -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