Skip to content

Commit

Permalink
1.添加设置组件 2.修改路由部分关于验证的实现 3.form onSubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
TeemoWan committed Feb 29, 2016
1 parent 34bd27f commit 59dd0f1
Show file tree
Hide file tree
Showing 34 changed files with 286 additions and 84 deletions.
6 changes: 5 additions & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ ecmascript
accounts-password
alanning:roles
flemay:less-autoprefixer
dburles:collection-helpers
stylus
semantic:ui
standard-minifier-css
Expand All @@ -27,3 +26,8 @@ kadira:dochead
meteorhacks:subs-manager
aldeed:collection2
kadira:flow-router-ssr
jagi:astronomy
jagi:astronomy-slug-behavior
jagi:astronomy-timestamp-behavior
jagi:astronomy-validators
email
6 changes: 5 additions & 1 deletion .meteor/versions
2 changes: 2 additions & 0 deletions app/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import authModule from './modules/auth';
import teamModule from './modules/team';
import documentModule from './modules/document';
import searchModule from './modules/search';
import settingsModule from './modules/settings';

// init context
const context = initContext();
Expand All @@ -20,4 +21,5 @@ app.loadModule(authModule);
app.loadModule(teamModule);
app.loadModule(documentModule);
app.loadModule(searchModule);
app.loadModule(settingsModule);
app.init();
14 changes: 8 additions & 6 deletions app/modules/auth/components/forgot_password.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ const ForgotPassword = React.createClass({
<div className='column'>
<h2 className='ui teal image header'>
<img src='/images/logo.png' className='image'/>
<div className='content'>
找回密码
</div>
<div className='content'>找回密码</div>
</h2>
<form className='ui large form'>
<form className='ui large form' onSubmit={this.handleSubmit}>
<div className='ui segment'>
<div className='field'>
<div className='ui left icon input'>
<i className='mail icon'/>
<input type='text' name='email' placeholder='邮箱' onKeyDown={this.handleEmailEnterKeyDown}/>
</div>
</div>
<div className='ui fluid large teal submit button' onClick={this.handleSubmit}>找回密码</div>
<div className='ui fluid large teal submit button'>找回密码</div>
</div>
{error && <div className='ui error message'><p>{error}</p></div>}
</form>
Expand All @@ -43,7 +41,11 @@ const ForgotPassword = React.createClass({
}
},

handleSubmit() {
handleSubmit(event) {
if (event && event.preventDefault) {
event.preventDefault();
}

const {forgotPassword} = this.props;
const {email} = this.refs;

Expand Down
14 changes: 8 additions & 6 deletions app/modules/auth/components/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const Login = React.createClass({
<div className='column'>
<h2 className='ui teal image header'>
<img src='/images/logo.png' className='image'/>
<div className='content'>
登录文字工匠
</div>
<div className='content'>登录文字工匠</div>
</h2>
<form className={classNames('ui', 'large', 'form', {error: Boolean(error)})}>
<form className={classNames('ui', 'large', 'form', {error: Boolean(error)})} onSubmit={this.handleSubmit}>
<div className='ui segment'>
<div className='field'>
<div className='ui left icon input'>
Expand All @@ -33,7 +31,7 @@ const Login = React.createClass({
</div>
{processing ?
<div className='ui fluid large loading button'>&nbsp;</div> :
<div className='ui fluid large teal button' onClick={this.handleSubmit}>登录</div>}
<div className='ui fluid large teal button'>登录</div>}
</div>
{error && <div className='ui error message'><p>{error}</p></div>}
</form>
Expand All @@ -59,7 +57,11 @@ const Login = React.createClass({
}
},

handleSubmit() {
handleSubmit(event) {
if (event && event.preventDefault) {
event.preventDefault();
}

const {login} = this.props;
const {email, password} = this.refs;

Expand Down
14 changes: 8 additions & 6 deletions app/modules/auth/components/register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ const Register = React.createClass({
<div className='column'>
<h2 className='ui teal image header'>
<img src='/images/logo.png' className='image'/>
<div className='content'>
注册文字工匠
</div>
<div className='content'>注册文字工匠</div>
</h2>

<form className={classNames('ui', 'large', 'form', {error: Boolean(error)})}>
<form className={classNames('ui', 'large', 'form', {error: Boolean(error)})} onSubmit={this.handleSubmit}>
<div className='ui segment'>
<div className='field'>
<div className='ui left icon input'>
Expand All @@ -41,7 +39,7 @@ const Register = React.createClass({
</div>
{processing ?
<div className='ui fluid large loading button'>&nbsp;</div> :
<div className='ui fluid large teal button' onClick={this.handleSubmit}>注册</div>}
<div className='ui fluid large teal button'>注册</div>}
</div>
{error && <div className='ui error message'><p>{error}</p></div>}
</form>
Expand Down Expand Up @@ -74,7 +72,11 @@ const Register = React.createClass({
}
},

handleSubmit() {
handleSubmit(event) {
if (event && event.preventDefault) {
event.preventDefault();
}

const {register} = this.props;
const {email, username, password} = this.refs;

Expand Down
3 changes: 2 additions & 1 deletion app/modules/core/components/nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Nav = React.createClass({
const teamAddPath = FlowRouter.path('team.add');
const loginPath = FlowRouter.path('auth.login');
const userHomePath = user ? FlowRouter.path('user.home', {id: user._id}) : '';
const settingsDomainPath = FlowRouter.path('settings.domain');

return (
<div className='ui borderless menu' id='nav'>
Expand Down Expand Up @@ -85,7 +86,7 @@ const Nav = React.createClass({
<a className='item' href={userHomePath}>
<i className='home icon'/> 主页
</a>
<a className='item'>
<a className='item' href={settingsDomainPath}>
<i className='setting icon'/> 设置
</a>
<div className='divider'></div>
Expand Down
76 changes: 48 additions & 28 deletions app/modules/core/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import NotFound from './containers/not_found.js';
import Login from '/app/modules/auth/containers/login';
import Register from '/app/modules/auth/containers/register';
import ForgotPassword from '/app/modules/auth/containers/forgot_password';
import UserHome from '/app/modules/user/containers/user_home';
import TeamHome from '/app/modules/team/containers/team_home';
import TeamAdd from '/app/modules/team/containers/team_add';
import DocumentHome from '/app/modules/document/containers/document_home';
import DocumentIndex from '/app/modules/document/containers/document_index';
import DocumentAdd from '/app/modules/document/containers/document_add';
import DocumentEdit from '/app/modules/document/containers/document_edit';
import Search from '/app/modules/search/containers/search';
import UserHome from '/app/modules/user/containers/user_home';
import SettingsDomain from '/app/modules/settings/containers/settings_domain';

const mountWithOptions = withOptions({
rootId: 'wenzi'
Expand All @@ -25,18 +26,6 @@ export default function (injectDeps, {FlowRouter, Meteor}) {
const LayoutNavContentCtx = injectDeps(LayoutNavContent);
const LayoutContentCtx = injectDeps(LayoutContent);

const checkLoggedIn = () => {
if (!Meteor.loggingIn() && !Meteor.userId()) {
FlowRouter.go('/login');
}
};

const redirectIfLoggedIn = (ctx, redirect) => {
if (Meteor.userId()) {
redirect('/');
}
};

FlowRouter.route('/', {
name: 'home',
action: () => {
Expand All @@ -48,8 +37,11 @@ export default function (injectDeps, {FlowRouter, Meteor}) {

FlowRouter.route('/login', {
name: 'auth.login',
triggersEnter: [ redirectIfLoggedIn ],
action: () => {
if (Meteor.userId()) {
FlowRouter.go('/');
}

mountWithOptions(LayoutContentCtx, {
content: () => (<Login />)
});
Expand All @@ -58,8 +50,11 @@ export default function (injectDeps, {FlowRouter, Meteor}) {

FlowRouter.route('/register', {
name: 'auth.register',
triggersEnter: [ redirectIfLoggedIn ],
action: () => {
if (Meteor.userId()) {
FlowRouter.go('/');
}

mountWithOptions(LayoutContentCtx, {
content: () => (<Register />)
});
Expand All @@ -68,27 +63,24 @@ export default function (injectDeps, {FlowRouter, Meteor}) {

FlowRouter.route('/forgotPassword', {
name: 'auth.forgotPassword',
triggersEnter: [ redirectIfLoggedIn ],
action: () => {
if (Meteor.userId()) {
FlowRouter.go('/');
}

mountWithOptions(LayoutContentCtx, {
content: () => (<ForgotPassword />)
});
}
});

FlowRouter.route('/user/:id', {
name: 'user.home',
action: ({id}) => {
mountWithOptions(LayoutNavContentCtx, {
content: () => (<UserHome userId={id}/>)
});
}
});

FlowRouter.route('/team/add', {
name: 'team.add',
triggersEnter: [ checkLoggedIn ],
action: () => {
if (!Meteor.userId()) {
FlowRouter.go('/login');
}

mountWithOptions(LayoutNavContentCtx, {
content: () => (<TeamAdd />)
});
Expand All @@ -115,8 +107,11 @@ export default function (injectDeps, {FlowRouter, Meteor}) {

FlowRouter.route('/document/add', {
name: 'document.add',
triggersEnter: [ checkLoggedIn ],
action: () => {
if (!Meteor.userId()) {
FlowRouter.go('/login');
}

mountWithOptions(LayoutNavContentCtx, {
content: () => (<DocumentAdd />)
});
Expand All @@ -134,8 +129,11 @@ export default function (injectDeps, {FlowRouter, Meteor}) {

FlowRouter.route('/document/:id/edit', {
name: 'document.edit',
triggersEnter: [ checkLoggedIn ],
action: ({id}) => {
if (!Meteor.userId()) {
FlowRouter.go('/login');
}

mountWithOptions(LayoutContentCtx, {
content: () => (<DocumentEdit documentId={id}/>)
});
Expand All @@ -151,6 +149,28 @@ export default function (injectDeps, {FlowRouter, Meteor}) {
}
});

FlowRouter.route('/user/:id', {
name: 'user.home',
action: ({id}) => {
mountWithOptions(LayoutNavContentCtx, {
content: () => (<UserHome userId={id}/>)
});
}
});

FlowRouter.route('/settings/domain', {
name: 'settings.domain',
action: () => {
if (!Meteor.userId()) {
FlowRouter.go('/login');
}

mountWithOptions(LayoutNavContentCtx, {
content: () => (<SettingsDomain/>)
});
}
});

FlowRouter.notFound = {
action: () => {
mountWithOptions(LayoutNavContentCtx, {
Expand Down
12 changes: 8 additions & 4 deletions app/modules/document/components/document_add.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const DocumentAdd = React.createClass({
<div className='ui grid' id='doc-add'>
<div className='two wide column'></div>
<div className='twelve wide column'>
<form className={classNames('ui', 'form', {error: Boolean(error)})}>
<form className={classNames('ui', 'form', {error: Boolean(error)})} onSubmit={this.handleSubmit}>
<h2 className='ui dividing header'>添加文档</h2>
{error && <div className='ui error message'><p>{error}</p></div>}
<div className='fields'>
Expand All @@ -72,16 +72,20 @@ const DocumentAdd = React.createClass({
<textarea ref='summary' placeholder='文档简介...' />
</div>
{processing ?
<div className='ui teal loading disabled button'></div> :
<div className='ui teal button' onClick={this.handleSubmit}>添加文档</div>}
<div className='ui teal loading disabled button'>&nbsp;</div> :
<div className='ui teal button'>添加文档</div>}
</form>
</div>
<div className='two wide column'></div>
</div>
);
},

handleSubmit() {
handleSubmit(event) {
if (event && event.preventDefault) {
event.preventDefault();
}

const {documentAdd} = this.props;
const {owner, name, summary} = this.refs;
const [ ownerType, ownerId ] = owner.value.split(':');
Expand Down
7 changes: 7 additions & 0 deletions app/modules/document/containers/document_add.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useDeps, composeWithTracker, composeAll} from 'mantra-core';
import {DocHead} from 'meteor/kadira:dochead';
import Loading from '/app/modules/core/components/loading.jsx';
import DocumentAdd from '../components/document_add.jsx';

Expand All @@ -10,6 +11,12 @@ const composer = ({Collections, WenziSubs, LocalState, clearDocumentAdd}, onData
let teams = Collections.Teams.find({admins: Meteor.userId()}).fetch();

onData(null, {error, processing, user, teams});

// SEO
DocHead.setTitle('添加文档');
DocHead.addMeta({
name: 'description', content: '添加文档'
});
}

return clearDocumentAdd;
Expand Down
7 changes: 7 additions & 0 deletions app/modules/settings/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import settings from './settings';

const actions = {
settings
};

export default actions;
Loading

0 comments on commit 59dd0f1

Please sign in to comment.