Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
ecommerce-ui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
ecommerce-ui
Commits
f6df80aa
Commit
f6df80aa
authored
Dec 17, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added gadget refresh on state change, put on existing docs vs post
parent
f6cc9419
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
295 additions
and
263 deletions
+295
-263
data/global.json
data/global.json
+1
-2
js/erp5_loader.js
js/erp5_loader.js
+291
-260
lang/en-EN/dict.json
lang/en-EN/dict.json
+3
-1
No files found.
data/global.json
View file @
f6df80aa
...
...
@@ -25,8 +25,7 @@
"google"
:
"https://accounts.google.com/Logout?continue=REDIRECT_URL"
,
"facebook"
:
"https://www.facebook.com/logout.php?next=REDIRECT_URL&access_token=ACCESS_TOKEN"
},
"modernizr"
:
[
"sessionStorage"
,
"localStorage"
],
"preserve_session"
:
"sessionStorage"
,
"modernizr"
:
[
"localStorage"
],
"redirect"
:
{
"redirect_uri"
:
"http://localhost/sven/slapos-ui/index.html"
}
}
},
...
...
js/erp5_loader.js
View file @
f6df80aa
...
...
@@ -37,7 +37,7 @@
if
(
i18n
)
{
return
i18n
.
t
(
path
);
}
else
{
util
.
error
Handler
({
"
error
"
:
"
Translate NodeList - i18n not defined
"
});
util
.
error
({
"
error
"
:
"
Translate NodeList - i18n not defined
"
});
return
""
}
},
...
...
@@ -116,7 +116,7 @@
}
}
}
else
{
util
.
error
Handler
({
"
error
"
:
"
Translate NodeList - i18n not defined
"
});
util
.
error
({
"
error
"
:
"
Translate NodeList - i18n not defined
"
});
}
},
...
...
@@ -179,7 +179,7 @@
* @param {object} obj Action Object
**/
"
logout_user
"
:
function
(
obj
)
{
var
provider
,
temp_store
=
app
.
default_dict
.
state_dict
.
preserve_in
;
var
provider
;
hello
(
obj
.
id
).
logout
(
function
(
x
){
return
;
...
...
@@ -194,21 +194,6 @@
}
}
// update preserve
if
(
temp_store
)
{
switch
(
temp_store
)
{
case
"
sessionStorage
"
:
window
.
sessionStorage
.
removeItem
(
"
state
"
);
break
;
case
"
localStorage
"
:
window
.
localStorage
.
removeItem
(
"
state
"
);
break
;
case
"
cookie
"
:
util
.
cookieHandler
.
removeItem
(
"
state
"
);
break
;
};
}
// TODO: Try to log out correctly
// http://stackoverflow.com/questions/17050575/logout-link-with-return-url-oauth/17127388#17127388
// http://stackoverflow.com/questions/16946798/logout-from-external-login-service-gmail-facebook-using-oauth
...
...
@@ -225,18 +210,18 @@
* @method login_user
* @param {object} obj Action Object
**/
// TODO: failed login?
"
login_user
"
:
function
(
obj
)
{
var
signature
,
match_string
,
reply
,
element
;
var
signature
,
match_string
,
reply
,
element
,
active
,
hashed_list
;
// create signature and ticket
element
=
obj
.
element
;
signature
=
util
.
generateRandomIdentifier
(
36
);
flux
[
signature
]
=
util
.
generateUuid
();
// pass to 3rd party
// pass to 3rd party and authenticate
// NOTE: normally the signature should be a token from the server!
hello
.
settings
.
state
=
signature
;
// authenticate
hello
(
obj
.
id
).
login
(
function
(){
window
.
parent
.
close
();
})
...
...
@@ -255,24 +240,43 @@
// update flux
app
.
setLoginStatus
(
response
,
undefined
);
}
catch
(
e
)
{
util
.
error
Handler
(
e
);
util
.
error
(
e
);
}
}
}
else
{
util
.
loader
(
""
,
"
global_dict.status_dict.failed
"
,
"
ban-circle
"
);
}
// since we are jquerying, close (all) popups
// TODO: this is also crap...
$
(
"
.ui-popup
"
).
popup
(
"
close
"
);
// NOTE: now that we have a authenticated user, check storage
// for user (INSECURE!!!!) and if not found, generate a new user
// with the login credentials accessible.
// TODO: not my problem now, but this must be secure access!
})
.
then
(
function
()
{
app
.
register
(
obj
.
id
);
util
.
loader
(
""
,
"
global_dict.status_dict.saving
"
);
return
app
.
register
(
obj
.
id
)
.
then
(
function
()
{
// TODO: find a way to access an element that is depending on
// the login status!
// update which would be closest form...
var
el
=
document
.
getElementsByTagName
(
"
form
"
)[
0
];
var
config
=
{
"
state
"
:
el
.
state
};
// update gadget
app
.
setContent
(
{
"
generate
"
:
"
gadget
"
,
"
id
"
:
"
person_view
"
,
"
href
"
:
"
person_view
"
},
{
"
fragment_list
"
:
config
.
state
.
fragment_list
},
false
,
true
)
.
then
(
function
(
answer
){
el
.
parentNode
.
replaceChild
(
answer
,
el
);
})
.
then
(
app
.
setPageBindings
)
.
fail
(
util
.
error
);
})
})
.
fail
(
util
.
errorHandler
);
.
fail
(
util
.
error
);
},
/**
...
...
@@ -534,7 +538,7 @@
(
spec
.
property_dict
.
feature_dict
.
link_identifier
||
"
id
"
)];
if
(
item
===
undefined
)
{
util
.
error
Handler
({
"
error
"
:
"
mapTableRows: include_docs not set
"
});
util
.
error
({
"
error
"
:
"
mapTableRows: include_docs not set
"
});
}
else
{
row
=
[];
for
(
m
=
0
;
m
<
config
.
length
;
m
+=
1
)
{
...
...
@@ -573,7 +577,7 @@
if
(
layout
.
footer
&&
layout
.
footer
.
length
>
0
)
{
util
.
error
Handler
(
util
.
error
(
{
"
error
"
:
"
mapTableRows: Missing handler for table footer
"
}
);
}
...
...
@@ -614,7 +618,7 @@
// if include_docs is not set, item will be undefined!
if
(
item
===
undefined
)
{
util
.
error
Handler
({
"
error
"
:
"
mapListItems: missing include_docs
"
});
util
.
error
({
"
error
"
:
"
mapListItems: missing include_docs
"
});
}
// radio
...
...
@@ -866,7 +870,7 @@
"
clear
"
:
clear
||
undefined
};
}
else
{
util
.
error
Handler
({
util
.
error
({
"
error
"
:
"
mapFormField: No field definition defined
"
});
}
...
...
@@ -919,23 +923,19 @@
// initialize hellojs
hello
.
init
(
foreign
.
initializer_dict
,
foreign
.
redirect
);
// set login state
if
(
foreign
.
preserve_session
)
{
app
.
default_dict
.
state_dict
.
preserve_in
=
foreign
.
preserve_session
;
app
.
default_dict
.
state_dict
.
verification_dict
=
foreign
.
verification_dict
;
}
app
.
default_dict
.
state_dict
.
verification_dict
=
foreign
.
verification_dict
;
set_login
=
true
;
}
else
{
util
.
error
Handler
({
"
error
"
:
"
globalConfig: Missing hellojs
"
});
util
.
error
({
"
error
"
:
"
globalConfig: Missing hellojs
"
});
}
}
break
;
}
}
}
else
{
util
.
error
Handler
({
"
error
"
:
"
globalConfig: Missing login dict
"
});
util
.
error
({
"
error
"
:
"
globalConfig: Missing login dict
"
});
}
// setup loader
...
...
@@ -956,7 +956,7 @@
}
}
}
else
{
util
.
error
Handler
({
"
error
"
:
"
globalConfig: Missing path dict
"
});
util
.
error
({
"
error
"
:
"
globalConfig: Missing path dict
"
});
}
// i18n
...
...
@@ -979,7 +979,7 @@
return
;
});
}
else
{
util
.
error
Handler
(
util
.
error
(
{
"
error
"
:
"
globalConfig: Missing i18n configuration
"
}
);
}
...
...
@@ -1061,7 +1061,7 @@
app
.
setGlobalBindings
();
});
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
},
/**
...
...
@@ -1089,7 +1089,7 @@
}
return
RSVP
.
all
(
promises
);
default
:
util
.
error
Handler
({
"
error
"
:
"
setStorage: Missing storage type
"
});
util
.
error
({
"
error
"
:
"
setStorage: Missing storage type
"
});
return
RSVP
.
all
(
promises
)
};
},
...
...
@@ -1104,7 +1104,7 @@
storage
[
content_dict
.
property_dict
.
definition
.
application_name
]
=
jIO
.
createJIO
(
content_dict
.
property_dict
.
definition
);
}
else
{
util
.
error
Handler
(
util
.
error
(
{
"
error
"
:
"
makeStorage: Missing storage definition
"
}
);
}
...
...
@@ -1123,7 +1123,7 @@
.
children
[
url_dict
?
(
url_dict
.
layout_level
||
0
)
:
0
];
if
(
page_dict
===
undefined
)
{
util
.
error
Handler
({
"
error
"
:
"
Pageindex: Missing page definition
"
});
util
.
error
({
"
error
"
:
"
Pageindex: Missing page definition
"
});
}
else
{
// NOTE: 3rd parameter "create" needs to be set to undefined,
...
...
@@ -1302,42 +1302,41 @@
"
fieldlist
"
:
function
(
spec
,
answer
,
field_dict
,
update
,
url_pointer
)
{
var
i
,
element
,
target
;
target
=
document
.
createDocumentFragment
();
// no auth
if
(
answer
===
null
)
{
target
=
factory
.
util
.
wrapInForm
(
spec
);
target
.
appendChild
(
app
.
noItemsFound
(
"
auth
"
));
return
target
;
}
if
((
answer
.
data
&&
answer
.
data
.
total_rows
===
0
)
||
(
answer
.
data
===
undefined
&&
answer
.
request_new
===
undefined
))
{
target
.
appendChild
(
app
.
noItemsFound
());
}
else
{
for
(
i
=
0
;
i
<
spec
.
children
.
length
;
i
+=
1
)
{
element
=
spec
.
children
[
i
];
target
=
document
.
createDocumentFragment
();
// new
if
(
element
.
type
===
"
form
"
)
{
if
(
answer
&&
(
answer
.
data
||
answer
.
request_new
))
{
if
(
answer
.
request_new
||
answer
.
data
.
total_rows
===
0
)
{
element
.
data
=
{};
}
else
if
(
answer
.
data
.
total_rows
>
1
)
{
util
.
errorHandler
({
"
error
"
:
"
Fieldlist: More than 1 record
"
});
}
else
{
element
.
data
=
answer
.
data
.
rows
[
0
].
doc
;
if
((
answer
.
data
&&
answer
.
data
.
total_rows
===
0
)
||
(
answer
.
data
===
undefined
&&
answer
.
request_new
===
undefined
))
{
target
.
appendChild
(
app
.
noItemsFound
());
}
else
{
for
(
i
=
0
;
i
<
spec
.
children
.
length
;
i
+=
1
)
{
element
=
spec
.
children
[
i
];
// new
if
(
element
.
type
===
"
form
"
)
{
if
(
answer
&&
(
answer
.
data
||
answer
.
request_new
))
{
if
(
answer
.
request_new
||
answer
.
data
.
total_rows
===
0
)
{
element
.
data
=
{};
}
else
if
(
answer
.
data
.
total_rows
>
1
)
{
util
.
error
({
"
error
"
:
"
Fieldlist: More than 1 record
"
});
}
else
{
element
.
data
=
answer
.
data
.
rows
[
0
].
doc
;
}
}
element
.
form
=
spec
.
form
;
element
.
fields
=
field_dict
;
element
.
id
=
spec
.
id
;
}
element
.
form
=
spec
.
form
;
element
.
fields
=
field_dict
;
element
.
id
=
spec
.
id
;
target
.
appendChild
(
app
.
setContent
(
element
));
}
target
.
appendChild
(
app
.
setContent
(
element
));
}
return
target
;
}
return
target
;
}
};
...
...
@@ -1464,18 +1463,26 @@
* @param {object} content Content to add
*/
// TODO: bad targeting, should be depending on the gadget being updated!
// TODO: remove altogether, when figuring out how to store state and target!
factory
.
util
.
updatePageSection
=
function
(
id
,
content
)
{
var
i
,
target
,
container
=
document
.
getElementById
(
id
);
// find a target
target
=
container
.
querySelectorAll
(
"
[data-update]
"
);
// ui-content
if
(
target
.
length
===
0
)
{
target
=
container
.
querySelectorAll
(
"
div.ui-content
"
);
}
// element itself
if
(
target
.
length
===
0
)
{
util
.
errorHandler
({
"
error
"
:
"
updatePageSection: No target found
"
});
target
=
[
container
];
}
// no more way
if
(
target
.
length
===
0
)
{
util
.
error
({
"
error
"
:
"
updatePageSection: No target found
"
});
}
else
{
for
(
i
=
0
;
i
<
target
.
length
;
i
+=
1
)
{
target
[
i
].
setAttribute
(
"
data-bound
"
,
true
);
...
...
@@ -1501,7 +1508,7 @@
// don't reload if same popup is opened
if
(
state
!==
reference
)
{
if
(
reference
===
null
)
{
util
.
error
Handler
({
"
error
"
:
"
Global Bindings: No handler for popup
"
});
util
.
error
({
"
error
"
:
"
Global Bindings: No handler for popup
"
});
fragment
=
factory
.
element
(
"
p
"
,
{},
{},
{
"
text
"
:
"
No handler for popup
"
}
);
...
...
@@ -1546,7 +1553,7 @@
// TODO: how to reposition popup right after appending?
$
(
popup
).
popup
(
"
reposition
"
,
{
"
positionto
"
:
"
window
"
});
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
}
}
};
...
...
@@ -1622,7 +1629,7 @@
var
i
,
target
,
popup
,
wrap
,
id
,
config
,
container
,
placeholder
;
if
(
config_dict
===
undefined
)
{
util
.
error
Handler
({
util
.
error
({
"
error
"
:
"
GeneratePopup: Missing configuration
"
});
}
else
{
...
...
@@ -1735,7 +1742,7 @@
target
,
state
;
if
(
config_dict
===
undefined
)
{
util
.
error
Handler
({
util
.
error
({
"
error
"
:
"
Generate Header: Missing configuration
"
});
}
else
{
...
...
@@ -1855,7 +1862,7 @@
var
i
,
element
,
config
,
id
,
panel
,
closer
,
order
,
target
;
if
(
config_dict
===
undefined
)
{
util
.
error
Handler
({
util
.
error
({
"
error
"
:
"
Generate Panel: Missing configuration
"
});
}
else
{
...
...
@@ -1954,7 +1961,7 @@
var
config
,
id
,
footer
,
i
,
element
,
order
;
if
(
config_dict
===
undefined
)
{
util
.
error
Handler
({
util
.
error
({
"
error
"
:
"
Generate Footer: Missing config
"
});
}
else
{
...
...
@@ -2026,13 +2033,14 @@
factory
.
form
=
function
(
spec
)
{
var
i
,
j
,
k
,
layout
,
element
,
container
,
area
,
field
,
overrides
,
position
,
doc
,
config
,
value
,
stamp
,
sauce
,
encode
,
secure
,
safety_box
,
noscript
,
fragment
,
wrap
,
update
;
safety_box
,
noscript
,
fragment
,
wrap
;
fragment
=
factory
.
util
.
wrapInForm
(
spec
);
secure
=
spec
.
property_dict
.
secure
;
if
(
spec
.
property_dict
.
update
)
{
spec
.
update
=
spec
.
property_dict
.
update
;
}
fragment
=
factory
.
util
.
wrapInForm
(
spec
);
wrap
=
function
(
area
,
captcha
)
{
var
keys
=
{};
...
...
@@ -2056,64 +2064,79 @@
area
=
layout
.
position
===
"
center
"
?
2
:
1
;
container
=
wrap
(
area
);
// secure
if
(
i
===
0
&&
secure
===
"
default
"
)
{
stamp
=
new
Date
().
getTime
();
encode
=
window
.
btoa
||
window
.
shim
.
Base64
.
encode
;
// TODO: include client IP in hash to block submission serverside
sauce
=
encode
(
stamp
.
toString
()
+
spec
.
property_dict
.
secret_hash
);
if
(
i
===
0
)
{
// secure form
// TODO: do properly once we have time
if
(
secure
===
"
default
"
)
{
container
.
appendChild
(
factory
.
formElement
(
{
"
type
"
:
"
input
"
,
"
direct
"
:
{
"
type
"
:
"
text
"
,
"
value
"
:
""
,
"
className
"
:
"
secure_form
"
},
"
attributes
"
:
{
"
placeholder
"
:
"
Please do not fill out this field
"
,
"
data-enhanced
"
:
"
true
"
,
"
data-i18n
"
:
"
[placeholder]global.form_helpers.secure_blank
"
},
"
logic
"
:
{
"
plain_element
"
:
true
,
"
label
"
:
"
Please do not fill out this field
"
,
"
label_i18n
"
:
"
global.form_helpers.secure_blank
"
stamp
=
new
Date
().
getTime
();
encode
=
window
.
btoa
||
window
.
shim
.
Base64
.
encode
;
// TODO: include client IP in hash to block submission serverside
sauce
=
encode
(
stamp
.
toString
()
+
spec
.
property_dict
.
secret_hash
);
container
.
appendChild
(
factory
.
formElement
(
{
"
type
"
:
"
input
"
,
"
direct
"
:
{
"
type
"
:
"
text
"
,
"
value
"
:
""
,
"
className
"
:
"
secure_form
"
},
"
attributes
"
:
{
"
placeholder
"
:
"
Please do not fill out this field
"
,
"
data-enhanced
"
:
"
true
"
,
"
data-i18n
"
:
"
[placeholder]global.form_helpers.secure_blank
"
},
"
logic
"
:
{
"
plain_element
"
:
true
,
"
label
"
:
"
Please do not fill out this field
"
,
"
label_i18n
"
:
"
global.form_helpers.secure_blank
"
}
}
}
));
container
.
appendChild
(
factory
.
element
(
"
input
"
,
{
"
type
"
:
"
hidden
"
,
"
value
"
:
spec
.
property_dict
.
secret_hash
,
"
id
"
:
spec
.
id
+
"
_not_a_secret
"
},
{
"
data-created
"
:
stamp
}
));
container
.
appendChild
(
factory
.
formElement
(
{
"
type
"
:
"
input
"
,
"
direct
"
:
{
"
type
"
:
"
text
"
,
"
className
"
:
"
secure_form
"
,
"
value
"
:
sauce
},
"
attributes
"
:
{
"
placeholder
"
:
"
Please leave this value unchanged
"
,
"
data-enhanced
"
:
"
true
"
,
"
data-i18n
"
:
"
[placeholder]global.form_helpers.secure_filled
"
));
container
.
appendChild
(
factory
.
element
(
"
input
"
,
{
"
type
"
:
"
hidden
"
,
"
value
"
:
spec
.
property_dict
.
secret_hash
,
"
id
"
:
spec
.
id
+
"
_not_a_secret
"
},
"
logic
"
:
{
"
plain_element
"
:
true
,
"
label
"
:
"
Please leave this value unchanged
"
,
"
label_i18n
"
:
"
global.form_helpers.secure_filled
"
{
"
data-created
"
:
stamp
}
}
));
));
container
.
appendChild
(
factory
.
formElement
(
{
"
type
"
:
"
input
"
,
"
direct
"
:
{
"
type
"
:
"
text
"
,
"
className
"
:
"
secure_form
"
,
"
value
"
:
sauce
},
"
attributes
"
:
{
"
placeholder
"
:
"
Please leave this value unchanged
"
,
"
data-enhanced
"
:
"
true
"
,
"
data-i18n
"
:
"
[placeholder]global.form_helpers.secure_filled
"
},
"
logic
"
:
{
"
plain_element
"
:
true
,
"
label
"
:
"
Please leave this value unchanged
"
,
"
label_i18n
"
:
"
global.form_helpers.secure_filled
"
}
}
));
}
// add hidden storage identifier
if
(
spec
.
data
.
_id
)
{
container
.
appendChild
(
factory
.
element
(
"
input
"
,
{
"
type
"
:
"
hidden
"
,
"
value
"
:
spec
.
data
.
_id
,
"
name
"
:
"
identifier
"
}
));
}
}
for
(
j
=
0
;
j
<
layout
.
fieldlist
.
length
;
j
+=
1
)
{
...
...
@@ -2122,6 +2145,7 @@
config
=
spec
.
fields
[
field
.
title
];
overrides
=
field
.
overrides
;
doc
=
spec
.
data
||
undefined
;
value
=
doc
?
(
doc
[
field
.
title
])
:
undefined
;
switch
(
j
)
{
...
...
@@ -2138,7 +2162,6 @@
position
=
undefined
;
break
;
}
// generate and append
container
.
appendChild
(
factory
.
formElement
(
map
.
utils
.
mapFormField
(
config
,
overrides
,
value
),
...
...
@@ -2156,7 +2179,7 @@
safety_box
=
wrap
(
1
,
true
);
fragment
.
appendChild
(
safety_box
);
}
else
{
util
.
error
Handler
({
"
error
"
:
"
Captcha - No public key supplied
"
});
util
.
error
({
"
error
"
:
"
Captcha - No public key supplied
"
});
}
}
...
...
@@ -2201,7 +2224,7 @@
var
config
,
group
,
direction
,
controls
,
i
,
element
,
order
,
state
;
if
(
spec
===
undefined
)
{
util
.
error
Handler
({
util
.
error
({
"
error
"
:
"
Generate Controlgroup: Missing config
"
});
}
else
{
...
...
@@ -2295,7 +2318,7 @@
var
navbar
,
controls
,
i
,
element
,
target
,
order
;
if
(
spec
===
undefined
)
{
util
.
error
Handler
({
util
.
error
({
"
error
"
:
"
Generate Navbar: Missing Configuration
"
});
}
else
{
...
...
@@ -2863,7 +2886,7 @@
);
}
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
};
/* ********************************************************************** */
...
...
@@ -3708,14 +3731,16 @@
obj
[
property
]
=
value
;
}
// prepare for form submit
// NOTE: formData can post CORS!
formData
.
append
(
property
.
replace
(
replace
,
""
),
value
);
}
}
util
.
updateStatus
(
"
show
"
,
""
,
"
global_dict.status_dict.saving
"
);
util
.
loader
(
""
,
"
global_dict.status_dict.saving
"
);
// TODO: a post should always include all required fields
// TODO: find a way to set default fields, like timestamp etc
// TODO: make sure we put on existing records!
app
.
postDataToStorage
({
"
response
"
:
[
obj
],
"
pass
"
:
{
"
type
"
:
config
.
gadget
.
state
.
type
,
"
reply
"
:
true
}
...
...
@@ -3724,17 +3749,17 @@
// TODO: This is not the correct place to run all status updates!
if
(
answer
.
response
.
result
===
"
success
"
)
{
switch
(
config
.
gadget
.
getAttribute
(
"
data-set
"
))
{
case
"
login_state
"
:
case
"
login_state
"
:
app
.
setLoginStatus
(
answer
.
response
,
config
.
portal_type_source
);
break
;
}
util
.
updateStatus
(
"
show
"
,
""
,
"
global_dict.status_dict.saved
"
,
"
check
"
);
break
;
};
util
.
loader
(
""
,
"
global_dict.status_dict.saved
"
,
"
check
"
);
}
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
}
}
else
{
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban-circle
"
);
}
};
...
...
@@ -3794,6 +3819,7 @@
*/
app
.
search
=
function
(
config
)
{
// TODO: why do I need the first 2 calls here, without I cannot search.
// gadget config
app
.
fetchConfiguration
({
"
storage
"
:
app
.
default_dict
.
storage_dict
.
settings
,
...
...
@@ -3831,13 +3857,13 @@
.
then
(
function
(
reply
){
factory
.
util
.
updatePageSection
(
config
.
id
,
reply
);
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
};
/**
* Register
a
user (in localstorage) - requires login module)
* Register user (in localstorage) - requires login module)
* @method register
* @param {string} provider Provider through which register should run
**/
...
...
@@ -3880,12 +3906,14 @@
"
response
"
:
[
user
],
"
pass
"
:
{
"
type
"
:
"
Person
"
}
});
}
else
{
util
.
error
({
"
error
"
:
"
regiser user: need account sync!
"
});
}
}
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
};
/**
...
...
@@ -3970,7 +3998,7 @@
.
then
(
function
(
reply
){
factory
.
util
.
updatePageSection
(
config
.
id
,
reply
);
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
// reset timer
app
.
timer
=
0
;
...
...
@@ -4124,12 +4152,12 @@
.
then
(
function
(
reply
){
factory
.
util
.
updatePageSection
(
config
.
id
,
reply
);
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
}
else
{
util
.
error
Handler
({
"
Error
"
:
"
No state information stored for gadget
"
});
util
.
error
({
"
Error
"
:
"
No state information stored for gadget
"
});
}
}
else
{
util
.
error
Handler
({
util
.
error
({
"
Error
"
:
"
Action is missing reference gadget
"
});
}
...
...
@@ -4220,9 +4248,8 @@
* @param {string} portal_type Portal Type concerned
**/
app
.
setLoginStatus
=
function
(
response
,
portal_type
)
{
var
temp_store
,
stamp
,
provider
,
auth
,
links
,
i
,
login
;
var
stamp
,
provider
,
auth
,
links
,
i
,
login
;
temp_store
=
app
.
default_dict
.
state_dict
.
preserve_in
;
stamp
=
Date
.
now
();
provider
=
response
.
network
?
response
.
network
.
slice
(
0
,
2
)
:
"
self
"
;
auth
=
response
.
authResponse
;
...
...
@@ -4238,26 +4265,6 @@
"
expires
"
:
auth
?
auth
.
expires_in
:
3600
}
// if specified store in preserve
if
(
temp_store
)
{
switch
(
temp_store
)
{
case
"
sessionStorage
"
:
window
.
sessionStorage
.
setItem
(
"
state
"
,
JSON
.
stringify
(
flux
.
state
));
break
;
// WARNING: you should not!
case
"
localStorage
"
:
window
.
localStorage
.
setItem
(
"
state
"
,
JSON
.
stringify
(
flux
.
state
));
break
;
// WARNING: you really should NOT!!!
case
"
cookie
"
:
util
.
cookieHandler
.
setItem
(
"
state
"
,
JSON
.
stringify
(
flux
.
state
));
break
;
};
}
// need to update the .... button
// TODO: make a login gadget, store dependend buttons in state
links
=
util
.
getHeader
().
getElementsByTagName
(
"
A
"
);
...
...
@@ -4281,16 +4288,17 @@
* @return {boolean} true/false
**/
// TODO: make this work with a regular login, too!!!
// TODO: refactor, make sure we always pass a pass!
app
.
checkLoginStatus
=
function
(
skip
,
pass
)
{
var
state
,
temp_store
,
lookup
,
logger
,
provider
,
verify
,
url
,
influx
,
info
,
valid
,
auth_config
,
stamp
,
expires
,
expired
,
token
;
var
state
,
lookup
,
logger
,
provider
,
verify
,
url
,
influx
,
info
,
valid
,
auth_config
,
stamp
,
expires
,
expired
,
token
,
auth_response
,
signee
;
if
(
skip
===
undefined
)
{
// TODO: name collusion! make normal pass object!
return
RSVP
.
resolve
({
"
pass
"
:
skip
});
}
else
{
logger
=
app
.
default_dict
.
state_dict
.
login_pointer
;
temp_store
=
app
.
default_dict
.
state_dict
.
preserve_in
;
verify
=
app
.
default_dict
.
state_dict
.
verification_dict
;
if
(
logger
)
{
...
...
@@ -4298,21 +4306,6 @@
// try flux
state
=
flux
.
state
;
// fallback to preserved locations
if
(
state
===
undefined
)
{
switch
(
temp_store
)
{
case
"
sessionStorage
"
:
state
=
JSON
.
parse
(
window
.
sessionStorage
.
getItem
(
"
state
"
));
break
;
case
"
localStorage
"
:
state
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
"
state
"
));
break
;
case
"
cookie
"
:
state
=
JSON
.
parse
(
util
.
cookieHandler
.
getItem
(
"
state
"
));
break
;
};
}
// found state
// TODO: break once first active session is found! For now I would
// like to keep one active login only.
...
...
@@ -4326,9 +4319,11 @@
switch
(
provider
)
{
case
"
go
"
:
url
=
verify
.
google
+
auth_config
.
token
;
signee
=
"
google
"
;
break
;
case
"
self
"
:
url
=
undefined
;
signee
=
"
self
"
;
break
;
}
// test for timeout
...
...
@@ -4344,10 +4339,11 @@
}
}
}
// token in memory still valid, add it to the pass object
// token in memory still valid, add it to the pass object
and done
if
(
valid
)
{
if
(
pass
)
{
pass
.
active_login
=
true
;
pass
.
verified_by
=
signee
;
pass
.
token
=
auth_config
.
token
;
pass
.
expires_in
=
expires
;
return
RSVP
.
resolve
(
pass
);
...
...
@@ -4359,23 +4355,37 @@
if
(
url
)
{
return
util
.
ajax
({
"
url
"
:
url
})
.
then
(
function
(
answer
)
{
auth_response
=
util
.
parseIfNeeded
(
answer
.
target
.
response
);
if
(
pass
)
{
pass
.
active_login
=
true
;
pass
.
verified_by
=
signee
;
pass
.
token
=
auth_config
.
token
;
pass
.
expires_in
=
auth_response
.
expires_in
;
return
RSVP
.
resolve
(
pass
);
}
return
auth_response
;
return
util
.
parseIfNeeded
(
answer
.
target
.
response
);
})
.
fail
(
function
(
event
)
{
// invalid session > return 400, so we are back on the then-column
if
(
event
.
target
.
status
===
400
)
{
return
util
.
parseIfNeeded
(
event
.
target
.
response
);
auth_response
=
util
.
parseIfNeeded
(
event
.
target
.
response
);
if
(
pass
)
{
return
RSVP
.
resolve
(
pass
);
}
return
RSVP
.
resolve
(
pass
);
}
throw
util
.
parseIfNeeded
(
event
.
target
);
});
}
// TODO: this should ask to login again!
if
(
pass
)
{
pass
.
active_login
=
false
;
return
RSVP
.
resolve
(
pass
);
}
return
RSVP
.
resolve
({
"
error
"
:
"
no state found/not logged in
"
});
}
else
{
util
.
error
Handler
({
"
error
"
:
"
loginStatus: Missing login handler.
"
});
util
.
error
({
"
error
"
:
"
loginStatus: Missing login handler.
"
});
}
}
};
...
...
@@ -4540,12 +4550,12 @@
if
(
handler
)
{
handler
(
app
.
generateActionObject
(
e
),
val
);
}
else
{
util
.
error
Handler
({
util
.
error
({
"
Error
"
:
"
Action: No method defined
"
});
}
}
else
{
util
.
error
Handler
({
util
.
error
({
"
Error
"
:
"
Action: No action defined for element
"
});
}
...
...
@@ -4827,8 +4837,11 @@
* @param {object} content_dict content to be generated
* @param {object} url_dict JSON pointers based on parsed link
* @param {boolean} create Create page/Generate content/Refresh content
* @param {boolean} purge Replace existing element/gadget
* @return {object} promise/HTML element
*/
app
.
setContent
=
function
(
content_dict
,
url_dict
,
create
)
{
// TODO: make this always return a promise. Requires to refactor listview!
app
.
setContent
=
function
(
content_dict
,
url_dict
,
create
,
purge
)
{
var
i
,
skip
,
container
,
target
,
pass
,
spec
,
dependency
;
spec
=
url_dict
||
{};
...
...
@@ -4850,6 +4863,7 @@
}
else
{
// this run needs query and dynamic data
pass
=
{
"
purge
"
:
purge
||
null
,
"
mode
"
:
spec
.
mode
||
null
,
"
create
"
:
create
,
"
layout_level
"
:
spec
.
layout_level
||
null
,
...
...
@@ -4882,7 +4896,7 @@
.
then
(
app
.
fetchDataTotal
)
.
then
(
app
.
fetchDataQuery
)
.
then
(
app
.
generateGadgetContent
)
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
default
:
switch
(
content_dict
.
type
)
{
...
...
@@ -4962,7 +4976,7 @@
request_new
=
pass
.
mode
===
"
new
"
?
{
"
request_new
"
:
true
}
:
null
;
if
(
constructor
===
undefined
)
{
util
.
error
Handler
(
util
.
error
(
{
"
error
"
:
"
generateGadgetContent: Missing constructor
"
}
);
}
...
...
@@ -4971,7 +4985,6 @@
if
(
pass
.
skip
)
{
return
constructor
(
pass
.
content_dict
,
pass
.
url_dict
);
}
else
{
// generate content
element
=
constructor
(
pass
.
config
,
...
...
@@ -4984,31 +4997,32 @@
// translate
map
.
actions
.
translateNodeList
(
element
);
// NOTE: when purging, we must not set state on the gadget being purged
if
(
pass
.
create
===
false
&&
pass
.
purge
===
null
)
{
selector
=
pass
.
state
.
gadget
;
}
else
{
// NOTE: in case of update, element will be the section to update
// not the gadget/fragment, so we need to find the gadget
// NOTE: in case of forms, we find the form!
// NOTE: in case of fragments, we punt to the firstElementChild...
selector
=
element
.
querySelector
(
"
#
"
+
pass
.
id
)
||
document
.
getElementById
(
pass
.
config
.
form
)
||
(
element
.
tagName
===
undefined
?
element
.
firstElementChild
:
element
);
pass
.
state
.
gadget
=
selector
;
}
// round up and store state on gadget
pass
.
state
.
constructor
=
pass
.
constructor
;
pass
.
state
.
selected
=
pass
.
create
===
false
?
(
pass
.
state
.
selected
)
:
undefined
;
// WARNING: this should use data(), it is bad practice to store like this
selector
.
state
=
pass
.
state
;
// not auth, no mojo!
if
(
pass
.
no_auth
||
(
pass
.
auth
&&
pass
.
active_login
||
pass
.
mode
===
"
new
"
))
{
if
(
pass
.
create
===
false
)
{
selector
=
pass
.
state
.
gadget
;
}
else
{
// NOTE: in case of update, element will be the section to update
// not the gadget/fragment, so we need to find the gadget
// NOTE: in case of forms, we find the form!
// NOTE: in case of fragments, we punt to the firstElementChild...
selector
=
element
.
querySelector
(
"
#
"
+
pass
.
id
)
||
document
.
getElementById
(
pass
.
config
.
form
)
||
(
element
.
tagName
===
undefined
?
element
.
firstElementChild
:
element
);
pass
.
state
.
gadget
=
selector
;
}
// round up and store state on gadget
pass
.
state
.
constructor
=
pass
.
constructor
;
pass
.
state
.
selected
=
pass
.
create
===
false
?
(
pass
.
state
.
selected
)
:
undefined
;
// WARNING: this should use data(), it is bad practice to store like this
selector
.
state
=
pass
.
state
;
app
.
updateInfoElement
(
pass
.
create
?
element
:
selector
,
pass
.
state
.
query
,
...
...
@@ -5039,6 +5053,8 @@
}
if
(
pass
.
create
===
false
)
{
// make sure include_docs is set, because at this point we want data!
pass
.
state
.
query
.
include_docs
=
true
;
pass
.
state
.
query
.
limit
=
pass
.
store_limit
;
}
else
{
pass
.
state
.
query
=
app
.
generateQueryObject
(
...
...
@@ -5070,15 +5086,17 @@
* @return {object} response object/promise
*/
app
.
fetchDataTotal
=
function
(
reply
)
{
var
pass
=
reply
.
pass
;
if
(
pass
.
skip
===
undefined
&&
(
pass
.
no_auth
||
(
pass
.
auth
&&
pass
.
active_login
||
pass
.
mode
===
"
new
"
)))
{
var
pass
=
reply
.
pass
,
reference
;
if
(
pass
.
skip
===
undefined
)
{
// create or update state object
if
(
pass
.
create
===
false
)
{
pass
.
state
=
document
.
getElementById
(
pass
.
id
).
state
;
// TODO: horrible, define a pass API!!!!
reference
=
document
.
getElementById
(
pass
.
id
);
if
(
reference
===
null
)
{
reference
=
document
.
getElementById
(
pass
.
config
.
id
);
}
pass
.
state
=
reference
.
state
;
pass
.
constructor
=
pass
.
state
.
method
;
pass
.
store_limit
=
pass
.
state
.
query
.
limit
;
pass
.
state
.
query
.
limit
=
[];
...
...
@@ -5104,6 +5122,11 @@
);
}
}
}
if
(
pass
.
skip
===
undefined
&&
(
pass
.
no_auth
||
(
pass
.
auth
&&
pass
.
active_login
||
pass
.
mode
===
"
new
"
)))
{
// skip total for single item layouts!
if
(
pass
.
config
.
initial_query
)
{
...
...
@@ -5140,10 +5163,11 @@
if
(
reply
.
response
)
{
store
=
storage
[
"
items
"
];
items
=
util
.
parseIfNeeded
(
reply
.
response
);
if
(
store
&&
items
.
length
>
0
)
{
promises
=
[];
// show some status
util
.
updateStatus
(
"
show
"
,
""
,
"
global_dict.status_dict.storing
"
);
util
.
loader
(
""
,
"
global_dict.status_dict.storing
"
);
// loop over item and create a JIO record
for
(
i
=
0
;
i
<
items
.
length
;
i
+=
1
)
{
...
...
@@ -5156,10 +5180,17 @@
}
// add portal type
obj
.
portal_type
=
pass
.
type
;
// make sure to overwrite existing files, so try to fetch...
// TODO: is there no easier way to check whether to put/post
promises
[
i
]
=
store
.
post
(
obj
)
console
.
log
(
obj
)
console
.
log
(
obj
.
identifier
)
// test for existing file
if
(
obj
.
identifier
)
{
method
=
"
put
"
;
obj
.
_id
=
obj
.
identifier
;
}
promises
[
i
]
=
store
[
method
||
"
post
"
](
obj
)
.
then
(
function
(
answer
)
{
console
.
log
(
"
DONE
"
)
console
.
log
(
answer
)
return
answer
;
});
}
...
...
@@ -5174,7 +5205,7 @@
"
pass
"
:
pass
};
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
}
// we may have no sample data!
return
{
...
...
@@ -5207,7 +5238,7 @@
"
pass
"
:
pass
};
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
}
}
return
{
...
...
@@ -5267,7 +5298,8 @@
if
(
pass
.
skip
===
undefined
&&
(
pass
.
no_auth
||
(
pass
.
auth
&&
pass
.
active_login
||
pass
.
mode
===
"
new
"
))
&&
pass
.
create
!==
false
&&
pass
.
config
.
portal_type_fields
)
{
//(pass.create !== false || pass.requires_fields) &&
pass
.
config
.
portal_type_fields
)
{
return
app
.
fetchConfiguration
({
"
storage
"
:
app
.
default_dict
.
storage_dict
.
settings
,
...
...
@@ -5305,11 +5337,12 @@
if
(
pass
.
auth
)
{
return
app
.
checkLoginStatus
(
true
,
pass
)
.
then
(
function
(
new_pass
)
{
return
{
"
pass
"
:
new_pass
}
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
}
return
{
"
pass
"
:
pass
...
...
@@ -5404,7 +5437,7 @@
if
(
property_dict
.
optional
)
{
return
RSVP
.
all
([]);
}
else
{
util
.
error
Handler
({
"
error
"
:
"
getFromDisk: URL undefined
"
});
util
.
error
({
"
error
"
:
"
getFromDisk: URL undefined
"
});
}
}
...
...
@@ -5424,7 +5457,7 @@
undefined
);
if
(
storage_location
===
undefined
)
{
util
.
error
Handler
({
"
error
"
:
"
getFromDisk: no storage defined
"
});
util
.
error
({
"
error
"
:
"
getFromDisk: no storage defined
"
});
return
RSVP
.
all
([]);
}
return
storage_location
.
put
({
...
...
@@ -5448,7 +5481,7 @@
}
return
response
;
})
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
};
/**
...
...
@@ -5492,16 +5525,16 @@
if
(
first
||
(
page
&&
base
)
||
raw_url
===
$
.
mobile
.
getDocumentUrl
()
||
data
.
options
.
role
===
"
popup
"
)
{
console
.
log
(
"
STOP us, JQM go
"
)
//
console.log("STOP us, JQM go")
return
;
}
if
((
document
.
getElementById
(
config
.
id
)
&&
base
!==
null
))
{
e
.
preventDefault
();
console
.
log
(
"
STOP us, STOP JQM
"
)
//
console.log("STOP us, STOP JQM")
return
;
}
handle
=
true
;
console
.
log
(
"
GO us, STOP JQM
"
)
//
console.log("GO us, STOP JQM")
e
.
preventDefault
();
}
else
{
...
...
@@ -5547,7 +5580,7 @@
return
app
.
setContent
(
reply
,
config
,
create
);
})
.
then
(
app
.
setPageBindings
)
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
}
};
...
...
@@ -5675,7 +5708,7 @@
captcha
.
id
,
{
"
theme
"
:
"
red
"
,
"
callback
"
:
Recaptcha
.
focus_response_field
}
);
}).
fail
(
util
.
error
Handler
);
}).
fail
(
util
.
error
);
}
if
(
form_element
.
getAttribute
(
"
data-bound
"
)
===
null
)
{
...
...
@@ -5943,13 +5976,12 @@
/**
* Show and hide the jQuery Mobile status message (loader/icon/message)
* @method loader
* @param {boolean} show Whether to show or hide the loader
* @param {string} message The message to display in the loader
* @param {string} msg_i18n lookup for status message
* @param {string} theme background theme
* @param {string} icon Which icon to display when overriding the loader
*/
util
.
updateStatus
=
function
(
show
,
message
,
msg_i18n
,
icon
,
theme
)
{
util
.
loader
=
function
(
message
,
msg_i18n
,
icon
,
theme
)
{
var
text_to_display
=
i18n
&&
msg_i18n
?
map
.
actions
.
translateLookup
(
msg_i18n
)
:
message
;
...
...
@@ -5972,9 +6004,9 @@
app
.
timer
=
window
.
setTimeout
(
function
()
{
$
.
mobile
.
loading
(
"
hide
"
);
},
25
00
);
},
30
00
);
}
else
{
util
.
error
Handler
({
"
error
"
:
"
showStatus: Loader not enabled
"
});
util
.
error
({
"
error
"
:
"
showStatus: Loader not enabled
"
});
}
};
...
...
@@ -6182,7 +6214,7 @@
}
if
(
supported
===
false
)
{
message
=
fail
.
splice
(
0
,
-
1
);
util
.
error
Handler
(
util
.
error
(
{
"
error
"
:
"
browser:
"
+
message
+
"
not supported
"
}
);
...
...
@@ -6206,7 +6238,7 @@
}
return
true
;
}
else
{
util
.
error
Handler
({
"
error
"
:
"
testBrowserSupport: Modernizr undefined
"
});
util
.
error
({
"
error
"
:
"
testBrowserSupport: Modernizr undefined
"
});
return
false
;
}
};
...
...
@@ -6220,7 +6252,7 @@
* @param {object} err Error object
*/
// TODO: update global config so we know where to post a ticket to!
util
.
error
Handler
=
function
(
err
)
{
util
.
error
=
function
(
err
)
{
console
.
log
(
err
);
};
...
...
@@ -6243,7 +6275,6 @@
if
(
window
.
opener
===
null
)
{
// TODO: don't wipe, sync...
window
.
localStorage
.
clear
();
window
.
sessionStorage
.
clear
();
}
app
.
getFromDisk
({
...
...
@@ -6259,7 +6290,7 @@
})
.
then
(
app
.
setContent
)
.
then
(
app
.
parsePage
)
.
fail
(
util
.
error
Handler
);
.
fail
(
util
.
error
);
});
}(
window
,
document
,
jQuery
));
\ No newline at end of file
lang/en-EN/dict.json
View file @
f6df80aa
...
...
@@ -13,7 +13,8 @@
"fetching"
:
"Fetching Data"
,
"storing"
:
"Storing Data"
,
"saving"
:
"Saving"
,
"saved"
:
"Saved"
"saved"
:
"Saved"
,
"failed"
:
"Failed"
},
"common_dict"
:
{
"sign_in"
:
"Sign in using:"
,
...
...
@@ -117,6 +118,7 @@
}
},
"validation_dict"
:
{
"general"
:
"Please correct the highlighted fields."
,
"requires_auth"
:
"Requires authorization."
,
"external"
:
"The input failed the external validator."
,
"required"
:
"Field is required but not found."
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment