Skip to content

Commit 43dffa3

Browse files
committed
User page functionality merger (80%)
1 parent 2b06ef5 commit 43dffa3

File tree

11 files changed

+826
-208
lines changed

11 files changed

+826
-208
lines changed

web/js/__init__.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
$(document).ready(function(){
22
try{
3-
App.Utils.detectBrowser();
4-
5-
App.Env.world = 'DNS';
6-
App.Pages.init();
7-
8-
App.Ref.init();
3+
App.Utils.detectBrowser();
4+
5+
App.Env.world = 'USER';
6+
App.Pages.init();
97

10-
//App.View.start();
11-
App.Core.listen();
12-
App.Core.initMenu();
13-
App.Helpers.liveValidate();
8+
App.Ref.init();
9+
10+
//App.View.start();
11+
App.Core.listen();
12+
App.Core.initMenu();
13+
App.Helpers.liveValidate();
1414

1515
}catch(e){
1616
fb.error(e);

web/js/_settings.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ App.i18n.getMessage = function(key)
1010

1111

1212
// Constants
13-
App.Constants.IP_FORM_ID = 'ip-form';
14-
App.Constants.DNS_FORM_ID = 'dns-form';
13+
App.Constants.IP_FORM_ID = 'ip-form';
14+
App.Constants.DNS_FORM_ID = 'dns-form';
15+
App.Constants.USER_FORM_ID = 'user-form';
1516

1617
App.Settings.ajax_url = 1;
1718
App.Settings.uri = location.href.replace('index.html', '');
@@ -59,4 +60,4 @@ App.Settings.getMethodName = function(action)
5960
}
6061

6162
return type + '.' + method;
62-
}
63+
}

web/js/actions.js

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
/*App.Actions.cancel_ip_form = function(){
2-
alert(1);
3-
}*/
1+
App.Actions.delete_entry = function(evt)
2+
{
3+
var confirmed = confirm(App.i18n.getMessage('confirm'));
4+
if (!confirmed) {
5+
return;
6+
}
7+
var elm = $(evt.target);
8+
var elm = elm.hasClass('row') ? elm : elm.parents('.row');
9+
App.Model.remove(App.Env.world, elm);
10+
}
411

512
App.Actions.show_subform = function(evt)
613
{
@@ -81,32 +88,47 @@ App.Actions.save_form = function(evt) {
8188
var elm_id = App.Env.world + '_FORM_ID';
8289
var build_method = App.Env.getWorldName() + '_entry';
8390

91+
if (!App.Validate.form(App.Env.world, elm)) {
92+
return App.Validate.displayFormErrors(App.Env.world, elm);
93+
}
94+
8495
if (elm.attr('id') == App.Constants[elm_id]) { // NEW ITEM
8596
var values = App.Helpers.getFormValues(elm);
8697
if(App.Validate.form(values, $('#'+elm_id))) {
8798
App.Model.add(values, source);
88-
var tpl = App.HTML.Build[build_method](values, 'new');
89-
$('#' + App.Constants[elm_id]).replaceWith(tpl);
99+
var form_id = App.Constants[App.Env.world + '_FORM_ID'];
100+
$('#'+form_id).remove();
90101
}
91102
}
92103
else { // OLD ITEM, UPDATING IT
93104
var source = $(elm).find('.source').val();
94105
var values = App.Helpers.getFormValues(elm);
95106
if(App.Validate.form(values, $('#'+elm_id))) {
96-
App.Model.update(values, source);
97-
var tpl = App.HTML.Build[build_method](values);
98-
elm.replaceWith(tpl);
107+
App.Model.add(values, source);
108+
//var form_id = App.Constants[App.Env.world + '_FORM_ID'];
109+
//$('#'+form_id).remove();
110+
App.Model.update(values, source, elm);
99111
}
100-
}
101-
App.Helpers.updateScreen();
112+
/*if(App.Validate.form(values, $('#'+elm_id))) {
113+
App.Model.update(values, source);
114+
}*/
115+
}
102116
}
103117

