1
0
mirror of https://github.com/fazo96/markcloud.git synced 2025-01-10 11:04:21 +01:00

added sweetalert

This commit is contained in:
Enrico Fasoli 2014-10-08 15:44:24 +02:00
parent 4a73498e54
commit 8b2522a9ee
4 changed files with 48 additions and 57 deletions

View File

@ -13,4 +13,5 @@ natestrauser:font-awesome
accounts-password accounts-password
mrt:moment mrt:moment
reactive-var reactive-var
kevohagan:sweetalert

View File

@ -29,6 +29,7 @@ iron:layout@0.4.1
iron:router@0.9.4 iron:router@0.9.4
jquery@1.0.0 jquery@1.0.0
json@1.0.0 json@1.0.0
kevohagan:sweetalert@0.0.1
less@1.0.9 less@1.0.9
livedata@1.0.10 livedata@1.0.10
localstorage@1.0.0 localstorage@1.0.0

View File

@ -17,7 +17,10 @@ docController = RouteController.extend
waitOn: -> Meteor.subscribe 'doc', @params._id waitOn: -> Meteor.subscribe 'doc', @params._id
data: -> docs.findOne @params._id data: -> docs.findOne @params._id
action: -> action: ->
if @ready() then @render() console.log @render
if @ready()
if @data()? then @render()
else @render '404'
else @render 'loading' else @render 'loading'
loggedOutController = RouteController.extend loggedOutController = RouteController.extend
@ -65,8 +68,6 @@ Router.map ->
if !@data() then @render '404' if !@data() then @render '404'
else if @ready() then @render() else if @ready() then @render()
else @render 'loading' else @render 'loading'
@route 'delete',
controller: loggedInController
@route 'new', template: 'editor' @route 'new', template: 'editor'
@route 'signup', @route 'signup',
controller: loggedOutController controller: loggedOutController
@ -75,32 +76,34 @@ Router.map ->
controller: loggedOutController controller: loggedOutController
@route '404', path: '*' @route '404', path: '*'
notification = new ReactiveVar()
share.notify = notify = (opt) -> share.notify = notify = (opt) ->
if !opt then notification.set undefined if opt.type? then type = opt.type
else else type = 'error'
opt.type ?= "danger" if opt.title? then title = opt.title
notification.set opt else title = if type is 'error' then 'Error' else 'Ok'
swal title, opt.msg, type
errCallback = (err) -> errCallback = (err) ->
return unless err return unless err
if err.reason then notify msg: err.reason else notify msg: err console.log err
Template.notifications.notification = -> notification.get() if err.reason
Template.notifications.events notify title: err.code or 'Error', msg: err.reason, type: 'error'
'click .close': -> notify() else notify title: 'Error', msg: err, type: 'error'
Template.layout.notHome = -> Router.current().route.name isnt 'home' Template.layout.notHome = -> Router.current().route.name isnt 'home'
Template.layout.showSpinner = -> Template.layout.showSpinner = ->
Meteor.status().connected is no or Router.current().ready() is no Meteor.status().connected is no or Router.current().ready() is no
Template.home.rendered = ->
$('.ttip').tooltip()
Template.editor.isPublic = -> return "checked" if @public is yes Template.editor.isPublic = -> return "checked" if @public is yes
Template.editor.showTitleChecked = -> return "checked" unless @showTitle is no Template.editor.showTitleChecked = -> return "checked" unless @showTitle is no
Template.editor.events Template.editor.events
'click #upload': (e,t) -> 'click #upload': (e,t) ->
if Meteor.loggingIn()
return notify
msg: "Can't upload while Logging In.\nTry again in a few seconds."
if t.find('#title').value is '' if t.find('#title').value is ''
return notify msg: 'please insert a title' return notify msg: 'Please insert a title.'
if t.find('#editor').value is '' if t.find('#editor').value is ''
return notify msg: "empty documents are not valid" return notify msg: "Empty documents are not valid."
if @_id then docs.update @_id, $set: { if @_id then docs.update @_id, $set: {
title: t.find('#title').value title: t.find('#title').value
text: t.find('#editor').value text: t.find('#editor').value
@ -109,7 +112,7 @@ Template.editor.events
}, (err) => }, (err) =>
if err then errCallback err if err then errCallback err
else else
notify type:'success', msg:'Document updated' notify type:'success', msg:'Document updated.'
Router.go 'doc', _id: @_id Router.go 'doc', _id: @_id
else docs.insert { else docs.insert {
title: t.find('#title').value title: t.find('#title').value
@ -118,7 +121,7 @@ Template.editor.events
public: $('#make-public').is(':checked') public: $('#make-public').is(':checked')
}, (err,id) -> }, (err,id) ->
if err then errCallback err if err then errCallback err
else notify type:'success', msg:'Document created successfully' else notify type:'success', msg:'Document created successfully!'
if id then Router.go 'doc', _id: id if id then Router.go 'doc', _id: id
Template.profile.isMe = -> Template.profile.isMe = ->
@ -132,15 +135,19 @@ Template.profile.events
if e then errCallback e if e then errCallback e
else notify msg: r, type:'success' else notify msg: r, type:'success'
'click #logout': -> Meteor.logout(); Router.go 'home' 'click #logout': -> Meteor.logout(); Router.go 'home'
'click #deleteme': -> swal {
Template.delete.events title: 'Are you sure?'
'click #del-account': (e,t) -> text: 'Do you want to permanently delete all your data?'
if t.find('#name').value is Meteor.user()._id type: 'warning'
Meteor.call 'deleteMe' showCancelButton: yes
confirmButtonColor: "#DD6B55"
confirmButtonText: "Yes!"
}, -> Meteor.call 'deleteMe', (e,r) ->
if e then errCallback e
else notify type: 'success', msg: 'Account deleted'
Template.doc.source = -> Router.current().route.name is 'src' Template.doc.source = -> Router.current().route.name is 'src'
Template.doc.rows = -> ""+@text.split('\n').length Template.doc.rows = -> ""+@text.split('\n').length
Template.doc.valid = -> @text?
Template.doc.owned = -> Meteor.user()._id is @owner Template.doc.owned = -> Meteor.user()._id is @owner
Template.doc.expirationDays = -> Template.doc.expirationDays = ->
if @owner then return 'never' if @owner then return 'never'
@ -149,7 +156,14 @@ Template.doc.events
'click #edit-doc': -> Router.go 'edit', _id: @_id 'click #edit-doc': -> Router.go 'edit', _id: @_id
'click #del-doc': -> 'click #del-doc': ->
if Meteor.user()._id is @owner if Meteor.user()._id is @owner
docs.remove @_id, (err) -> swal {
title: 'Are you sure?'
text: 'This document will be deleted permanently'
type: 'warning'
showCancelButton: yes
confirmButtonColor: "#DD6B55"
confirmButtonText: "Yes!"
}, => docs.remove @_id, (err) ->
if err then errCallback err if err then errCallback err
else notify type:'success', msg:'Document removed' else notify type:'success', msg:'Document removed'
'click #src-doc': -> 'click #src-doc': ->

