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
mrt:moment
reactive-var
kevohagan:sweetalert

View File

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

View File

@ -17,7 +17,10 @@ docController = RouteController.extend
waitOn: -> Meteor.subscribe 'doc', @params._id
data: -> docs.findOne @params._id
action: ->
if @ready() then @render()
console.log @render
if @ready()
if @data()? then @render()
else @render '404'
else @render 'loading'
loggedOutController = RouteController.extend
@ -65,8 +68,6 @@ Router.map ->
if !@data() then @render '404'
else if @ready() then @render()
else @render 'loading'
@route 'delete',
controller: loggedInController
@route 'new', template: 'editor'
@route 'signup',
controller: loggedOutController
@ -75,32 +76,34 @@ Router.map ->
controller: loggedOutController
@route '404', path: '*'
notification = new ReactiveVar()
share.notify = notify = (opt) ->
if !opt then notification.set undefined
else
opt.type ?= "danger"
notification.set opt
if opt.type? then type = opt.type
else type = 'error'
if opt.title? then title = opt.title
else title = if type is 'error' then 'Error' else 'Ok'
swal title, opt.msg, type
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
'click .close': -> notify()
console.log err
if err.reason
notify title: err.code or 'Error', msg: err.reason, type: 'error'
else notify title: 'Error', msg: err, type: 'error'
Template.layout.notHome = -> Router.current().route.name isnt 'home'
Template.layout.showSpinner = ->
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.showTitleChecked = -> return "checked" unless @showTitle is no
Template.editor.events
'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 ''
return notify msg: 'please insert a title'
return notify msg: 'Please insert a title.'
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: {
title: t.find('#title').value
text: t.find('#editor').value
@ -109,7 +112,7 @@ Template.editor.events
}, (err) =>
if err then errCallback err
else
notify type:'success', msg:'Document updated'
notify type:'success', msg:'Document updated.'
Router.go 'doc', _id: @_id
else docs.insert {
title: t.find('#title').value
@ -118,7 +121,7 @@ Template.editor.events
public: $('#make-public').is(':checked')
}, (err,id) ->
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
Template.profile.isMe = ->
@ -132,15 +135,19 @@ Template.profile.events
if e then errCallback e
else notify msg: r, type:'success'
'click #logout': -> Meteor.logout(); Router.go 'home'
Template.delete.events
'click #del-account': (e,t) ->
if t.find('#name').value is Meteor.user()._id
Meteor.call 'deleteMe'
'click #deleteme': -> swal {
title: 'Are you sure?'
text: 'Do you want to permanently delete all your data?'
type: 'warning'
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.rows = -> ""+@text.split('\n').length
Template.doc.valid = -> @text?
Template.doc.owned = -> Meteor.user()._id is @owner
Template.doc.expirationDays = ->
if @owner then return 'never'
@ -149,7 +156,14 @@ Template.doc.events
'click #edit-doc': -> Router.go 'edit', _id: @_id
'click #del-doc': ->
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
else notify type:'success', msg:'Document removed'
'click #src-doc': ->

View File

@ -37,7 +37,6 @@
{{/if}}
</h1>
<hr>
{{> notifications}}
{{> yield}}
</div>
</template>
@ -98,25 +97,12 @@ You will be able to delete your account and all your data whenever you want.
</template>
<template name="doc">
{{#if valid}}
{{#if showTitle}}<h1>{{title}}</h1><hr>{{/if}}
<div class="notification-area">
{{> notifications}}
</div>
{{#if source}}
<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}}
{{#if showTitle}}<h1>{{title}}</h1><hr>{{/if}}
{{#if source}}
<textarea id="src" class="form-control" rows="{{rows}}" readonly>{{text}}</textarea>
{{else}}
<div id="doc">{{#markdown}}{{text}}{{/markdown}}</div>
{{/if}}
<hr>
<div class="text-center">
{{#unless currentUser}}
@ -171,17 +157,6 @@ You will be able to delete your account and all your data whenever you want.
</div>
</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">
<div id="signup-container">
<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">
<i class="fa fa-file-text"></i> New Document</a>
{{/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>
</div>
{{else}}