login.template 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <script>
  2. {{#if key}}
  3. back();
  4. {{/if}}
  5. </script>
  6. <form id="form" style="display:none;">
  7. <input name="username" autocomplete="off" class="fill-width" placeholder="Username" id="login-username" type="text"/>
  8. <input id="login-password" class="fill-width" placeholder="Password" name="password" type="password"/>
  9. <button value="Cancel" class="danger">Cancel</button>
  10. <button value="Login" onclick="$(this).parent().submit();">Login</button>
  11. </form>
  12. <script>
  13. {{#unless key}}
  14. $(document).ready(function(){
  15. $('form#form').show().submit(function(){
  16. var data = $(this).serializeObject(),
  17. State = History.getState();
  18. for(var i in State.data){
  19. data[i] = State.data;
  20. }
  21. data.type = 'action';
  22. data.id = 'login';
  23. apiCall(data,function(d){
  24. if(!exists(d.error) && exists(d.key)){
  25. setKey(d.key);
  26. back(true);
  27. }else{
  28. setKey(null);
  29. $('#loading').hide();
  30. if(!exists(d.error)){
  31. alert('Error communicating with the server');
  32. }
  33. }
  34. return false;
  35. });
  36. return false;
  37. }).find('.danger').click(function(){
  38. back(true);
  39. return false;
  40. }).parent().find('input').keypress(function(e){
  41. if(e.which == 13){
  42. $('form#form').submit();
  43. return false;
  44. }
  45. });
  46. });
  47. {{/unless}}
  48. </script>