View File

@ -37,7 +37,6 @@
{{/if}} {{/if}}
</h1> </h1>
<hr> <hr>
{{> notifications}}
{{> yield}} {{> yield}}
</div> </div>
</template> </template>
@ -98,25 +97,12 @@ You will be able to delete your account and all your data whenever you want.
</template> </template>
<template name="doc"> <template name="doc">
{{#if valid}} {{#if showTitle}}<h1>{{title}}</h1><hr>{{/if}}
{{#if showTitle}}<h1>{{title}}</h1><hr>{{/if}} {{#if source}}
<div class="notification-area"> <textarea id="src" class="form-control" rows="{{rows}}" readonly>{{text}}</textarea>
{{> notifications}} {{else}}
</div> <div id="doc">{{#markdown}}{{text}}{{/markdown}}</div>
{{#if source}} {{/if}}
<textarea id="src" class="form-control" rows="{{rows}}" readonly>{{text}}</textarea>
{{else}}
<div id="doc">{{#markdown}}{{text}}{{/markdown}}</div>
{{/if}}
{{else}}
<div class="text-center">
<h1>404</h1>
<div class="notification-area">
{{> notifications}}
</div>
<p>This document is invalid, expired, never existed or was deleted.</p>
</div>
{{/if}}
<hr> <hr>
<div class="text-center"> <div class="text-center">
{{#unless currentUser}} {{#unless currentUser}}
@ -171,17 +157,6 @@ You will be able to delete your account and all your data whenever you want.
</div> </div>
</template> </template>
<template name="notifications">
{{#if notification}}
<div class="center-block text-center">
<div class="alert alert-{{notification.type}} error">
<p align="center">{{notification.msg}}</p>
<button type="button" class="close close-error">&times;</button>
</div>
</div>
{{/if}}
</template>
<template name="signup"> <template name="signup">
<div id="signup-container"> <div id="signup-container">
<h2>Sign Up</h2> <h2>Sign Up</h2>
@ -229,7 +204,7 @@ You will be able to delete your account and all your data whenever you want.
<a class="btn btn-success" href="/new"> <a class="btn btn-success" href="/new">
<i class="fa fa-file-text"></i> New Document</a> <i class="fa fa-file-text"></i> New Document</a>
{{/if}} {{/if}}
<a class="btn btn-danger" href="/delete"> <a class="btn btn-danger" id="deleteme">
<i class="fa fa-exclamation-circle"></i> Delete Account</a> <i class="fa fa-exclamation-circle"></i> Delete Account</a>
</div> </div>
{{else}} {{else}}