104118
// do_action_edit
105119
App.Actions.edit = function(evt) {
106120
var elm = $(evt.target);
107121
elm = elm.hasClass('row') ? elm : elm.parents('.row');
108-
App.Pages[App.Env.world].edit(elm);
109-
App.Helpers.updateScreen();
122+
123+
var options = elm.find('.source').val();
124+
fb.warn(elm);
125+
fb.warn(options);
126+
var build_method = App.Env.getWorldName() + '_form';
127+
var tpl = App.HTML.Build[build_method](options);
128+
elm.replaceWith(tpl);
129+
130+
//App.Pages[App.Env.world].edit(elm);
131+
//App.Helpers.updateScreen();
110132
}
111133

112134
// do_cancel_form
@@ -160,4 +182,9 @@ App.Actions.save_dns_subrecords = function(evt)
160182
});
161183

162184
fb.warn($.toJSON(records));
163-
}
185+
}
186+
187+
App.Actions.generate_pass = function()
188+
{
189+
$('.password').val(App.Helpers.generatePassword());
190+
}

web/js/app.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
var _DEBUG = true;
22

3+
window.jsonParse=function(){var r="(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)",k='(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))';k='(?:"'+k+'*")';var s=new RegExp("(?:false|true|null|[\\{\\}\\[\\]]|"+r+"|"+k+")","g"),t=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),u={'"':'"',"/":"/","\\":"\\",b:"\u0008",f:"\u000c",n:"\n",r:"\r",t:"\t"};function v(h,j,e){return j?u[j]:String.fromCharCode(parseInt(e,16))}var w=new String(""),x=Object.hasOwnProperty;return function(h,
4+
j){h=h.match(s);var e,c=h[0],l=false;if("{"===c)e={};else if("["===c)e=[];else{e=[];l=true}for(var b,d=[e],m=1-l,y=h.length;m<y;++m){c=h[m];var a;switch(c.charCodeAt(0)){default:a=d[0];a[b||a.length]=+c;b=void 0;break;case 34:c=c.substring(1,c.length-1);if(c.indexOf("\\")!==-1)c=c.replace(t,v);a=d[0];if(!b)if(a instanceof Array)b=a.length;else{b=c||w;break}a[b]=c;b=void 0;break;case 91:a=d[0];d.unshift(a[b||a.length]=[]);b=void 0;break;case 93:d.shift();break;case 102:a=d[0];a[b||a.length]=false;
5+
b=void 0;break;case 110:a=d[0];a[b||a.length]=null;b=void 0;break;case 116:a=d[0];a[b||a.length]=true;b=void 0;break;case 123:a=d[0];d.unshift(a[b||a.length]={});b=void 0;break;case 125:d.shift();break}}if(l){if(d.length!==1)throw new Error;e=e[0]}else if(d.length)throw new Error;if(j){var p=function(n,o){var f=n[o];if(f&&typeof f==="object"){var i=null;for(var g in f)if(x.call(f,g)&&f!==n){var q=p(f,g);if(q!==void 0)f[g]=q;else{i||(i=[]);i.push(g)}}if(i)for(g=i.length;--g>=0;)delete f[i[g]]}return j.call(n,
6+
o,f)};e=p({"":e},"")}return e}}();
7+
38

