Skip to content

Commit

Permalink
Save in LocalStorage last connection
Browse files Browse the repository at this point in the history
  • Loading branch information
soyjavi committed Nov 10, 2014
1 parent 8eaa692 commit 20789da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion source/zen.init.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"use strict"

$ ->
console.log "last connection", ZEN.storage.get()

instance = ZEN.storage.get()
if instance
$("input[name=host]").val instance.host
$("input[name=port]").val instance.port
$("input[name=password]").val instance.password

ZEN.proxy("POST", "http://localhost:1337/api").then (error, response) ->
console.log "POST", error, response
Expand All @@ -21,11 +28,12 @@ $ ->
date : moment($("input[name=date]").val()).format("YYYYMMDD")

if ZEN.instance.host and ZEN.instance.password and ZEN.instance.date
ZEN.storage.set ZEN.instance
$(document.body).removeClass "landing"
ZEN.process.get()
ZEN.request.get()

$("header > form > button.connect").on "click", (event) ->
event.preventDefault()
event.stopPropagation()
$(document.body).addClass "landing"
$(document.body).remove "landing"
14 changes: 14 additions & 0 deletions source/zen.storage.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict"

ZEN.storage = do ->

KEY = "zen"

_get = ->
JSON.parse window.localStorage.getItem KEY

_set = (instance) ->
window.localStorage.setItem KEY, JSON.stringify instance

get: _get
set: _set
4 changes: 2 additions & 2 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<header>
<h1 class="logo"><span class="color theme">ZEN</span>.monitor</h1>
<form>
<input type="text" name="host" placeholder="IP or address" value="http://appnima.com" required />
<input type="text" name="host" placeholder="IP or address" required />
<input type="number" name="port" placeholder="Port" maxlength="5" value="" />
<input type="password" name="password" placeholder="Password" value="as09dasdjKalsd9" required/>
<input type="password" name="password" placeholder="Password" required/>
<input type="date" name="date" required/>
<button class="connect">START</button>
<button class="disconnect">DISCONNECT</button>
Expand Down

0 comments on commit 20789da

Please sign in to comment.