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
b286b8c0
Commit
b286b8c0
authored
Apr 11, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslint
parent
a66ebf80
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
595 additions
and
834 deletions
+595
-834
js/erp5_loader.js
js/erp5_loader.js
+595
-834
No files found.
js/erp5_loader.js
View file @
b286b8c0
/*jslint indent: 2, maxlen: 80, nomen: true, sloppy: true, todo: true */
/*global console, window, jIO, complex_queries, FormData, RSVP, document,
jQuery, i18n, Recaptcha, XMLHttpRequest, Modernizr */
jQuery, i18n, Recaptcha, XMLHttpRequest,
alert,
Modernizr */
(
function
(
window
,
document
,
$
)
{
"
use strict
"
;
...
...
@@ -37,7 +37,7 @@
**/
// TODO: optgroup support!
factory
.
element
=
function
(
spec
)
{
var
element
,
setter
,
attribute
,
logic
,
item
,
i
,
j
,
mock
,
recurse
,
pic
;
var
element
,
setter
,
attribute
,
logic
,
item
,
i
,
mock
,
recurse
,
pic
;
// element
element
=
document
.
createElement
(
spec
.
type
);
...
...
@@ -379,7 +379,8 @@
}
// class string: assemble
container_class_list
+=
(
no_validate
?
""
:
"
ui-corner-all ui-shadow-inset
"
)
+
container_class_list
+=
(
no_validate
?
""
:
"
ui-corner-all ui-shadow-inset
"
)
+
disabled
+
readonly
+
(
action
||
""
)
+
(
clear
||
""
)
+
(
theme
?
(
"
ui-bar-
"
+
theme
+
"
"
)
:
"
ui-body-inherit
"
);
}
...
...
@@ -466,7 +467,7 @@
"
type
"
:
"
span
"
,
"
direct
"
:
{
"
className
"
:
"
ui-invalid-label
"
},
"
attributes
"
:
{},
"
logic
"
:
{
"
text
"
:
"
wrong
"
}
"
logic
"
:
{
"
text
"
:
"
wrong
"
}
}));
}
...
...
@@ -594,7 +595,7 @@
}
else
{
target
=
container
.
querySelector
(
"
[data-update]
"
)
||
container
.
querySelector
(
"
div.ui-content
"
)
||
container
container
;
}
// return new page and/or pointer to gadget content container
...
...
@@ -641,7 +642,7 @@
* @return {object} object including fragment, child-selector, placeholder
**/
factory
.
widget
.
collapsibleset
=
function
(
spec
)
{
var
container
,
f
ragment
,
f
orm
,
obj
,
prop
;
var
container
,
form
,
obj
,
prop
;
// TODO: why spec.set, BS?
if
(
spec
.
set
)
{
...
...
@@ -736,13 +737,13 @@
**/
// TODO: add dynamic
factory
.
widget
.
collapsible
=
function
(
spec
)
{
var
container
,
header
,
target
,
link
,
form
,
tranlate
,
collapsed
,
translate
;
var
container
,
header
,
target
,
link
,
form
,
collapsed
,
translate
;
translate
=
spec
.
text_i18n
?
"
translate
"
:
"
"
;
collapsed
=
spec
.
collapsed
===
false
;
container
=
factory
.
element
({
"
type
"
:
spec
.
form
?
"
fieldset
"
:
"
div
"
,
"
type
"
:
spec
.
form
?
"
fieldset
"
:
"
div
"
,
"
direct
"
:
{
"
className
"
:
"
ui-collapsible
"
+
(
spec
.
mini
?
"
ui-mini
"
:
""
)
+
(
!
spec
.
inset
?
""
:
"
ui-collapsible-inset ui-corner-all
"
)
+
...
...
@@ -789,7 +790,7 @@
},
"
logic
"
:
{
"
data-i18n
"
:
spec
.
text_i18n
?
(
"
[node]
"
+
spec
.
text_i18n
)
:
null
,
"
data-ajax
"
:
spec
.
href
?
"
false
"
:
null
,
"
data-ajax
"
:
spec
.
href
?
"
false
"
:
null
}
});
link
.
appendChild
(
document
.
createTextNode
(
spec
.
text
||
"
\
u00A0
"
));
...
...
@@ -810,7 +811,8 @@
"
type
"
:
"
div
"
,
"
direct
"
:
{
"
className
"
:
"
ui-collapsible-content
"
+
(
spec
.
collapsed
===
false
?
""
:
"
ui-collapsible-content-collapsed
"
)
+
"
ui-body-
"
+
(
spec
.
content_theme
||
"
inherit
"
)
""
:
"
ui-collapsible-content-collapsed
"
)
+
"
ui-body-
"
+
(
spec
.
content_theme
||
"
inherit
"
)
},
"
attributes
"
:
{
"
aria-hidden
"
:
spec
.
collapsed
===
false
?
false
:
true
...
...
@@ -1011,7 +1013,7 @@
"
direct
"
:
{
"
className
"
:
"
ui-fieldcontain translate
"
},
"
attributes
"
:
{
"
title
"
:
spec
.
label
.
title
},
"
logic
"
:
{
"
data-i18n
"
:
i18n
?
(
"
[title]
"
+
spec
.
label
.
title_i18n
)
:
null
,
"
data-i18n
"
:
i18n
?
(
"
[title]
"
+
spec
.
label
.
title_i18n
)
:
null
}
});
label
=
factory
.
element
({
...
...
@@ -1118,7 +1120,7 @@
// add popup
wrap
.
appendChild
(
factory
.
element
({
"
type
"
:
"
div
"
,
"
direct
"
:{
"
direct
"
:
{
"
className
"
:
"
ui-popup ui-body-
"
+
spec
.
theme
+
(
spec
.
shadow
?
"
ui-overlay-shadow
"
:
"
"
)
+
"
ui-corner-all
"
+
spec
.
class_list
,
...
...
@@ -1211,9 +1213,9 @@
return
{
"
fragment
"
:
container
,
"
child_selector
"
:
container
.
querySelector
(
"
div#
"
+
id
),
"
child_selector
"
:
container
.
querySelector
(
"
div#
"
+
id
)
};
};
}
/* ********************************************************************** */
/* JQM Navbar */
...
...
@@ -1241,7 +1243,9 @@
target
=
function
(
j
)
{
return
factory
.
element
({
"
type
"
:
"
li
"
,
"
direct
"
:
{
"
className
"
:
"
ui-block-
"
+
util
.
toLetter
(
j
+
1
).
toLowerCase
()}
"
direct
"
:
{
"
className
"
:
"
ui-block-
"
+
util
.
toLetter
(
j
+
1
).
toLowerCase
()
}
});
};
...
...
@@ -1296,7 +1300,7 @@
* @return {object} fragment
*/
factory
.
widget
.
controlbar
=
function
(
spec
)
{
var
container
,
slot
,
pass
,
class_list
,
wrap
;
var
container
,
slot
,
pass
,
class_list
;
pass
=
function
(
container
)
{
return
{
...
...
@@ -1304,7 +1308,7 @@
"
child_selector
"
:
container
.
firstElementChild
||
container
,
"
add_on_dom
"
:
spec
.
target
===
"
document
"
};
}
}
;
container
=
document
.
createDocumentFragment
();
slot
=
spec
.
slot
;
...
...
@@ -1360,15 +1364,15 @@
*/
// NOTE: Needs JQM pre-enhancement if outside page!
factory
.
widget
.
panel
=
function
(
spec
)
{
var
container
,
id
,
wrap
,
fragment
,
closer
,
element
;
var
container
,
id
,
wrap
,
closer
;
container
=
document
.
createDocumentFragment
();
id
=
spec
.
id
||
((
spec
.
data_url
||
"
global
"
)
+
"
-panel
"
);
// content wrapper with optional close button
wrap
=
function
(
j
,
len
)
{
switch
(
true
)
{
case
(
j
===
0
):
var
fragment
,
element
;
if
(
j
===
0
)
{
fragment
=
document
.
createDocumentFragment
();
element
=
factory
.
element
({
"
type
"
:
"
div
"
,
...
...
@@ -1380,18 +1384,18 @@
element
.
appendChild
(
closer
);
}
fragment
.
appendChild
(
element
);
return
fragment
;
case
(
j
===
len
-
1
):
return
factory
.
element
({
}
else
if
(
j
===
len
-
1
)
{
fragment
=
factory
.
element
({
"
type
"
:
"
div
"
,
"
direct
"
:
{
"
className
"
:
"
panel_element panel_element_last
"
}
});
default
:
return
factory
.
element
({
}
else
{
fragment
=
factory
.
element
({
"
type
"
:
"
div
"
,
"
direct
"
:
{
"
className
"
:
"
panel_element
"
}
});
}
return
fragment
;
};
// panel
...
...
@@ -1459,7 +1463,7 @@
* @return HTML fragment
*/
factory
.
widget
.
form
=
function
(
spec
)
{
var
container
,
form_id
,
form
,
item_id
,
stamp
,
encode
,
sauce
,
captcha
,
wrap
;
var
container
,
form_id
,
form
,
item_id
,
stamp
,
captcha
,
sauce
,
wrap
;
container
=
document
.
createDocumentFragment
();
form_id
=
"
form_
"
+
util
.
uuid
();
...
...
@@ -1500,6 +1504,7 @@
// TODO: only if shim is available!
//encode = window.btoa || window.shim.Base64.encode;
//sauce = encode(stamp.toString() + spec.secret_hash);
sauce
=
undefined
;
form
.
appendChild
(
factory
.
element
({
"
type
"
:
"
input
"
,
...
...
@@ -1556,6 +1561,7 @@
// assemble
container
.
appendChild
(
form
);
wrap
=
undefined
;
return
{
"
fragment
"
:
container
,
"
child_selector
"
:
container
.
querySelectorAll
(
"
form
"
)[
0
],
...
...
@@ -1609,13 +1615,12 @@
**/
factory
.
widget
.
carousel
=
function
(
spec
)
{
var
fragment
,
generator
,
empty_string
,
has_handles
,
make_handle
,
is_thumb
,
controller
,
control
,
i
,
id
,
radio_id
;
controller
,
i
,
id
,
radio_id
;
// makes carousel elements
generator
=
function
(
element
,
wrapper
,
i
)
{
var
item
,
config
,
target
,
has_link
;
var
item
,
target
,
has_link
;
config
=
wrapper
.
property_dict
;
has_link
=
element
.
href
;
item
=
factory
.
element
({
"
type
"
:
"
li
"
,
...
...
@@ -1652,12 +1657,12 @@
"
href
"
:
"
#
"
,
"
className
"
:
"
ui-carousel-handle ui-carousel-handle-
"
+
direction
+
"
ui-btn ui-btn-icon-notext ui-corner-all ui-icon-carat-
"
+
direction
.
slice
(
0
,
1
)
+
"
ui-shadow translate
"
direction
.
slice
(
0
,
1
)
+
"
ui-shadow translate
"
},
"
attributes
"
:
{
"
data-i18n
"
:
"
global_dict.
"
+
direction
},
"
logic
"
:
{
"
text
"
:
direction
}
});
}
}
;
fragment
=
document
.
createDocumentFragment
();
empty_string
=
""
;
...
...
@@ -1803,24 +1808,26 @@
// TODO: add collapsible support if needed
// TODO: dividers? will not be in spec, so can only be listview option!
factory
.
widget
.
listview
=
function
(
spec
)
{
var
fragment
,
filter
,
has_filter
,
generator
;
var
fragment
,
has_filter
,
generator
;
// generate list item
generator
=
function
(
element
,
wrapper
,
i
)
{
var
divider
,
static_item
,
theme
,
config
,
auto
,
last
,
item
,
target
,
content
;
var
divider
,
static_item
,
theme
,
config
,
auto
,
last
,
item
,
target
,
list
,
content
;
config
=
wrapper
.
property_dict
;
divider
=
element
.
type
===
"
divider
"
?
true
:
undefined
;
static_item
=
(
element
.
href
===
undefined
&&
!
divider
)
?
true
:
undefined
;
theme
=
config
.
divider_theme
||
config
.
theme
||
"
inherit
"
;
// autodividers (TODO: does this work?)
// autodividers (TODO: does this work?
NO!!! do with i!
)
if
(
config
.
autodividers
)
{
auto
=
element
.
text
[
0
].
text
.
slice
(
0
,
1
).
toUpperCase
();
if
(
last
!==
auto
)
{
list
=
document
.
createDocumentFragment
();
list
.
appendChild
(
factory
.
element
({
"
type
"
:
"
li
"
,
"
direct
"
:{
"
direct
"
:
{
"
className
"
:
"
ui-li-divider ui-bar-
"
+
theme
+
(
i
===
0
?
"
ui-first-child
"
:
((
i
===
config
.
length
-
1
)
?
...
...
@@ -1838,7 +1845,11 @@
target
=
document
.
createDocumentFragment
();
}
else
{
element
.
is_main
=
true
;
target
=
factory
.
util
.
generateContentElement
(
"
link
"
,
element
,
config
)[
0
];
target
=
factory
.
util
.
generateContentElement
(
"
link
"
,
element
,
config
)[
0
];
}
// generate contents, split button will return [frag1, frag2, class_list]
...
...
@@ -1885,7 +1896,7 @@
// NOTE: if input provided, the filter is already there!
if
(
spec
.
filter
&&
spec
.
input
===
undefined
)
{
has_filter
=
true
;
f
ilter
=
factory
.
widget
.
formElement
({
f
ragment
.
appendChild
(
factory
.
widget
.
formElement
({
"
type
"
:
"
input
"
,
"
direct
"
:
{
"
id
"
:
"
filter_
"
+
(
spec
.
id
||
"
items
"
),
...
...
@@ -1901,7 +1912,7 @@
"
logic
"
:
{
"
clear
"
:
"
true
"
}
});
})
)
;
}
fragment
.
appendChild
(
factory
.
element
({
...
...
@@ -2033,7 +2044,7 @@
};
generator
=
function
(
element
,
wrapper
,
i
)
{
var
item
,
quirk_dict
,
row
,
temp
,
cell
,
j
,
field
,
link
,
logic
,
faux_id
,
var
quirk_dict
,
row
,
temp
,
cell
,
j
,
field
,
link
,
logic
,
faux_id
,
attributes
,
property
,
snippet
,
title
,
k
,
button
,
group
,
dict
,
set
,
wrap
,
lookup
,
item_href
;
...
...
@@ -2047,13 +2058,11 @@
// checkbox/radio
if
(
!
quirk_dict
.
no_items
&&
(
quirk_dict
.
check
||
quirk_dict
.
radio
))
{
switch
(
true
)
{
case
(
quirk_dict
.
global_check
):
if
(
quirk_dict
.
global_check
)
{
element
.
action
=
"
check_all
"
;
break
;
case
(
quirk_dict
.
check
&&
!
quirk_dict
.
global_check
):
}
if
(
quirk_dict
.
check
&&
!
quirk_dict
.
global_check
)
{
element
.
action
=
"
check_all_visible
"
;
break
;
}
cell
=
factory
.
element
({
"
type
"
:
"
th
"
});
faux_id
=
wrap
?
element
.
action
:
"
select_
"
+
element
[
0
].
id
;
...
...
@@ -2072,7 +2081,8 @@
"
type
"
:
"
input
"
,
"
direct
"
:
{
"
id
"
:
(
wrap
?
quirk_dict
.
reference
+
"
_
"
:
""
)
+
faux_id
,
"
name
"
:
quirk_dict
.
check
?
faux_id
:
"
radio_
"
+
quirk_dict
.
reference
,
"
name
"
:
quirk_dict
.
check
?
faux_id
:
"
radio_
"
+
quirk_dict
.
reference
,
"
className
"
:
element
.
action
?
"
action
"
:
""
},
"
attributes
"
:
dict
,
...
...
@@ -2120,7 +2130,7 @@
// action menu (calling widget is cheating...)
if
(
field
.
action_list
)
{
group
=
factory
.
widget
.
controlgroup
({
"
direction
"
:
"
horizontal
"
});
group
=
factory
.
widget
.
controlgroup
({
"
direction
"
:
"
horizontal
"
});
for
(
k
=
0
;
k
<
field
.
action_list
.
length
;
k
+=
1
)
{
button
=
field
.
action_list
[
k
];
if
(
field
.
id
)
{
...
...
@@ -2149,8 +2159,8 @@
link
=
group
.
fragment
;
// link/sorting
}
else
if
(
quirk_dict
.
link
&&
field
.
href
||
(
wrap
&&
quirk_dict
.
sortable
&&
field
.
sort
)
}
else
if
(
quirk_dict
.
link
&&
(
field
.
href
||
(
wrap
&&
quirk_dict
.
sortable
&&
field
.
sort
)
)
)
{
// header link (sorting) or href link
link
=
factory
.
element
({
...
...
@@ -2343,7 +2353,7 @@
crumb
=
spec
.
children
[
i
];
if
(
typeof
crumb
===
"
string
"
)
{
pass
=
{
"
href
"
:
base
+
=
(
patch
+
crumb
),
"
href
"
:
base
+
(
patch
+
crumb
),
"
text
"
:
crumb
};
patch
=
"
/
"
;
...
...
@@ -2377,7 +2387,11 @@
len
=
arr
.
length
;
for
(
k
=
0
;
k
<
len
;
k
+=
1
)
{
block
=
arr
[
k
];
content
=
factory
.
util
.
generateContentElement
(
block
.
type
,
block
,
config
);
content
=
factory
.
util
.
generateContentElement
(
block
.
type
,
block
,
config
);
class_string
+=
content
[
1
];
if
(
content
[
1
]
===
split
)
{
...
...
@@ -2403,7 +2417,7 @@
// TODO: class_string only works for listview, could be expanded
// TODO: this is crap though....
factory
.
util
.
generateContentElement
=
function
(
type
,
spec
,
config
)
{
var
id
,
is_type
,
is_main
,
no_icon
,
input_dict
,
container
,
is_text
;
var
id
,
is_type
,
is_main
,
no_icon
,
input_dict
,
container
;
switch
(
type
)
{
...
...
@@ -2467,15 +2481,16 @@
"
href
"
:
spec
.
href
||
"
#
"
,
"
className
"
:
"
ui-btn
"
+
"
ui-btn-
"
+
(
config
.
split_theme
||
config
.
theme
||
"
inherit
"
)
+
(
no_icon
?
"
"
:
(
is_main
?
"
ui-btn-icon-right
"
:
(
no_icon
?
"
"
:
(
is_main
?
"
ui-btn-icon-right
"
:
"
ui-btn-icon-
"
+
(
spec
.
iconpos
||
"
notext
"
))
+
"
ui-icon-
"
+
(
config
.
icon
||
spec
.
icon
||
"
carat-r
"
))
},
"
attributes
"
:
{
"
title
"
:
spec
.
title
||
""
,
"
data-i18n
"
:
"
[title]
"
+
(
spec
.
title_i18n
||
""
)
+
"
;
"
+
(
spec
.
text_i18n
||
""
)
"
data-i18n
"
:
"
[title]
"
+
(
spec
.
title_i18n
||
""
)
+
"
;
"
+
(
spec
.
text_i18n
||
""
)
},
"
logic
"
:
{
"
logic
"
:
{
"
rel
"
:
spec
.
external
?
"
external
"
:
null
,
"
data-ajax
"
:
spec
.
external
?
"
false
"
:
null
,
"
text
"
:
spec
.
text
||
null
...
...
@@ -2521,7 +2536,6 @@
"
className
"
:
"
ui-li-count ui-body-
"
+
(
config
.
count_theme
||
config
.
theme
)
},
"
attributes
"
:
{},
"
logic
"
:
{
"
text
"
:
spec
.
count
}
}),
"
ui-li-has-count
"
];
...
...
@@ -2542,7 +2556,6 @@
"
data-i18n
"
:
spec
.
text_i18n
||
spec
.
title_i18n
||
null
}
}),
""
];
}
};
...
...
@@ -2579,8 +2592,10 @@
container
.
unshift
(
util
.
mergeObject
(
util
.
cloneObject
(
item
),
{
"
text
"
:
content_dict
.
dynamic
||
content_dict
.
message
||
"
No items found.
"
,
"
text_i18n
"
:
content_dict
.
message_i18n
||
"
validation_dict.no_items_found
"
,
"
text
"
:
content_dict
.
dynamic
||
content_dict
.
message
||
"
No items found.
"
,
"
text_i18n
"
:
content_dict
.
message_i18n
||
"
validation_dict.no_items_found
"
,
"
colspan
"
:
counter
||
count
}
));
...
...
@@ -2594,12 +2609,16 @@
"
center
"
:
{
"
text
"
:
[{
"
type
"
:
"
h1
"
,
"
text
"
:
content_dict
.
dynamic
||
content_dict
.
message
||
"
No items found.
"
,
"
text_i18n
"
:
content_dict
.
message_i18n
||
"
validation_dict.no_items_found
"
"
text
"
:
content_dict
.
dynamic
||
content_dict
.
message
||
"
No items found.
"
,
"
text_i18n
"
:
content_dict
.
message_i18n
||
"
validation_dict.no_items_found
"
}]
}
};
default
:
alert
(
"
placeholder for no items missing
"
);
break
;
default
:
alert
(
"
placeholder for no items missing
"
);
break
;
}
};
...
...
@@ -2679,13 +2698,13 @@
"
data-type
"
:
"
search
"
,
"
type
"
:
"
search
"
},
"
logic
"
:
{
"
clear
"
:
"
true
"
,
"
action
"
:
"
search
"
}
"
logic
"
:
{
"
clear
"
:
"
true
"
,
"
action
"
:
"
search
"
}
}];
for
(
i
=
0
;
i
<
spec
.
info_list
.
length
;
i
+=
1
)
{
element_list
.
push
({
"
type
"
:
"
div
"
,
"
direct
"
:
{
"
className
"
:
"
info
"
},
"
direct
"
:
{
"
className
"
:
"
info
"
},
"
attributes
"
:
{
"
data-info
"
:
spec
.
info_list
[
i
]}
});
}
...
...
@@ -2716,7 +2735,11 @@
for
(
n
=
0
;
n
<
spec
.
option_list
.
length
;
n
+=
1
)
{
option
=
spec
.
option_list
[
n
];
option_list
.
push
({
"
value
"
:
option
.
value
,
"
text
"
:
option
.
text
,
"
text_i18n
"
:
option
.
text_i18n
});
option_list
.
push
({
"
value
"
:
option
.
value
,
"
text
"
:
option
.
text
,
"
text_i18n
"
:
option
.
text_i18n
});
}
config
=
{
...
...
@@ -2730,43 +2753,43 @@
"
property_dict
"
:
{
"
direction
"
:
"
horizontal
"
},
"
children
"
:
[{
"
type
"
:
"
a
"
,
"
direct
"
:
{
"
className
"
:
"
action
"
,
"
href
"
:
"
#
"
},
"
attributes
"
:{
"
direct
"
:
{
"
className
"
:
"
action
"
,
"
href
"
:
"
#
"
},
"
attributes
"
:
{
"
data-i18n
"
:
"
global_dict.first
"
,
"
data-action
"
:
"
first
"
,
"
data-icon
"
:
"
step-backward
"
,
"
data-iconpos
"
:
"
notext
"
},
"
logic
"
:
{
"
text
"
:
"
First
"
}
"
logic
"
:
{
"
text
"
:
"
First
"
}
},
{
"
type
"
:
"
a
"
,
"
direct
"
:
{
"
className
"
:
"
action
"
,
"
href
"
:
"
#
"
},
"
attributes
"
:{
"
direct
"
:
{
"
className
"
:
"
action
"
,
"
href
"
:
"
#
"
},
"
attributes
"
:
{
"
data-i18n
"
:
"
global_dict.previous
"
,
"
data-action
"
:
"
prev
"
,
"
data-icon
"
:
"
backward
"
,
"
data-iconpos
"
:
"
notext
"
},
"
logic
"
:
{
"
text
"
:
"
Previous
"
}
"
logic
"
:
{
"
text
"
:
"
Previous
"
}
},
{
"
type
"
:
"
select
"
,
"
direct
"
:{
"
id
"
:
"
select_
"
+
util
.
uuid
(),
"
className
"
:
"
action
"
},
"
type
"
:
"
select
"
,
"
direct
"
:
{
"
id
"
:
"
select_
"
+
util
.
uuid
(),
"
className
"
:
"
action
"
},
"
attributes
"
:
{
"
data-icon
"
:
"
bars
"
,
"
data-action
"
:
"
limit
"
,
"
data-iconpos
"
:
"
notext
"
"
data-icon
"
:
"
bars
"
,
"
data-action
"
:
"
limit
"
,
"
data-iconpos
"
:
"
notext
"
},
"
logic
"
:
{
"
options
"
:
option_list
}
"
logic
"
:
{
"
options
"
:
option_list
}
},
{
"
type
"
:
"
a
"
,
"
direct
"
:
{
"
className
"
:
"
action
"
,
"
href
"
:
"
#
"
},
"
attributes
"
:{
"
direct
"
:
{
"
className
"
:
"
action
"
,
"
href
"
:
"
#
"
},
"
attributes
"
:
{
"
data-i18n
"
:
"
global_dict.next
"
,
"
data-action
"
:
"
next
"
,
"
data-icon
"
:
"
forward
"
,
"
data-iconpos
"
:
"
notext
"
},
"
logic
"
:
{
"
text
"
:
"
Next
"
}
"
logic
"
:
{
"
text
"
:
"
Next
"
}
}]
}]
};
...
...
@@ -2775,14 +2798,14 @@
if
(
!
app
.
storage_dict
.
property_dict
.
skip_total_records
)
{
config
.
children
[
0
].
children
.
push
({
"
type
"
:
"
a
"
,
"
direct
"
:
{
"
className
"
:
"
action
"
,
"
href
"
:
"
#
"
},
"
attributes
"
:{
"
direct
"
:
{
"
className
"
:
"
action
"
,
"
href
"
:
"
#
"
},
"
attributes
"
:
{
"
data-i18n
"
:
"
global_dict.last
"
,
"
data-action
"
:
"
last
"
,
"
data-icon
"
:
"
step-forward
"
,
"
data-iconpos
"
:
"
notext
"
},
"
logic
"
:
{
"
text
"
:
"
Last
"
}
"
logic
"
:
{
"
text
"
:
"
Last
"
}
});
}
...
...
@@ -2798,7 +2821,7 @@
* @param {obj} object Action object (popupbeforeposition)
*/
factory
.
util
.
generateDynamicContents
=
function
(
obj
)
{
var
i
,
j
,
promises
,
fragment
,
element
,
reference
,
state
,
$el
;
var
element
,
reference
,
state
,
$el
;
element
=
obj
.
gadget
;
reference
=
element
.
getAttribute
(
"
data-reference
"
);
...
...
@@ -2808,7 +2831,6 @@
if
(
state
!==
reference
)
{
if
(
reference
===
null
)
{
app
.
util
.
error
(
"
Global Bindings: No element handler
"
);
fragment
=
factory
.
element
(
"
p
"
,
{},
{},
{
"
text
"
:
"
No element handler
"
});
}
else
{
element
.
setAttribute
(
"
data-state
"
,
reference
);
element
.
setAttribute
(
"
data-reference
"
,
reference
);
...
...
@@ -2816,7 +2838,6 @@
// empty gadget and reload
// TODO: how to replace in javaScript?
element
.
innerHTML
=
""
;
promises
=
[];
// fetch content
storage
.
fetchConfigAttachment
({
...
...
@@ -2908,230 +2929,6 @@
factory
.
util
.
setDynamicPointer
(
obj
,
"
ui_panel_sales
"
);
},
// =================================================
/**
* POST an object
* @method new
* @param {object} obj Action Object
**/
"
new
"
:
function
(
obj
)
{
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
app
.
util
.
loader
(
""
,
"
status_dict.saved
"
,
"
check
"
);
app
.
navigate
(
obj
,
response
);
})
.
fail
(
function
(
error
)
{
switch
(
error
.
status
)
{
case
408
:
app
.
util
.
loader
(
""
,
"
status_dict.timeout
"
,
"
clock-o
"
);
break
;
case
400
:
app
.
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban
"
);
break
;
default
:
app
.
util
.
loader
(
""
,
"
status_dict.error
"
,
"
ban
"
);
break
;
}
});
},
/**
* PUT an object
* @method update
* @param {object} obj Action Object
**/
"
update
"
:
function
(
obj
)
{
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
app
.
util
.
loader
(
""
,
"
status_dict.saved
"
,
"
check
"
);
app
.
navigate
(
obj
,
response
);
})
.
fail
(
function
(
error
)
{
switch
(
error
.
status
)
{
case
408
:
app
.
util
.
loader
(
""
,
"
status_dict.timeout
"
,
"
clock-o
"
);
break
;
case
400
:
app
.
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban
"
);
break
;
default
:
app
.
util
.
loader
(
""
,
"
status_dict.error
"
,
"
ban
"
);
break
;
}
});
},
/**
* update server scope - custom action, because my_ not implemented,
* same for ticket status updates
* @method update
* @param {object} obj Action Object
**/
"
update_scope
"
:
function
(
obj
)
{
obj
.
force_data
=
true
;
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
app
.
util
.
loader
(
""
,
"
status_dict.saved
"
,
"
check
"
);
app
.
navigate
(
obj
,
response
);
})
.
fail
(
function
(
error
)
{
switch
(
error
.
status
)
{
case
408
:
app
.
util
.
loader
(
""
,
"
status_dict.timeout
"
,
"
clock-o
"
);
break
;
default
:
app
.
util
.
loader
(
""
,
"
status_dict.error
"
,
"
ban
"
);
break
;
}
});
},
/**
* Install a service on a machine
* @method install
* @param {object} obj Action Object
**/
"
install
"
:
function
(
obj
)
{
// HACK: no good way to refer to the calling server!
obj
.
state
.
reference
=
window
.
decodeURIComponent
(
obj
.
state
.
fragment_list
[
1
]);
storage
.
write
(
obj
);
},
/**
* Revoke a SSL certificate - custom action, so extra entry
* @method revoke_ssl
* @param {object} obj Action Object
**/
"
revoke_ssl
"
:
function
(
obj
)
{
app
.
util
.
loader
(
""
,
"
status_dict.updating
"
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
app
.
util
.
loader
(
""
,
"
status_dict.ssl_revoked
"
,
"
check
"
);
})
.
fail
(
function
(
error
)
{
app
.
util
.
loader
(
""
,
"
status_dict.ssl_no
"
,
"
ban
"
);
});
},
/**
* Request SSL certificate
* @method request_ssl
* @param {object} obj Action Object
**/
"
request_ssl
"
:
function
(
obj
)
{
app
.
util
.
loader
(
""
,
"
status_dict.requesting
"
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
// get certificate!
flux
=
flux
||
{};
flux
.
_temp
=
util
.
parse
(
response
.
_temp
);
app
.
util
.
loader
(
""
,
"
status_dict.ssl_generated
"
,
"
check
"
);
app
.
navigate
(
obj
,
response
);
})
.
fail
(
function
(
error
)
{
app
.
util
.
loader
(
""
,
"
status_dict.ssl_error
"
,
"
ban
"
);
});
},
/**
* Start a software instance
* @method start_instance
* @param {object} obj Action Object
**/
"
destroy
"
:
function
(
obj
)
{
app
.
util
.
loader
(
""
,
"
status_dict.destroying
"
,
"
trash
"
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
app
.
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
app
.
navigate
(
obj
,
response
);
})
.
fail
(
app
.
util
.
error
);
},
/**
* Start a software instance
* @method start
* @param {object} obj Action Object
**/
"
start
"
:
function
(
obj
)
{
app
.
util
.
loader
(
""
,
"
status_dict.starting
"
,
"
signal
"
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
app
.
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
})
.
fail
(
app
.
util
.
error
);
},
/**
* Stop a software instance
* @method stop_instance
* @param {object} obj Action Object
**/
"
stop
"
:
function
(
obj
)
{
app
.
util
.
loader
(
""
,
"
status_dict.stopping
"
,
"
ban
"
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
app
.
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
})
.
fail
(
app
.
util
.
error
);
},
/**
* GET an object
* @method get
* @param {object} obj Action Object
**/
"
get
"
:
function
(
obj
)
{
storage
.
fetch
(
obj
);
},
/**
* Download a file (as pdf)
* @method download
* @param {object} obj Action Object
**/
"
download
"
:
function
(
obj
)
{
app
.
util
.
loader
(
""
,
"
status_dict.downloading
"
);
storage
.
fetch
(
obj
)
.
then
(
function
(
response
)
{
app
.
util
.
loader
(
""
,
"
status_dict.rendering
"
);
window
.
location
.
href
=
response
.
data
.
_links
.
slapos_jump
.
href
;
})
.
fail
(
app
.
util
.
error
);
},
// ==============================================
// /**
// * Destroy an installation = service object
// * @method destroy
// * @param {object} obj Action Object
// **/
// "destroy": function (obj) {
// storage.remove(obj);
// },
/**
* Start a software instance
* @method start_instance
* @param {object} obj Action Object
**/
"
destroy_installation
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
id
=
obj
.
state
.
fragment_list
[
1
],
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
app
.
util
.
loader
(
""
,
"
status_dict.destroying
"
,
"
trash
"
);
jIO
.
util
.
ajax
({
"
url
"
:
window
.
decodeURIComponent
(
element
.
href
),
"
type
"
:
element
.
getAttribute
(
"
data-method
"
),
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
})
.
then
(
function
(
answer
)
{
app
.
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#servers
"
);
})
.
fail
(
function
(
error
)
{
app
.
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
app
.
util
.
error
(
error
);
if
(
util
.
parse
(
error
.
target
).
responseText
===
""
&&
id
&&
obj
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
decode
?
id
:
window
.
encodeURIComponent
(
id
)));
}
});
},
// ==============================================================
/**
* Look up single value from dict
* @method translateLookup
...
...
@@ -3508,7 +3305,7 @@
quirk_dict
=
wrapper
.
property_dict
;
record
=
item
.
doc
;
id
=
record
[
quirk_dict
.
link_identifier
]
||
record
[
"
_id
"
]
||
item
[
"
_id
"
]
;
id
=
record
[
quirk_dict
.
link_identifier
]
||
record
.
_id
||
item
.
_id
;
new_item
=
{};
// id
...
...
@@ -3527,11 +3324,18 @@
// loop field_list = cells
for
(
k
=
0
;
k
<
segment
.
field_list
.
length
;
k
+=
1
)
{
cell
=
util
.
mergeObject
(
new_item
,
util
.
cloneObject
(
segment
.
field_list
[
k
]));
cell
=
util
.
mergeObject
(
new_item
,
util
.
cloneObject
(
segment
.
field_list
[
k
])
);
// custom header (!) cells have text/i18n defined
if
(
!
cell
.
custom
)
{
cell
.
text
=
util
.
generateText
(
record
[
field
.
value
||
field
.
field
],
cell
,
record
);
cell
.
text
=
util
.
generateText
(
record
[
cell
.
value
||
cell
.
field
],
cell
,
record
);
cell
.
text_i18n
=
record
.
text_i18n
||
null
;
}
row
.
push
(
cell
);
...
...
@@ -3556,19 +3360,19 @@
// TODO: not nice & find better handling for text elements and i18n tags
// NOTE: make sure there is no "id" flying through here!!! only _id
map
.
listItem
=
function
(
item
,
wrapper
,
i
)
{
var
quirk_dict
,
core
,
section
,
pos
,
label
,
j
,
k
,
field
,
setter
,
record
,
property
,
source
,
new_item
,
id
,
key
,
obj
,
translation_fields
;
var
quirk_dict
,
section
,
pos
,
label
,
j
,
k
,
field
,
setter
,
record
,
new_item
,
id
,
key
,
obj
,
translation_fields
;
translation_fields
=
"
titletextlabel
"
;
quirk_dict
=
wrapper
.
property_dict
;
record
=
item
.
doc
;
id
=
record
[
quirk_dict
.
link_identifier
]
||
record
[
"
_id
"
]
||
item
[
"
_id
"
]
;
id
=
record
[
quirk_dict
.
link_identifier
]
||
record
.
_id
||
item
.
_id
;
new_item
=
{};
// radio
if
(
quirk_dict
.
radio
)
{
label
=
true
;
new_item
.
right
=
[{
"
type
"
:
"
radio
"
,
"
action
"
:
"
check
"
}];
new_item
.
right
=
[{
"
type
"
:
"
radio
"
,
"
action
"
:
"
check
"
}];
}
// checkbox
...
...
@@ -3630,8 +3434,8 @@
// TODO: should we wrap in span_12 here. why do we wrap at all, do with CSS
map
.
formItem
=
function
(
item
,
wrapper
,
i
)
{
var
helper
,
getHelp
,
j
,
k
,
segment
,
section
,
field
,
setValue
,
root
,
veto
,
textarea_value
,
override_value
,
value
,
field_value
,
validation_list
,
class_list
,
el
,
type
,
clear
,
alt_name
,
fetch_items
,
option_list
,
pass
,
textarea_value
,
override_value
,
value
,
field_value
,
validation_list
,
class_list
,
el
,
type
,
clear
,
alt_name
,
fetch_items
,
pass
,
field_list
,
l
,
m
,
section_list
,
container
,
disabled
,
readonly
;
getHelp
=
function
(
prop
)
{
...
...
@@ -3644,24 +3448,25 @@
};
// TODO: remove this crap or make it generic...
// set = setter_list ... JSLINT
setValue
=
function
(
setter
)
{
var
i
,
len
,
set_value
,
set_flux
,
setter_list
,
lookup_value
,
set_reference
;
var
n
,
len
,
set_value
,
set_flux
,
set
,
val
,
set_reference
;
if
(
setter
.
logic
)
{
set_reference
=
setter
.
logic
.
setReference
;
set_value
=
setter
.
logic
.
setValue
;
lookup_value
=
setter
.
logic
.
lookupValue
;
set
ter_list
=
setter
.
logic
.
setters
;
val
=
setter
.
logic
.
lookupValue
;
set
=
setter
.
logic
.
setters
;
set_flux
=
setter
.
logic
.
setFlux
;
if
(
set
ter_list
)
{
len
=
set
ter_list
.
length
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
if
(
lookup_value
)
{
if
(
set
)
{
len
=
set
.
length
;
for
(
n
=
0
;
n
<
len
;
n
+=
1
)
{
if
(
val
)
{
// FU§$%&/NG HAL
setter
.
logic
[
set
ter_list
[
i
]]
=
item
.
doc
[
lookup_value
[
i
][
0
]][
lookup_value
[
i
][
1
]][
lookup_value
[
i
][
2
]];
setter
.
logic
[
set
[
n
]]
=
item
.
doc
[
val
[
n
][
0
]][
val
[
n
][
1
]][
val
[
n
][
2
]];
}
else
{
setter
.
logic
[
set
ter_list
[
i
]]
=
item
.
doc
[
set_value
];
setter
.
logic
[
set
[
n
]]
=
item
.
doc
[
set_value
];
}
}
}
else
if
(
set_value
)
{
...
...
@@ -3688,11 +3493,9 @@
// NOTE: all children of a form will be passed through here, these can
// be ready HTML constructor objects, widgets or form elements
// requiring mapping (custom or based on element.field_dict)
switch
(
true
)
{
case
!!
item
.
direct
:
if
(
!!
item
.
direct
)
{
setValue
(
item
);
break
;
case
!!
item
.
generate
:
}
else
if
(
!!
item
.
generate
)
{
// we must declare wrap for non-form elements here, because they
// don't belong into any widget
container
=
getHelp
({
...
...
@@ -3700,10 +3503,8 @@
"
class_list
"
:
"
span_
"
+
(
item
.
property_dict
.
wrap
||
1
)
});
container
.
children
.
push
(
item
);
break
;
default
:
}
else
{
helper
=
getHelp
({
"
wrap
"
:
"
fragment
"
});
break
;
}
// nothing to do, pass back directly
...
...
@@ -3739,8 +3540,8 @@
root
=
item
.
field_dict
[
field
.
field
];
veto
=
util
.
mergeObject
(
field
.
overrides
||
{},
{
"
properties
"
:
{},
"
widget
"
:
{
}
}
);
{
"
properties
"
:
{},
"
widget
"
:
{}
}
);
value
=
item
.
doc
[
field
.
setValue
||
field
.
field
];
// flag false/missing field_dict
...
...
@@ -3759,9 +3560,8 @@
// easy way out if not enabled
// TODO: should be full field setup with label... and span
switch
(
true
)
{
case
(
veto
.
properties
.
enabled
===
false
||
root
.
properties
.
enabled
===
false
):
if
(
veto
.
properties
.
enabled
===
false
||
root
.
properties
.
enabled
===
false
)
{
pass
=
{
"
push
"
:
{
"
type
"
:
"
span
"
,
...
...
@@ -3770,8 +3570,7 @@
"
logic
"
:
{
"
text
"
:
field_value
}
}
};
break
;
case
(
veto
.
type
===
"
ImageField
"
||
root
.
type
===
"
ImageField
"
):
}
else
if
(
veto
.
type
===
"
ImageField
"
||
root
.
type
===
"
ImageField
"
)
{
pass
=
{
"
push
"
:
{
"
type
"
:
"
img
"
,
...
...
@@ -3779,7 +3578,6 @@
"
attributes
"
:
{
"
skip
"
:
true
}
}
};
break
;
}
// check for options (select elements), which need to be fetched
...
...
@@ -3802,7 +3600,9 @@
// required fields
if
(
root
.
properties
.
required
===
true
)
{
if
(
veto
.
properties
.
required
===
undefined
||
veto
.
properties
.
required
===
true
)
{
if
(
veto
.
properties
.
required
===
undefined
||
veto
.
properties
.
required
===
true
)
{
class_list
+=
"
required
"
;
}
}
...
...
@@ -3946,8 +3746,8 @@
"
attachment
"
:
fetch_items
,
"
pass
"
:
pass
}).
then
(
function
(
answer
)
{
var
i
,
j
,
value
,
option
,
len
,
loaded_options
,
el_type
,
radio_check
,
clone
,
clone_opt
,
group
,
push
,
group_id
;
var
o
,
p
,
new_value
,
option
,
len
,
loaded_options
,
el_type
,
radio_check
,
clone
,
clone_opt
,
group
,
push
,
group_id
;
loaded_options
=
answer
.
response
;
...
...
@@ -3956,16 +3756,16 @@
push
=
answer
.
pass
.
push
;
push
.
logic
.
options
=
util
.
parse
(
loaded_options
);
value
=
push
.
logic
.
value
;
new_
value
=
push
.
logic
.
value
;
len
=
loaded_options
.
length
;
el_type
=
push
.
attributes
.
type
;
radio_check
=
(
el_type
===
"
radio
"
||
el_type
===
"
checkbox
"
);
// TODO: set value here? this is a mapper??!
if
(
value
)
{
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
option
=
loaded_options
[
i
];
if
(
option
.
value
===
value
)
{
if
(
new_
value
)
{
for
(
o
=
0
;
o
<
len
;
o
+=
1
)
{
option
=
loaded_options
[
o
];
if
(
option
.
value
===
new_
value
)
{
option
.
checked
=
true
;
option
.
selected
=
"
selected
"
;
}
...
...
@@ -3989,15 +3789,15 @@
"
children
"
:
[]
};
for
(
j
=
0
;
j
<
len
;
j
+=
1
)
{
clone_opt
=
loaded_options
[
j
];
for
(
p
=
0
;
p
<
len
;
p
+=
1
)
{
clone_opt
=
loaded_options
[
p
];
clone
=
{
"
type
"
:
"
input
"
,
"
logic
"
:
util
.
cloneObject
(
push
.
logic
),
"
attributes
"
:
util
.
cloneObject
(
push
.
attributes
),
"
direct
"
:
util
.
cloneObject
(
push
.
direct
)
};
clone
.
direct
.
id
+=
"
_
"
+
j
;
clone
.
direct
.
id
+=
"
_
"
+
p
;
if
(
clone_opt
.
checked
)
{
clone
.
direct
.
checked
=
true
;
}
...
...
@@ -4038,7 +3838,7 @@
for
(
m
=
0
;
m
<
section_response_list
.
length
;
m
+=
1
)
{
helper
.
children
.
push
(
section_response_list
[
m
]);
}
return
RSVP
.
resolve
(
helper
)
return
RSVP
.
resolve
(
helper
)
;
})
.
fail
(
app
.
util
.
error
);
};
...
...
@@ -4066,40 +3866,39 @@
// there is no need to look it up in pass.config.property_dict...
// TODO: jump is bad, it is the lookup for the data to display. rename!
storage
.
fetch
=
function
(
obj
)
{
var
pass
,
query
,
method
,
map
,
config
,
answer
,
lookup
,
pointer
,
action_id
,
var
pass
,
query
,
method
,
map
per
,
config
,
answer
,
lookup
,
pointer
,
action_id
,
quirk
;
pass
=
obj
.
pass
;
quirk
=
obj
.
state
||
pass
.
config_dict
;
lookup
=
obj
.
state
||
quirk
.
property_dict
||
storage
.
obj
;
query
=
obj
.
query
||
lookup
.
query
||
storage
.
obj
;
pointer
=
(
lookup
[
"
url_pointer
"
]
||
storage
.
obj
).
jump
;
pointer
=
(
lookup
.
url_pointer
||
storage
.
obj
).
jump
;
// TODO: action > id, this should be triggered via form submit not link!
action_id
=
((
obj
.
element
||
storage
.
obj
).
href
||
""
).
split
(
"
/
"
).
pop
();
if
(
action_id
)
{
pointer
=
undefined
;
query
=
{
"
_id
"
:
window
.
decodeURIComponent
(
action_id
)}
query
=
{
"
_id
"
:
window
.
decodeURIComponent
(
action_id
)}
;
}
switch
(
true
)
{
// F%&/() JSLINT...
if
(
!!
pointer
)
{
// TODO: "hack" for forcing get into allDocs, don't overwrite criteria!
case
!!
pointer
:
map
=
"
values
"
;
mapper
=
"
values
"
;
query
.
select_list
=
query
.
select_list
||
pass
.
data_dict
.
field_list
;
query
.
limit
=
query
.
limit
||
pass
.
config_dict
.
initial_query
.
limit
;
break
;
case
((
query
.
select_list
||
storage
.
arr
).
length
>
0
&&
!
query
.
include_docs
):
map
=
"
values
"
;
break
;
case
(
!!
query
.
_id
):
map
=
"
single_item
"
;
}
else
if
((
query
.
select_list
||
storage
.
arr
).
length
>
0
&&
!
query
.
include_docs
)
{
mapper
=
"
values
"
;
}
else
if
(
!!
query
.
_id
)
{
mapper
=
"
single_item
"
;
method
=
"
get
"
;
config
=
{
"
_view
"
:
quirk
.
view
};
break
;
}
// TODO: remove - pass custom query to storage
...
...
@@ -4116,21 +3915,27 @@
if
(
action_id
)
{
return
response
;
}
answer
=
storage
.
mapResponse
(
response
,
map
);
answer
=
storage
.
mapResponse
(
response
,
map
per
);
}
return
{
"
response
"
:
answer
||
response
,
"
pass
"
:
pass
};
}).
fail
(
function
(
error
)
{
}).
fail
(
function
(
error
)
{
switch
(
error
.
status
)
{
case
408
:
app
.
util
.
loader
(
""
,
"
status_dict.timeout
"
,
"
clock-o
"
);
break
;
case
400
:
app
.
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban
"
);
break
;
default
:
app
.
util
.
loader
(
""
,
"
status_dict.error
"
,
"
ban
"
);
break
;
case
408
:
app
.
util
.
loader
(
""
,
"
status_dict.timeout
"
,
"
clock-o
"
);
break
;
case
400
:
app
.
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban
"
);
break
;
default
:
app
.
util
.
loader
(
""
,
"
status_dict.error
"
,
"
ban
"
);
break
;
}
app
.
util
.
error
(
error
)
app
.
util
.
error
(
error
)
;
});
}
,
}
;
/**
* Write to storage = POST or PUT
...
...
@@ -4140,10 +3945,10 @@
// TODO: storage.add included prefetch of field_items and validation
// TODO: storage.add deleted identifier if create_new was set
storage
.
write
=
function
(
obj
)
{
var
form
,
data
,
valid
,
prefix
,
config
,
method
,
action
,
pointer
,
id
;
var
form
,
data
,
valid
,
prefix
,
config
,
method
,
action
,
pointer
;
form
=
obj
.
form
;
pointer
=
(
obj
.
element
||
storage
.
span
).
getAttribute
(
"
data-action
"
)
,
pointer
=
(
obj
.
element
||
storage
.
span
).
getAttribute
(
"
data-action
"
)
;
action
=
(
obj
.
state
.
url_pointer
||
storage
.
obj
)[
pointer
];
config
=
{};
prefix
=
obj
.
id
+
"
_
"
;
...
...
@@ -4151,7 +3956,7 @@
if
(
valid
)
{
data
=
obj
.
sample_data
||
storage
.
parseForm
(
valid
,
prefix
,
true
);
// TODO: remove, used for update scope,
which does no
t honor form definition
// TODO: remove, used for update scope,
doesn'
t honor form definition
if
(
obj
.
force_data
)
{
config
.
_force_data
=
true
;
}
...
...
@@ -4180,10 +3985,9 @@
return
RSVP
.
resolve
(
app
.
storage_dict
.
items
[
method
||
"
post
"
](
data
,
config
)
);
}
else
{
}
app
.
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban
"
);
return
RSVP
.
reject
({
"
status
"
:
400
});
}
};
/**
...
...
@@ -4232,54 +4036,7 @@
}
// NOTE: throw to get back in success chain!!!
throw
error
;
}
);
};
/**
* Load files from disk (fallback, not using storage)
* @method loadFromDiskAndSave
* @param {object} obj Configuration object (may include pass)
* @return {object} object
*/
// TODO: put/putAttachment should be set somewhere more general!
// TODO: merge with fetch/write - requires attachment and storage handling
storage
.
oldload
=
function
(
obj
)
{
var
url
,
destination
;
// fetch and store if set
return
util
.
ajax
({
"
url
"
:
url
})
.
then
(
function
(
event
)
{
destination
=
obj
.
store
||
app
.
storage_dict
.
settings
;
if
(
!
destination
)
{
app
.
util
.
error
(
"
load: storage not defined
"
);
return
RSVP
.
all
([]);
}
return
destination
.
put
({
"
_id
"
:
(
obj
.
file
||
"
settings
"
)})
.
then
(
function
()
{
return
destination
.
putAttachment
({
"
_id
"
:
(
obj
.
file
||
"
settings
"
),
"
_attachment
"
:
(
obj
.
attachment
||
app
.
storage_dict
.
property_dict
.
name_dict
.
configuration
),
"
_data
"
:
JSON
.
stringify
(
util
.
parse
(
event
.
target
.
responseText
)),
"
_mimetype
"
:
"
application/json
"
});
})
.
fail
(
app
.
util
.
error
);
})
.
then
(
function
(
response
)
{
if
(
obj
.
pass
)
{
return
{
"
response
"
:
response
,
"
pass
"
:
obj
.
pass
};
}
return
response
;
})
.
fail
(
app
.
util
.
error
);
};
/**
...
...
@@ -4355,14 +4112,13 @@
*/
// WARNING: jIO dependency!
storage
.
parseQuery
=
function
(
query
,
type
,
key
,
value
,
field_list
,
restore
)
{
var
property
,
wrap
,
query_object
,
query_clean
,
default_query
,
obj
,
is_value
,
i
,
is_id
,
decode
;
var
wrap
,
query_object
,
query_clean
,
default_query
,
obj
,
is_value
,
i
,
is_id
;
is_value
=
value
&&
value
!==
""
;
is_id
=
query
&&
query
.
query
&&
query
.
query
.
_id
;
// "id" = "bar" => THIS SHOULD BE GET!
if
(
is_value
&&
key
&&
key
===
"
_id
"
||
is_id
)
{
if
(
(
is_value
&&
key
&&
key
===
"
_id
"
)
||
is_id
)
{
obj
=
{
"
_id
"
:
window
.
decodeURIComponent
(
is_id
?
query
.
query
.
_id
:
value
)};
// ALLDOCS
...
...
@@ -4418,8 +4174,11 @@
wrap
=
""
;
for
(
i
=
0
;
i
<
field_list
.
length
;
i
+=
1
)
{
if
(
!
util
.
findKey
(
(
query_object
||
{}),
"
query_list
"
,
"
key
"
,
field_list
[
i
])
)
{
query_object
||
{},
"
query_list
"
,
"
key
"
,
field_list
[
i
]
))
{
wrap
+=
field_list
[
i
]
+
'
: "
'
+
obj
.
wildcard_character
+
value
+
...
...
@@ -4575,7 +4334,7 @@
}
}
// TODO: verfiy this is valid!
data
[
"
_id
"
]
=
record
.
id
;
data
.
_id
=
record
.
id
;
answer
.
data
.
rows
.
push
(
pushit
(
data
,
record
));
}
}
...
...
@@ -4589,7 +4348,7 @@
* @return {object} form fields/errors
**/
storage
.
validate
=
function
(
form_to_test
)
{
var
i
,
pass
,
form_to_submit
,
anti_spam
,
valid
,
test_time
,
test_empty
,
var
i
,
pass
,
anti_spam
,
valid
,
test_time
,
test_empty
,
test_full
,
form_element
,
form_elements
;
pass
=
false
;
...
...
@@ -4665,8 +4424,8 @@
if
(
store
&&
items
.
length
>
0
)
{
for
(
i
=
0
;
i
<
items
.
length
;
i
+=
1
)
{
store
.
remove
({
"
_id
"
:
items
[
i
]})
.
then
(
function
()
{
store
.
remove
({
"
_id
"
:
items
[
i
]})
.
then
(
function
()
{
if
(
config
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
config
.
state
.
callback
);
}
...
...
@@ -4718,16 +4477,16 @@
* @param {Object} response The action response
*/
app
.
navigate
=
function
(
obj
,
response
)
{
var
answer
,
id
,
goto
,
decode
;
var
answer
,
id
,
goto
_page
,
decode
;
if
(
obj
.
state
.
callback
)
{
app
.
util
.
loader
(
""
,
"
status_dict.forwarding
"
);
answer
=
util
.
parse
(
response
);
id
=
answer
.
id
;
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
goto
=
decode
?
id
:
window
.
encodeURIComponent
(
id
);
goto
_page
=
decode
?
id
:
window
.
encodeURIComponent
(
id
);
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
goto
));
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
goto
_page
));
}
};
...
...
@@ -5033,7 +4792,8 @@
info_field_list
=
element
.
querySelectorAll
(
"
.info
"
);
info
=
""
;
no_total
=
total
===
undefined
&&
app
.
storage_dict
.
property_dict
.
skip_total_records
;
no_total
=
total
===
undefined
&&
app
.
storage_dict
.
property_dict
.
skip_total_records
;
generateInfo
=
function
(
text
,
text_i18n
)
{
return
factory
.
element
(
"
span
"
,
...
...
@@ -5075,7 +4835,8 @@
no_items
=
options
.
limit
[
1
]
||
0
;
zero_no_show
=
(
no_limit
===
0
&&
use_total
!==
0
)
?
1
:
no_limit
;
if
(
no_total
)
{
min
=
((
no_limit
+
no_items
===
0
)
?
use_total
:
no_limit
+
no_items
);
min
=
((
no_limit
+
no_items
===
0
)
?
use_total
:
no_limit
+
no_items
);
total_records
=
""
;
}
else
{
min
=
Math
.
min
(
...
...
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