49
(function($){$.toJSON=function(o)
510
{if(typeof(JSON)=='object'&&JSON.stringify)
@@ -86,7 +91,7 @@ var App = {
8691
// pages related views
8792
Pages: {
8893
USER: {},
89-
WEBDOMAIN: {},
94+
WEB_DOMAIN: {},
9095
MAIL: {},
9196
DB: {},
9297
DNS: {},
@@ -97,7 +102,7 @@ var App = {
97102
Messages: {},
98103
Model: {
99104
USER: {},
100-
WEBDOMAIN: {},
105+
WEB_DOMAIN: {},
101106
MAIL: {},
102107
DB: {},
103108
DNS: {},
@@ -109,7 +114,7 @@ var App = {
109114
},
110115
Pages: {
111116
USER: {},
112-
WEBDOMAIN: {},
117+
WEB_DOMAIN: {},
113118
MAIL: {},
114119
DB: {},
115120
DNS: {},
@@ -119,8 +124,10 @@ var App = {
119124
Ref: {},
120125
Tmp: {},
121126
Thread: {
122-
run: function(delay, ref){
123-
setTimeout(function(){
127+
run: function(delay, ref)
128+
{
129+
setTimeout(function()
130+
{
124131
ref();
125132
}, delay*10);
126133
}
@@ -136,31 +143,36 @@ var App = {
136143
};
137144

138145
// Internals
139-
Array.prototype.set = function(key, value){
146+
Array.prototype.set = function(key, value)
147+
{
140148
var index = this[0][key];
141149
this[1][index] = value;
142150
}
143151
Array.prototype.get = function(key){
144152
var index = this[0][key];
145153
return this[1][index];
146154
}
147-
Array.prototype.finalize = function(){
155+
Array.prototype.finalize = function()
156+
{
148157
this.shift();
149158
this[0] = this[0].join('');
150159
return this[0];
151160
}
152-
Array.prototype.done = function(){
161+
Array.prototype.done = function()
162+
{
153163
return this.join('');
154164
}
155165

156-
String.prototype.wrapperize = function(key, ns){
166+
String.prototype.wrapperize = function(key, ns)
167+
{
157168
var tpl = App.Templates.get(key, ns);
158169
tpl.set(':content', this);
159170

160171
return tpl.finalize();
161172
}
162173

163-
App.Ajax.request = function(jedi_method, data, callback){
174+
App.Ajax.request = function(jedi_method, data, callback)
175+
{
164176
App.Helpers.beforeAjax(jedi_method);
165177
$.ajax({
166178
url: function() {
@@ -176,13 +188,17 @@ App.Ajax.request = function(jedi_method, data, callback){
176188
global: false,
177189
type: data.request_method || "POST",
178190
data: $.extend(data, {'jedi_method': jedi_method}),
179-
dataType: "json",
191+
dataType: "text",
180192
async:true,
181-
success: function(reply){
193+
success: function(reply)
194+
{
195+
timer.start();
196+
callback && callback(jsonParse(reply));
182197
App.Helpers.afterAjax();
183-
callback && callback(reply);
198+
timer.stop(jedi_method);
184199
},
185-
error: function() {
200+
error: function()
201+
{
186202
App.View.popup('error');
187203
}
188204
});
@@ -207,7 +223,7 @@ timer.stop = function( msg )
207223
timer.print = function( msg )
208224
{
209225
var passed = timer.stop_time - timer.start_time;
210-
fb.info( msg || '' + passed / 1000 );
226+
fb.info( (msg || '') + ': ' + passed / 1000 );
211227
}
212228

213229

web/js/helpers.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ App.Helpers.beforeAjax = function(jedi_method)
4646
App.Helpers.showLoading();
4747
break;
4848
default:
49+
App.Helpers.showLoading();
4950
break;
5051
}
5152
}
@@ -189,4 +190,23 @@ App.Helpers.liveValidate = function()
189190
var elm = $(evt.target);
190191
fb.log(elm.attr('TAGNAME'));
191192
});
192-
}
193+
}
194+
195+
App.Helpers.generatePassword = function()
196+
{
197+
var length = 12;
198+
var chars = "abcdefghijklmn.-%$#&-opqrstuvwxyz.-%$#&-ABCDEFGHIJKLMNOPQRSTUV.-%$#&-WXYZ1234567890.-%$#&-";
199+
var pass = "";
200+
201+
for (x=0;x<length;x++) {
202+
var i = Math.floor(Math.random() * 62);
203+
pass += chars.charAt(i);
204+
}
205+
206+
return pass;
207+
}
208+
209+
App.Helpers.Warn = function(msg)
210+
{
211+
alert(msg);
212+
}

0 commit comments

Comments
 (0)