1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 23:44:27 +02:00

Replace Ember app with Mithril app

This commit is contained in:
Toby Zerner
2015-04-25 22:28:39 +09:30
parent 6f67b8c247
commit b68a4711dc
377 changed files with 5641 additions and 7330 deletions

View File

@@ -0,0 +1,126 @@
import UserPage from 'flarum/components/user-page';
import ItemList from 'flarum/utils/item-list';
import SwitchInput from 'flarum/components/switch-input';
import ActionButton from 'flarum/components/action-button';
import FieldSet from 'flarum/components/field-set';
import NotificationGrid from 'flarum/components/notification-grid';
import listItems from 'flarum/helpers/list-items';
export default class SettingsPage extends UserPage {
/**
*/
constructor(props) {
super(props);
this.user = app.session.user;
}
content() {
return m('div.settings', [
m('ul', listItems(this.settingsItems().toArray()))
]);
}
settingsItems() {
var items = new ItemList();
items.add('account',
FieldSet.component({
label: 'Account',
className: 'settings-account',
fields: this.accountItems().toArray()
})
);
items.add('notifications',
FieldSet.component({
label: 'Notifications',
className: 'settings-account',
fields: [NotificationGrid.component({
types: this.notificationTypes().toArray(),
user: this.user()
})]
})
);
items.add('privacy',
FieldSet.component({
label: 'Privacy',
fields: this.privacyItems().toArray()
})
);
return items;
}
accountItems() {
var items = new ItemList();
items.add('changePassword',
ActionButton.component({
label: 'Change Password',
className: 'btn btn-default'
})
);
items.add('changeEmail',
ActionButton.component({
label: 'Change Email',
className: 'btn btn-default'
})
);
items.add('deleteAccount',
ActionButton.component({
label: 'Delete Account',
className: 'btn btn-default btn-danger'
})
);
return items;
}
save(key) {
return (value, control) => {
var preferences = this.user().preferences();
preferences[key] = value;
control.loading(true);
m.redraw();
this.user().save({preferences}).then(() => {
control.loading(false);
m.redraw();
});
};
}
privacyItems() {
var items = new ItemList();
items.add('discloseOnline',
SwitchInput.component({
label: 'Allow others to see when I am online',
state: this.user().preferences().discloseOnline,
onchange: (value, component) => {
this.user().pushData({lastSeenTime: null});
this.save('discloseOnline')(value, component);
}
})
);
return items;
}
notificationTypes() {
var items = new ItemList();
items.add('discussionRenamed', {
name: 'discussionRenamed',
label: 'Someone renames a discussion I started'
});
return items;
}
}