1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2026-01-17 13:39:46 +00:00

initial commit from appmail

هذا الالتزام موجود في:
Adam Cooke
2017-04-19 13:07:25 +01:00
الأصل a3eff53792
التزام 2fdba0ceb5
474 ملفات معدلة مع 51228 إضافات و0 حذوفات

عرض الملف

@@ -0,0 +1,61 @@
onStart = (event) ->
$('.flashMessage').remove()
$('input, select, textarea').blur()
$target = $(event.target)
if $target.is('form')
$('.js-form-submit', $target).addClass('is-spinning')
if $target.hasClass('button')
$($target).addClass('is-spinning')
onComplete = (event, xhr)->
$target = $(event.target)
if xhr.responseJSON
data = xhr.responseJSON
if data.redirect_to
Turbolinks.clearCache()
Turbolinks.visit(data.redirect_to, {"action":"replace"})
console.log "Redirected to #{data.redirect_to}"
if data.alert
unSpin($target)
alert(data.alert)
if data.form_errors
if $target.is('form')
unSpin($target)
handleErrors($target, data.form_errors)
if data.flash
unSpin($target)
$('body .flashMessage').remove()
for key, value of data.flash
$message = $("<div class='flashMessage flashMessage--#{key}'>#{value}</div>")
$('body').prepend($message)
if data.region_html
unSpin($target)
$('.js-ajax-region').replaceWith(data.region_html)
$('[autofocus]', '.js-ajax-region').focus()
else
console.log "Unsupported return."
unSpin = ($target)->
$target.removeClass('is-spinning')
$('.js-form-submit', $target).removeClass('is-spinning')
handleErrors = (form, errors)->
html = $("<div class='formErrors errorExplanation'><ul></ul</div>")
list = $('ul', html)
$.each errors, ->
list.append("<li>#{this}</li>")
$('.formErrors', form).remove()
form.prepend($(html))
console.log errors
$ ->
$.ajaxSettings.dataType = 'json'
$(document)
.on 'ajax:before', onStart
.on 'ajax:complete', onComplete

عرض الملف

@@ -0,0 +1,32 @@
$(document).on 'turbolinks:load', ->
mailGraph = $('.mailGraph')
if mailGraph.length
data = JSON.parse(mailGraph.attr('data-data'))
incomingMail = []
outgoingMail = []
for d in data
incomingMail.push(d.incoming)
outgoingMail.push(d.outgoing)
data =
series: [outgoingMail, incomingMail]
options =
fullWidth: true
axisY:
offset:40
axisX:
showGrid: false
offset: 0
showLabel: true
height: '230px'
showArea: true
high: if incomingMail? && incomingMail.length then undefined else 1000
chartPadding:
top:0
right:0
bottom:0
left:0
new Chartist.Line '.mailGraph__graph', data, options

عرض الملف

@@ -0,0 +1,8 @@
$ ->
$(document).on 'click', '.js-remember a', ->
$parent = $(this).parents('.js-remember')
value = $(this).attr('data-remember')
$parent.remove()
if value == 'yes'
$.post('/persist')
false

عرض الملف

@@ -0,0 +1,113 @@
ENTER = 13
DOWN_ARROW = 40
UP_ARROW = 38
filterList = ($container, query) ->
$items = getItems($container)
index = $container.data('searchifyIndex')
re = new RegExp(query, 'g')
$matches = $items.filter (i, item) ->
value = $(item).data('value')
re.test(value)
$items.addClass('is-hidden').filter($matches).removeClass('is-hidden')
toggleState($container, $matches.length > 0)
if index?
index = 0
$container.data('searchifyIndex', index)
highlightItem($container, $matches, index)
getContainer = ($el) ->
$el.closest('.js-searchable')
getEmpty = ($container) ->
$('.js-searchable__empty', $container)
getList = ($container) ->
$('.js-searchable__list', $container)
getItems = ($container) ->
$('.js-searchable__item', $container)
highlightItem = ($container, $scope, index) ->
$items = getItems($container)
$items.removeClass('is-highlighted')
$scope.eq(index).addClass('is-highlighted') if index? && $scope.length
highlightNext = ($container) ->
$matches = getMatches($container)
index = $container.data('searchifyIndex')
return unless $matches.length
if index?
return if index == $matches.length - 1
newIndex = index + 1
else
newIndex = 0
$container.data('searchifyIndex', newIndex)
highlightItem($container, $matches, newIndex)
highlightPrev = ($container) ->
$matches = getMatches($container)
index = $container.data('searchifyIndex')
return unless $matches.length
if index?
return if index == 0
newIndex = index - 1
else
newIndex = 0
$container.data('searchifyIndex', newIndex)
highlightItem($container, $matches, newIndex)
getMatches = ($container) ->
$items = getItems($container)
$items.filter(':not(.is-hidden)')
searchify = (str) ->
str.toLowerCase().replace(/\W/g, '')
selectHighlighted = ($container) ->
index = $container.data('searchifyIndex')
$matches = getMatches($container)
return unless index? && $matches.length
url = $matches.eq(index).data('url')
Turbolinks.visit(url)
showAll = ($container) ->
$items = getItems($container)
index = $container.data('searchifyIndex')
$items.removeClass('is-hidden')
toggleState($container, true)
if index?
index = 0
$container.data('searchifyIndex', index)
highlightItem($container, $items, index)
toggleState = ($container, predicate) ->
$empty = getEmpty($container)
$list = getList($container)
$empty.toggleClass('is-hidden', predicate)
$list.toggleClass('is-hidden', !predicate)
# Event Handlers
handleInput = (event) ->
$input = $(event.target)
$container = getContainer($input)
query = searchify($input.val())
if query.length then filterList($container, query) else showAll($container)
handleKeydown = (event) ->
$container = getContainer($(event.target))
keyCode = event.keyCode
if keyCode == DOWN_ARROW
event.preventDefault()
highlightNext($container)
else if keyCode == ENTER
event.preventDefault()
selectHighlighted($container)
else if keyCode == UP_ARROW
event.preventDefault()
highlightPrev($container)
$ ->
$(document)
.on('input', '.js-searchable__input', handleInput)
.on('keydown', '.js-searchable__input', handleKeydown)