summaryrefslogtreecommitdiff
path: root/skins/jason/login.js
blob: 15e99c6b1e86f895faafae1ffaa6f1e8a8ca08fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * jason - Javascript based skin for xxv
 * Copyright(c) 2009-2012, anbr
 * 
 * http://projects.vdr-developer.org/projects/xxv
 *
 */

Ext.LoginPanel = function() {

    Ext.LoginPanel.superclass.constructor.call(this, {
         labelWidth:120
        ,url:'?cmd=login&ajax=json&__action=save'
        ,frame:true
        ,title:this.szTitle
        ,defaultType:'textfield'
        ,monitorValid:true
        ,items:[ {
               xtype:'box'
              ,anchor:''
              ,isFormField:false
              ,fieldLabel:''
              ,autoEl:{
                  tag:'div' 
                  ,style:'margin:0 0 0 0'
                  ,children:[{
                   tag:'img'
                  ,src:'pic/login.png'
                }]
              }
            },{ 
                fieldLabel:this.szUser
                ,name:'__name'
                ,allowBlank:false 
            },{ 
                fieldLabel:this.szPassword
                ,name:'__password'
                ,inputType:'password'
                ,allowBlank:false 
            }]
        ,buttons:[{ 
                text: this.szLogin
                ,formBind: true
                ,scope: this
                ,handler:this.onSubmit
                }]
    });
};

Ext.extend(Ext.LoginPanel, Ext.FormPanel, {
     szTitle:   'Please login'
    ,szUser:    'Username'
    ,szPassword:'Password'
    ,szLogin:   'Login'
    ,szFailed:  'Login failed!'
    ,szWarning: 'Warning!'
    ,szUnreachable: 'Authentication server is unreachable : '
    ,onSubmit:function() { 
        this.getForm().submit({ 
            method:'POST'
            ,waitTitle:Ext.form.BasicForm.prototype.waitTitle 
            ,waitMsg:Ext.LoadMask.prototype.msg
            ,scope: this
            ,success:function(){ 
                var redirect = '?cmd=n'; 
                window.location = redirect;
            }
            ,failure:function(form, action){ 
                if(action.response && action.response.status === 200 ){ 
                    var obj = Ext.util.JSON.decode(action.response.responseText);
                    Ext.Msg.show({
                       title:this.szFailed,
                       msg: obj.data,
                       buttons: Ext.Msg.CANCEL,
                       icon: Ext.MessageBox.ERROR
                    });
                }else{ 
                    if(action.failureType) {
                      switch (action.failureType) {
                          case Ext.form.Action.CLIENT_INVALID:
                              Ext.Msg.show({
                                 title:this.szWarning,
                                 msg: Ext.form.Field.prototype.invalidText,
                                 buttons: Ext.Msg.CANCEL,
                                 icon: Ext.MessageBox.ERROR
                              });
                              break;
                          case Ext.form.Action.CONNECT_FAILURE:
                              Ext.Msg.show({
                                 title:this.szWarning,
                                 msg: this.szUnreachable + action.response.statusText,
                                 buttons: Ext.Msg.CANCEL,
                                 icon: Ext.MessageBox.ERROR
                              });
                              break;
                          case Ext.form.Action.SERVER_INVALID:
                              Ext.Msg.show({
                                 title:this.szWarning,
                                 msg: action.result.msg,
                                 buttons: Ext.Msg.CANCEL,
                                 icon: Ext.MessageBox.ERROR
                              });
                              break;
                     }
                    } else {
                      Ext.Msg.show({
                         title:this.szWarning,
                         msg: this.szUnreachable + action.response.statusText,
                         buttons: Ext.Msg.CANCEL,
                         icon: Ext.MessageBox.ERROR
                      });
                    }
                } 
                this.getForm().reset(); 
            } 
        }); 
    } 
});

Ext.onReady(function(){
  Ext.QuickTips.init();

  var win = new Ext.Window({
      layout:'fit',
      width:330,
      height:220,
      closable: false,
      resizable: false,
      plain: true,
      border: false,
      items: [new Ext.LoginPanel()]
    });

  win.show();

  setTimeout(function(){
        var l = Ext.get('loading'); 
        if(l) {
          l.remove();
        }
        var m = Ext.get('loading-mask'); 
        if(m) {
          m.fadeOut({remove:true});
        }
  }, 250);
});