1
0
mirror of https://github.com/fazo96/markcloud.git synced 2025-01-10 11:04:21 +01:00
This commit is contained in:
Enrico Fasoli 2014-10-06 08:42:31 +02:00
parent 8c2ef8e59a
commit 7636cee3ec
5 changed files with 63 additions and 18 deletions

View File

@ -40,6 +40,7 @@ share.notify = notify = (opt) ->
opt.type ?= "danger"
notification.set opt
errCallback = (err) ->
return unless err
if err.reason then notify msg: err.reason else notify msg: err
Template.notifications.notification = -> notification.get()
Template.notifications.events
@ -50,13 +51,20 @@ Template.layout.showSpinner = ->
Template.home.ndocs = -> docs.find().count()
Template.new.events
'click #new-btn': (e,t) ->
id = docs.insert
if t.find('#title').value is ''
return notify msg: 'please insert a title'
if t.find('#editor').value is ''
return notify msg: "can't create empty document"
docs.insert {
title: t.find('#title').value
text: t.find('#editor').value
showTitle: $('#show-title').is(':checked')
dateCreated: moment().unix()
if id
Router.go 'doc', _id: id
else notify msg: 'document creation failed'
}, (err,id) ->
errCallback err
if id then Router.go 'doc', _id: id
Template.doc.canEdit = -> "disabled" unless Meteor.user()._id is @owner
Template.signup.events
'click #signup': (e,t) ->

View File

@ -1,6 +0,0 @@
<head>
<title>MarkCloud</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

View File

@ -19,6 +19,13 @@
}
// Editor
#title {
margin-bottom: 1em;
}
#editor {
margin-top: 1em;
}
#new-btn {
margin-top: 1em;
}

View File

@ -1,3 +1,10 @@
<head>
<title>MarkCloud</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<template name="layout">
{{> yield region="outside"}}
<div class="container">
@ -22,7 +29,8 @@
<template name="new">
<p>Write your document in <a href="https://help.github.com/articles/github-flavored-markdown/">GitHub Flavored Markdown</a> then submit it with the button. You will be redirected to its permanent link</p>
<input type="text" id="title" class="form-control" placeholder="Title">
<textarea id="editor" class="form-control" rows="10" autofocus></textarea>
<input type="checkbox" id="show-title" checked> Show title in document
<textarea id="editor" class="form-control" rows="10" placeholder="Write your markdown :)" autofocus></textarea>
<button id="new-btn" class="btn btn-primary">
<i class="fa fa-upload"></i> Upload</button>
</template>
@ -33,6 +41,7 @@
</template>
<template name="doc">
{{#if showTitle}}<h1>{{title}}</h1><hr>{{/if}}
{{#if text}}
{{#markdown}}{{text}}{{/markdown}}
{{else}}
@ -42,7 +51,24 @@
</div>
{{/if}}
<hr>
<div class="text-center">Powered by <a href="/">MarkCloud</a></div>
<div class="text-center">
{{#unless currentUser}}
<a href="/login">Log in</a> to edit and delete your documents<br>
{{/unless}}
<div class="btn-group" id="tools">
{{#if currentUser}}
<button id="edit-doc" class="btn btn-primary" {{canEdit}}>
Edit</button>
{{/if}}
<button id="clone-doc" class="btn btn-success">
Clone</button>
{{#if currentUser}}
<button id="del-doc" class="btn btn-danger">
Delete</button>
{{/if}}
</div>
<br>Powered by <a href="/">MarkCloud</a>
</div>
</template>
<template name="loading">
@ -77,19 +103,23 @@
<template name="signup">
<div id="signup-container">
<h2>Sign Up</h2>
<h2>Sign Up<a href="/"><i class="fa fa-home pull-right"></i></a></h2>
<input type="text" class="form-control" id="mail" placeholder="E-Mail Address">
<input type="password" class="form-control" placeholder="Password" id="pw">
<input type="password" class="form-control" placeholder="Repeat Password" id="rpw">
<button class="btn btn-primary" id="signup">Sign Up</button>
<hr>
<div class="text-center">Already have an account? <a href="/login">Sign in!</a></div>
</div>
</template>
<template name="signin">
<div id="signin-container">
<h2>Sign In</h2>
<h2>Sign In<a href="/"><i class="fa fa-home pull-right"></i></a></h2>
<input type="text" class="form-control" id="mail" placeholder="E-Mail Address">
<input type="password" class="form-control" placeholder="Password" id="pw">
<button class="btn btn-primary" id="signin">Sign In</button>
<hr>
<div class="text-center">Need an account? <a href="/signup">Sign Up!</a></div>
</div>
</template>

View File

@ -9,14 +9,20 @@ Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1
Meteor.publish 'docs', -> docs.find {}, fields: text: 0
Meteor.publish 'user', ->
if @userId
docs.find {_id:@userId}, fields: {dateCreated: 1}
Meteor.users.find {_id: @userId}, fields: {dateCreated: 1}
else @ready()
docs.allow
insert: (uid,doc) ->
return no unless doc.text and doc.title
if uid then doc.owner = uid; return yes
else if doc.owner then return no
if doc.text and doc.title
doc.dateCreated = moment().unix()
if doc.owner and !uid then return no
if uid then doc.owner = uid
console.log 'ok'
return yes
console.log 'nope'
return no
docs.allow
# Owners can update and remove their documents
update: (uid,doc) -> doc.owner is uid
remove: (uid,doc) -> doc.owner is uid