Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
erp5
Commits
5e2ef471
Commit
5e2ef471
authored
Jul 05, 2016
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_web_renderjs_ui] RelationField: drop JQM dependency
parent
78ec4fb8
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
701 additions
and
118 deletions
+701
-118
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multirelationstringfield_js.js
...age_module/rjs_gadget_erp5_multirelationstringfield_js.js
+372
-100
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multirelationstringfield_js.xml
...ge_module/rjs_gadget_erp5_multirelationstringfield_js.xml
+2
-2
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_relationstringfield_js.js
...web_page_module/rjs_gadget_erp5_relationstringfield_js.js
+325
-14
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_relationstringfield_js.xml
...eb_page_module/rjs_gadget_erp5_relationstringfield_js.xml
+2
-2
No files found.
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multirelationstringfield_js.js
View file @
5e2ef471
/*jslint indent: 2, maxerr: 3, nomen: true */
/*global window, rJS, RSVP, document */
(
function
(
window
,
rJS
,
RSVP
,
document
)
{
/*global window, rJS, RSVP, URI, loopEventListener, Handlebars, Event, document,
SimpleQuery, ComplexQuery, Query, QueryFactory, promiseEventListener*/
(
function
(
window
,
rJS
,
RSVP
,
URI
,
loopEventListener
,
promiseEventListener
,
document
,
SimpleQuery
,
ComplexQuery
,
Query
,
QueryFactory
,
Handlebars
,
Event
)
{
"
use strict
"
;
var
gadget_klass
=
rJS
(
window
),
single_input_source
=
gadget_klass
.
__template_element
.
getElementById
(
"
single-input-template
"
)
.
innerHTML
,
single_input_template
=
Handlebars
.
compile
(
single_input_source
),
relation_listview_source
=
gadget_klass
.
__template_element
.
getElementById
(
"
relation-listview-template
"
)
.
innerHTML
,
relation_listview_template
=
Handlebars
.
compile
(
relation_listview_source
),
multi_input_source
=
gadget_klass
.
__template_element
.
getElementById
(
"
multi-input-template
"
)
.
innerHTML
,
multi_input_template
=
Handlebars
.
compile
(
multi_input_source
),
create_source
=
gadget_klass
.
__template_element
.
getElementById
(
"
create-template
"
)
.
innerHTML
,
create_template
=
Handlebars
.
compile
(
create_source
),
searching
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-input-clear ui-icon-spinner ui-icon-spin
"
,
searched
=
"
ui-hidden-accessible
"
,
jump_on
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-icon-plane ui-shadow-inset ui-btn-inline
"
,
jump_off
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-icon-plane ui-shadow-inset ui-btn-inline ui-disabled
"
,
jump_add
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-icon-plus ui-shadow-inset ui-btn-inline ui-disabled
"
,
jump_unknown
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-icon-warning ui-shadow-inset ui-btn-inline ui-disabled
"
;
function
listenToInput
(
gadget
,
index
)
{
var
props
=
gadget
.
props
,
div
=
gadget
.
props
.
element
.
querySelectorAll
(
'
.single_input
'
)[
index
],
input
=
div
.
querySelector
(
'
input
'
),
search_query
,
simple_query
,
plane
=
div
.
querySelector
(
'
.ui-btn
'
),
field_json
=
props
.
field_json
,
spinner
=
div
.
querySelector
(
'
.ui-hidden-accessible
'
),
create_div
=
div
.
querySelector
(
"
.ui-tag-list
"
),
ul
=
div
.
querySelector
(
"
.search_ul
"
);
function
generateList
(
event
)
{
var
catalog_index
=
field_json
.
catalog_index
,
begin_from
=
props
.
begin_from
||
0
,
lines
=
field_json
.
lines
||
10
,
my_value
=
event
.
target
.
value
;
ul
.
innerHTML
=
""
;
create_div
.
innerHTML
=
""
;
plane
.
className
=
jump_off
;
props
.
jump_url
[
index
]
=
""
;
if
(
my_value
===
""
)
{
spinner
.
className
=
searched
;
return
;
}
simple_query
=
new
SimpleQuery
({
key
:
catalog_index
,
value
:
my_value
});
spinner
.
className
=
searching
;
search_query
=
Query
.
objectToSearchText
(
new
ComplexQuery
({
operator
:
"
AND
"
,
query_list
:
[
gadget
.
props
.
query
,
simple_query
]
}));
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
jio_allDocs
({
"
query
"
:
search_query
,
"
limit
"
:
[
begin_from
,
begin_from
+
lines
],
"
select_list
"
:
[
catalog_index
]
});
})
.
push
(
function
(
result
)
{
var
list
=
[],
i
,
type
=
field_json
.
allow_creation
?
field_json
.
portal_types
:
[],
html
;
for
(
i
=
0
;
i
<
result
.
data
.
rows
.
length
;
i
+=
1
)
{
list
.
push
({
id
:
result
.
data
.
rows
[
i
].
id
,
value
:
result
.
data
.
rows
[
i
].
value
[
catalog_index
]
});
}
spinner
.
className
=
searched
;
html
=
relation_listview_template
({
list
:
list
,
type
:
type
,
value
:
my_value
});
ul
.
innerHTML
=
html
;
});
}
function
setSelectedElement
(
event
)
{
var
element
=
event
.
target
,
jump_url
=
element
.
getAttribute
(
"
data-relative-url
"
),
create_object_type
=
element
.
getAttribute
(
"
data-create-object
"
),
explore
=
element
.
getAttribute
(
"
data-explore
"
),
tmp
;
ul
.
innerHTML
=
""
;
if
(
index
===
gadget
.
props
.
last_index
-
1
&&
!
explore
)
{
props
.
jump_url
[
gadget
.
props
.
last_index
]
=
""
;
tmp
=
document
.
createElement
(
"
fieldset
"
);
tmp
.
innerHTML
=
single_input_template
();
gadget
.
props
.
container
.
appendChild
(
tmp
);
gadget
.
props
.
input_list
.
push
({
"
title
"
:
field_json
.
key
,
"
name
"
:
field_json
.
key
,
"
value
"
:
""
,
"
href
"
:
""
,
"
create_object
"
:
""
});
gadget
.
props
.
last_index
+=
1
;
gadget
.
props
.
element
.
dispatchEvent
(
new
Event
(
'
add_relation_input
'
));
}
if
(
jump_url
)
{
props
.
jump_url
[
index
]
=
jump_url
;
input
.
value
=
element
.
textContent
;
return
gadget
.
getUrlFor
({
command
:
'
index
'
,
options
:
{
jio_key
:
jump_url
}
}).
push
(
function
(
url
)
{
if
(
field_json
.
allow_jump
)
{
plane
.
href
=
url
;
plane
.
className
=
jump_on
;
}
});
}
if
(
create_object_type
)
{
input
.
setAttribute
(
"
data-create-object
"
,
create_object_type
);
plane
.
className
=
jump_add
;
create_div
.
innerHTML
=
create_template
({
'
text
'
:
create_object_type
});
return
;
}
if
(
explore
)
{
return
gadget
.
getFormContent
({
format
:
"
json
"
})
.
push
(
function
(
content
)
{
return
gadget
.
redirect
({
command
:
'
index
'
,
options
:
{
page
:
"
relation_search
"
,
url
:
gadget
.
props
.
field_json
.
url
,
extended_search
:
Query
.
objectToSearchText
(
simple_query
),
view
:
gadget
.
props
.
field_json
.
view
,
back_field
:
gadget
.
props
.
field_json
.
key
,
target_index
:
index
},
form_content
:
content
});
});
}
plane
.
className
=
jump_unknown
;
}
return
RSVP
.
all
([
loopEventListener
(
input
,
'
input
'
,
false
,
generateList
),
loopEventListener
(
input
,
'
blur
'
,
false
,
function
()
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
any
([
RSVP
.
delay
(
200
),
promiseEventListener
(
ul
,
"
click
"
,
true
)
]);
})
.
push
(
function
(
event
)
{
var
tmp
;
if
(
event
)
{
return
setSelectedElement
(
event
);
}
if
(
ul
.
innerHTML
)
{
ul
.
innerHTML
=
""
;
plane
.
className
=
jump_unknown
;
if
(
index
===
gadget
.
props
.
last_index
-
1
)
{
props
.
jump_url
[
gadget
.
props
.
last_index
]
=
""
;
tmp
=
document
.
createElement
(
"
fieldset
"
);
tmp
.
innerHTML
=
single_input_template
();
gadget
.
props
.
container
.
appendChild
(
tmp
);
gadget
.
props
.
input_list
.
push
({
"
title
"
:
field_json
.
key
,
"
name
"
:
field_json
.
key
,
"
value
"
:
""
,
"
href
"
:
""
,
"
create_object
"
:
""
});
gadget
.
props
.
last_index
+=
1
;
gadget
.
props
.
element
.
dispatchEvent
(
new
Event
(
'
add_relation_input
'
));
}
}
});
})]
);
}
rJS
(
window
)
/////////////////////////////////////////////////////////////////
...
...
@@ -16,35 +225,17 @@
gadget
.
props
.
element
=
element
;
});
})
.
allowPublicAcquisition
(
"
addRelationInput
"
,
function
()
{
var
fieldset
=
document
.
createElement
(
"
fieldset
"
),
gadget
=
this
,
container
=
gadget
.
props
.
element
.
querySelector
(
'
.container
'
);
return
gadget
.
declareGadget
(
'
gadget_erp5_relation_input.html
'
,
{
element
:
fieldset
})
.
push
(
function
(
relation_input
)
{
var
field_json
=
gadget
.
props
.
field_json
,
index
;
if
(
field_json
.
default
.
value
)
{
index
=
field_json
.
default
.
relation_item_relative_url
.
length
;
field_json
.
default
.
relation_item_relative_url
.
push
(
''
);
field_json
.
default
.
value
.
push
(
''
);
}
else
{
index
=
field_json
.
relation_item_relative_url
.
length
;
field_json
.
relation_item_relative_url
.
push
(
''
);
field_json
.
default
.
push
(
''
);
}
gadget
.
props
.
gadget_list
.
push
(
relation_input
);
return
relation_input
.
render
({
field_json
:
gadget
.
props
.
field_json
},
{
index
:
index
,
addRelationInput
:
true
});
})
.
push
(
function
()
{
container
.
appendChild
(
fieldset
);
});
})
/////////////////////////////////////////////////////////////////
// acquired methods
/////////////////////////////////////////////////////////////////
.
declareAcquiredMethod
(
"
notifyInvalid
"
,
"
notifyInvalid
"
)
.
declareAcquiredMethod
(
"
notifyChange
"
,
"
notifyChange
"
)
.
declareAcquiredMethod
(
"
jio_allDocs
"
,
"
jio_allDocs
"
)
.
declareAcquiredMethod
(
"
translateHtml
"
,
"
translateHtml
"
)
.
declareAcquiredMethod
(
"
getUrlFor
"
,
"
getUrlFor
"
)
.
declareAcquiredMethod
(
"
redirect
"
,
"
redirect
"
)
.
declareAcquiredMethod
(
"
getFormContent
"
,
"
getFormContent
"
)
/////////////////////////////////////////////////////////////////
// declared methods
...
...
@@ -52,91 +243,172 @@
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
gadget
=
this
,
i
,
list
=
[],
fieldset
,
container
=
gadget
.
props
.
element
.
querySelector
(
'
.container
'
),
field_json
=
options
.
field_json
||
{},
relation_item_relative_url
;
gadget
.
props
.
field_json
=
field_json
;
if
(
field_json
.
default
.
value
)
{
if
(
field_json
.
default
.
relation_item_relative_url
[
field_json
.
default
.
relation_item_relative_url
.
length
-
1
])
{
//return form listbox
field_json
.
default
.
value
.
push
(
""
);
field_json
.
default
.
relation_item_relative_url
.
push
(
""
);
}
target_url_list
=
[],
list
=
[],
input
=
[],
create_object
,
unknown
,
uid
,
relation_item_relative_url
,
value_list
;
if
(
field_json
.
default
.
format
===
"
json
"
)
{
create_object
=
field_json
.
default
.
create_object
||
[];
unknown
=
field_json
.
default
.
jump_unknown
||
[];
uid
=
field_json
.
default
.
uid
;
relation_item_relative_url
=
field_json
.
default
.
relation_item_relative_url
;
value_list
=
field_json
.
default
.
value
||
[];
}
else
{
field_json
.
relation_item_relative_url
.
push
(
''
);
field_json
.
default
.
push
(
''
);
create_object
=
field_json
.
create_object
||
[];
unknown
=
field_json
.
jump_unknown
||
[];
uid
=
field_json
.
uid
;
relation_item_relative_url
=
field_json
.
relation_item_relative_url
;
value_list
=
field_json
.
default
||
[];
}
for
(
i
=
0
;
i
<
relation_item_relative_url
.
length
;
i
+=
1
)
{
fieldset
=
document
.
createElement
(
"
fieldset
"
);
container
.
appendChild
(
fieldset
);
list
.
push
(
gadget
.
declareGadget
(
'
gadget_erp5_relation_input.html
'
,
{
element
:
fieldset
}));
if
(
relation_item_relative_url
)
{
target_url_list
=
relation_item_relative_url
;
}
gadget
.
props
.
field_json
=
field_json
;
gadget
.
props
.
jump_url
=
[];
gadget
.
props
.
query
=
QueryFactory
.
create
(
new
URI
(
field_json
.
query
).
query
(
true
).
query
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
(
list
);
for
(
i
=
0
;
i
<
value_list
.
length
;
i
+=
1
)
{
if
(
!
value_list
[
i
])
{
if
(
uid
)
{
return
gadget
.
jio_allDocs
({
query
:
Query
.
objectToSearchText
(
new
SimpleQuery
({
key
:
"
catalog.uid
"
,
value
:
uid
})),
limit
:
[
0
,
1
],
select_list
:
[
field_json
.
catalog_index
]
});
}
}
}
})
.
push
(
function
(
gadget_list
)
{
.
push
(
function
(
result
)
{
var
non_empty_input
=
true
;
list
=
[];
gadget
.
props
.
gadget_list
=
gadget_list
;
for
(
i
=
0
;
i
<
gadget_list
.
length
;
i
+=
1
)
{
list
.
push
(
gadget_list
[
i
].
render
(
options
,
{
index
:
i
,
addRelationInput
:
(
i
===
gadget_list
.
length
-
1
)
if
(
result
)
{
value_list
[
i
]
=
result
.
data
.
rows
[
0
].
value
[
field_json
.
catalog_index
];
}
for
(
i
=
0
;
i
<
target_url_list
.
length
;
i
+=
1
)
{
if
(
target_url_list
[
i
])
{
gadget
.
props
.
jump_url
.
push
(
target_url_list
[
i
]);
list
.
push
(
gadget
.
getUrlFor
({
command
:
'
index
'
,
options
:
{
jio_key
:
target_url_list
[
i
]
}
}));
}
else
{
if
(
!
create_object
[
i
])
{
//non jump url nor create onject
non_empty_input
=
false
;
}
gadget
.
props
.
jump_url
.
push
(
""
);
list
.
push
(
""
);
}
}
if
(
non_empty_input
)
{
value_list
.
push
(
""
);
list
.
push
(
""
);
gadget
.
props
.
jump_url
.
push
(
""
);
}
return
RSVP
.
all
(
list
);
})
.
push
(
function
(
href_list
)
{
for
(
i
=
0
;
i
<
value_list
.
length
;
i
+=
1
)
{
input
.
push
({
"
create_object
"
:
create_object
[
i
],
"
title
"
:
field_json
.
key
,
"
name
"
:
field_json
.
key
,
"
value
"
:
value_list
[
i
],
"
href
"
:
href_list
[
i
],
"
jump_unknown
"
:
unknown
[
i
],
"
error_text
"
:
field_json
.
error_text
});
}
gadget
.
props
.
input_list
=
input
;
gadget
.
props
.
default_index
=
input
.
length
;
gadget
.
props
.
last_index
=
input
.
length
;
return
gadget
.
translateHtml
(
multi_input_template
({
input
:
input
,
allow_jump
:
field_json
.
allow_jump
,
readonly
:
field_json
.
editable
?
""
:
"
ui-state-readonly
"
}));
})
.
push
(
function
(
html
)
{
gadget
.
props
.
element
.
innerHTML
=
html
;
gadget
.
props
.
container
=
gadget
.
props
.
element
.
querySelector
(
"
.container
"
);
});
})
.
declareMethod
(
'
getContent
'
,
function
(
options
)
{
var
list
=
[],
var
list
=
this
.
props
.
element
.
querySelectorAll
(
'
.single_input
'
),
result
=
{},
i
,
gadget
=
this
,
length
=
gadget
.
props
.
gadget_list
.
length
;
if
(
options
.
format
===
'
erp5
'
)
{
length
-=
1
;
}
for
(
i
=
0
;
i
<
length
;
i
+=
1
)
{
list
.
push
(
gadget
.
props
.
gadget_list
[
i
].
getContent
(
options
,
{
"
type
"
:
"
MultiRelationField
"
}));
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
(
list
);
})
.
push
(
function
(
result
)
{
var
tmp
=
{},
key
,
key1
;
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
)
{
for
(
key
in
result
[
i
])
{
if
(
result
[
i
].
hasOwnProperty
(
key
))
{
if
(
options
.
format
===
'
erp5
'
)
{
if
(
tmp
[
key
]
===
undefined
)
{
tmp
[
key
]
=
[];
}
tmp
[
key
].
push
(
result
[
i
][
key
]);
}
else
{
if
(
tmp
[
key
]
===
undefined
)
{
tmp
[
key
]
=
{};
input
,
value_list
=
[],
plane
,
tmp
=
{},
field_json
=
this
.
props
.
field_json
;
if
(
options
.
format
===
"
erp5
"
)
{
for
(
i
=
0
;
i
<
list
.
length
-
1
;
i
+=
1
)
{
plane
=
list
[
i
].
querySelector
(
'
.ui-btn
'
);
input
=
list
[
i
].
querySelector
(
'
input
'
);
if
(
plane
.
className
===
jump_add
)
{
result
[
field_json
.
relation_field_id
+
"
_
"
+
i
]
=
"
_newContent_
"
+
input
.
getAttribute
(
"
data-create-object
"
);
}
for
(
key1
in
result
[
i
][
key
])
{
if
(
result
[
i
][
key
].
hasOwnProperty
(
key1
))
{
if
(
tmp
[
key
][
key1
]
===
undefined
)
{
tmp
[
key
][
key1
]
=
[];
value_list
.
push
(
input
.
value
);
}
tmp
[
key
][
key1
].
push
(
result
[
i
][
key
][
key1
][
0
]);
result
[
field_json
.
key
]
=
value_list
;
return
result
;
}
tmp
.
format
=
"
json
"
;
tmp
.
value
=
[];
tmp
.
create_object
=
[];
tmp
.
jump_unknown
=
[];
for
(
i
=
0
;
i
<
list
.
length
;
i
+=
1
)
{
plane
=
list
[
i
].
querySelector
(
'
.ui-btn
'
);
input
=
list
[
i
].
querySelector
(
'
input
'
);
tmp
.
value
[
i
]
=
input
.
value
;
tmp
.
jump_unknown
[
i
]
=
""
;
tmp
.
create_object
[
i
]
=
""
;
if
(
plane
.
className
===
jump_add
)
{
tmp
.
create_object
[
i
]
=
input
.
getAttribute
(
"
data-create-object
"
);
}
else
{
if
(
plane
.
className
===
jump_unknown
)
{
tmp
.
jump_unknown
[
i
]
=
true
;
}
}
}
tmp
.
relation_item_relative_url
=
this
.
props
.
jump_url
;
result
[
field_json
.
key
]
=
tmp
;
return
result
;
})
.
declareService
(
function
()
{
var
i
,
gadget
=
this
,
list
=
[];
for
(
i
=
0
;
i
<
gadget
.
props
.
last_index
;
i
+=
1
)
{
list
.
push
(
listenToInput
(
gadget
,
i
));
}
return
RSVP
.
all
(
list
);
})
.
declareService
(
function
()
{
var
gadget
=
this
;
return
loopEventListener
(
gadget
.
props
.
element
,
'
add_relation_input
'
,
false
,
function
()
{
var
list
=
[],
i
;
for
(
i
=
gadget
.
props
.
default_index
;
i
<
gadget
.
props
.
last_index
;
i
+=
1
)
{
list
.
push
(
listenToInput
(
gadget
,
i
));
}
return
tmp
;
return
RSVP
.
all
(
list
)
;
});
});
}(
window
,
rJS
,
RSVP
,
document
));
\ No newline at end of file
}(
window
,
rJS
,
RSVP
,
URI
,
loopEventListener
,
promiseEventListener
,
document
,
SimpleQuery
,
ComplexQuery
,
Query
,
QueryFactory
,
Handlebars
,
Event
));
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multirelationstringfield_js.xml
View file @
5e2ef471
...
...
@@ -230,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
952.
33012.29157.25361
</string>
</value>
<value>
<string>
952.
22772.44488.1757
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
146
8331865.64
</float>
<float>
146
7710697.76
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_relationstringfield_js.js
View file @
5e2ef471
/*jslint indent: 2, maxerr: 3, nomen: true */
/*global window, rJS */
(
function
(
window
,
rJS
)
{
/*global window, rJS, RSVP, URI, loopEventListener, Handlebars,
SimpleQuery, ComplexQuery, Query, QueryFactory, promiseEventListener*/
(
function
(
window
,
rJS
,
RSVP
,
URI
,
loopEventListener
,
promiseEventListener
,
SimpleQuery
,
ComplexQuery
,
Query
,
QueryFactory
,
Handlebars
)
{
"
use strict
"
;
var
gadget_klass
=
rJS
(
window
),
relation_input_source
=
gadget_klass
.
__template_element
.
getElementById
(
"
relation-input-template
"
)
.
innerHTML
,
relation_input_template
=
Handlebars
.
compile
(
relation_input_source
),
relation_listview_source
=
gadget_klass
.
__template_element
.
getElementById
(
"
relation-listview-template
"
)
.
innerHTML
,
relation_listview_template
=
Handlebars
.
compile
(
relation_listview_source
),
create_source
=
gadget_klass
.
__template_element
.
getElementById
(
"
create-template
"
)
.
innerHTML
,
create_template
=
Handlebars
.
compile
(
create_source
),
searching
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-input-clear ui-icon-spinner ui-icon-spin
"
,
searched
=
"
ui-hidden-accessible
"
,
jump_on
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-icon-plane ui-shadow-inset ui-btn-inline
"
,
jump_off
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-icon-plane ui-shadow-inset ui-btn-inline ui-disabled
"
,
jump_add
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-icon-plus ui-shadow-inset ui-btn-inline ui-disabled
"
,
jump_unknown
=
"
ui-btn ui-corner-all ui-btn-icon-notext
"
+
"
ui-icon-warning ui-shadow-inset ui-btn-inline ui-disabled
"
;
rJS
(
window
)
/////////////////////////////////////////////////////////////////
...
...
@@ -15,25 +46,305 @@
return
my_gadget
.
getElement
()
.
push
(
function
(
element
)
{
my_gadget
.
props
.
element
=
element
;
return
my_gadget
.
getDeclaredGadget
(
"
relation_input
"
);
})
.
push
(
function
(
relation_input_gadget
)
{
my_gadget
.
props
.
relation_input_gadget
=
relation_input_gadget
;
});
})
.
allowPublicAcquisition
(
"
addRelationInput
"
,
function
()
{
return
;
})
/////////////////////////////////////////////////////////////////
// acquired methods
/////////////////////////////////////////////////////////////////
.
declareAcquiredMethod
(
"
notifyInvalid
"
,
"
notifyInvalid
"
)
.
declareAcquiredMethod
(
"
notifyChange
"
,
"
notifyChange
"
)
.
declareAcquiredMethod
(
"
jio_allDocs
"
,
"
jio_allDocs
"
)
.
declareAcquiredMethod
(
"
getUrlFor
"
,
"
getUrlFor
"
)
.
declareAcquiredMethod
(
"
redirect
"
,
"
redirect
"
)
.
declareAcquiredMethod
(
"
getFormContent
"
,
"
getFormContent
"
)
.
declareAcquiredMethod
(
"
translateHtml
"
,
"
translateHtml
"
)
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.
declareMethod
(
'
render
'
,
function
(
options
)
{
return
this
.
props
.
relation_input_gadget
.
render
(
options
,
{
index
:
0
var
gadget
=
this
,
field_json
=
options
.
field_json
||
{},
target_url
,
queue
=
new
RSVP
.
Queue
(),
create_object
,
unknown
,
relation_item_relative_url
,
uid
,
value
=
""
;
if
(
field_json
.
default
.
format
===
"
json
"
)
{
//load non saved value
create_object
=
field_json
.
default
.
create_object
;
unknown
=
field_json
.
default
.
jump_unknown
;
relation_item_relative_url
=
field_json
.
default
.
relation_item_relative_url
;
uid
=
field_json
.
default
.
uid
;
value
=
field_json
.
default
.
value
[
0
]
||
""
;
}
else
{
create_object
=
field_json
.
create_object
;
unknown
=
field_json
.
jump_unknown
;
relation_item_relative_url
=
field_json
.
relation_item_relative_url
;
uid
=
field_json
.
uid
;
value
=
field_json
.
default
[
0
]
||
""
;
}
gadget
.
props
.
jump_url
=
relation_item_relative_url
;
if
(
relation_item_relative_url
)
{
target_url
=
relation_item_relative_url
[
0
];
}
gadget
.
props
.
field_json
=
field_json
;
gadget
.
props
.
query
=
QueryFactory
.
create
(
new
URI
(
field_json
.
query
).
query
(
true
).
query
);
if
(
!
value
&&
target_url
&&
uid
)
{
//return from listbox
queue
.
push
(
function
()
{
return
gadget
.
jio_allDocs
({
"
query
"
:
Query
.
objectToSearchText
(
new
SimpleQuery
({
key
:
"
catalog.uid
"
,
value
:
uid
,
limit
:
[
0
,
1
]
})),
"
select_list
"
:
[
field_json
.
catalog_index
]
});
})
.
push
(
function
(
result
)
{
value
=
result
.
data
.
rows
[
0
].
value
[
field_json
.
catalog_index
];
});
}
if
(
target_url
)
{
queue
.
push
(
function
()
{
return
gadget
.
getUrlFor
({
command
:
'
index
'
,
options
:
{
jio_key
:
target_url
}
});
});
}
queue
.
push
(
function
(
href
)
{
return
gadget
.
translateHtml
(
relation_input_template
({
href
:
href
,
readonly
:
field_json
.
editable
?
""
:
"
ui-state-readonly
"
,
required
:
field_json
.
required
?
"
required
"
:
""
,
value
:
value
,
title
:
field_json
.
title
,
name
:
field_json
.
key
,
create_object
:
create_object
,
allow_jump
:
field_json
.
allow_jump
?
true
:
undefined
,
error_text
:
field_json
.
error_text
,
jump_unknown
:
unknown
}));
})
.
push
(
function
(
html
)
{
gadget
.
props
.
element
.
innerHTML
=
html
;
gadget
.
props
.
input
=
gadget
.
props
.
element
.
querySelector
(
"
input
"
);
gadget
.
props
.
new_tag_div
=
gadget
.
props
.
element
.
querySelector
(
"
.new_tag
"
);
gadget
.
props
.
spinner
=
gadget
.
props
.
element
.
querySelector
(
"
a
"
);
gadget
.
props
.
plane
=
gadget
.
props
.
element
.
querySelectorAll
(
"
a
"
)[
1
];
});
return
queue
;
})
.
declareMethod
(
'
getContent
'
,
function
(
options
)
{
return
this
.
props
.
relation_input_gadget
.
getContent
(
options
);
var
element
=
this
.
props
.
element
.
querySelector
(
'
input
'
),
result
=
{},
tmp
=
{},
field_json
=
this
.
props
.
field_json
;
if
(
options
.
format
===
"
erp5
"
)
{
if
(
this
.
props
.
plane
.
className
===
jump_add
)
{
result
[
field_json
.
relation_field_id
]
=
"
_newContent_
"
+
this
.
props
.
create_object_type
;
}
result
[
element
.
getAttribute
(
'
name
'
)]
=
element
.
value
;
return
result
;
}
tmp
.
format
=
"
json
"
;
tmp
.
value
=
[
element
.
value
];
if
(
this
.
props
.
plane
.
className
===
jump_add
)
{
tmp
.
create_object
=
this
.
props
.
create_object_type
;
}
else
{
if
(
this
.
props
.
plane
.
className
===
jump_unknown
)
{
tmp
.
jump_unknown
=
true
;
}
else
{
tmp
.
relation_item_relative_url
=
this
.
props
.
jump_url
;
}
}
result
[
element
.
getAttribute
(
'
name
'
)]
=
tmp
;
return
result
;
})
/////////////////////////////////////////////////////////////////
// declared services
/////////////////////////////////////////////////////////////////
.
declareService
(
function
()
{
var
gadget
=
this
,
props
=
gadget
.
props
,
input
=
gadget
.
props
.
element
.
querySelector
(
'
input
'
),
search_query
,
simple_query
,
field_json
=
props
.
field_json
,
create_div
=
props
.
element
.
querySelector
(
"
.ui-tag-list
"
),
ul
=
gadget
.
props
.
element
.
querySelector
(
"
.search_ul
"
);
function
generateList
(
event
)
{
var
index
=
field_json
.
catalog_index
,
begin_from
=
props
.
begin_from
||
0
,
lines
=
field_json
.
lines
||
10
,
my_value
=
event
.
target
.
value
;
ul
.
innerHTML
=
""
;
create_div
.
innerHTML
=
""
;
props
.
plane
.
className
=
jump_off
;
props
.
jump_url
=
[];
if
(
my_value
===
""
)
{
props
.
spinner
.
className
=
searched
;
return
;
}
simple_query
=
new
SimpleQuery
({
key
:
index
,
value
:
my_value
});
props
.
spinner
.
className
=
searching
;
search_query
=
Query
.
objectToSearchText
(
new
ComplexQuery
({
operator
:
"
AND
"
,
query_list
:
[
gadget
.
props
.
query
,
simple_query
]
}));
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
jio_allDocs
({
"
query
"
:
search_query
,
"
limit
"
:
[
begin_from
,
begin_from
+
lines
],
"
select_list
"
:
[
index
]
});
})
.
push
(
function
(
result
)
{
var
list
=
[],
i
,
type
=
field_json
.
allow_creation
?
field_json
.
portal_types
:
[],
html
;
for
(
i
=
0
;
i
<
result
.
data
.
rows
.
length
;
i
+=
1
)
{
list
.
push
({
id
:
result
.
data
.
rows
[
i
].
id
,
value
:
result
.
data
.
rows
[
i
].
value
[
index
]
});
}
props
.
spinner
.
className
=
searched
;
html
=
relation_listview_template
({
list
:
list
,
type
:
type
,
value
:
my_value
});
ul
.
innerHTML
=
html
;
});
}
function
setSelectedElement
(
event
)
{
var
element
=
event
.
target
,
jump_url
=
element
.
getAttribute
(
"
data-relative-url
"
),
create_object_type
=
element
.
getAttribute
(
"
data-create-object
"
),
explore
=
element
.
getAttribute
(
"
data-explore
"
);
ul
.
innerHTML
=
""
;
if
(
jump_url
)
{
props
.
input
.
value
=
element
.
textContent
;
props
.
jump_url
=
[
jump_url
];
return
gadget
.
getUrlFor
({
command
:
'
index
'
,
options
:
{
jio_key
:
jump_url
}
}).
push
(
function
(
url
)
{
if
(
field_json
.
allow_jump
)
{
props
.
plane
.
href
=
url
;
props
.
plane
.
className
=
jump_on
;
}
});
}
if
(
create_object_type
)
{
gadget
.
props
.
create_object_type
=
create_object_type
;
props
.
plane
.
className
=
jump_add
;
create_div
.
innerHTML
=
create_template
({
'
text
'
:
create_object_type
});
return
;
}
if
(
explore
)
{
return
gadget
.
getFormContent
({
format
:
"
json
"
})
.
push
(
function
(
content
)
{
return
gadget
.
redirect
({
command
:
'
index
'
,
options
:
{
page
:
"
relation_search
"
,
url
:
gadget
.
props
.
field_json
.
url
,
extended_search
:
Query
.
objectToSearchText
(
simple_query
),
view
:
gadget
.
props
.
field_json
.
view
,
back_field
:
gadget
.
props
.
field_json
.
key
,
target_index
:
0
},
form_content
:
content
});
});
}
props
.
plane
.
className
=
jump_unknown
;
}
return
RSVP
.
all
([
loopEventListener
(
input
,
'
input
'
,
false
,
generateList
),
loopEventListener
(
input
,
'
blur
'
,
false
,
function
()
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
any
([
RSVP
.
delay
(
200
),
promiseEventListener
(
ul
,
"
click
"
,
true
)
]);
})
.
push
(
function
(
event
)
{
if
(
event
)
{
return
setSelectedElement
(
event
);
}
if
(
ul
.
innerHTML
)
{
ul
.
innerHTML
=
""
;
props
.
plane
.
className
=
jump_unknown
;
}
});
})]
);
})
.
declareService
(
function
()
{
var
gadget
=
this
;
function
notifyInvalid
(
evt
)
{
return
gadget
.
notifyInvalid
(
evt
.
target
.
validationMessage
);
}
// Listen to input change
return
loopEventListener
(
gadget
.
props
.
element
.
querySelector
(
'
input
'
),
'
invalid
'
,
false
,
notifyInvalid
);
})
.
declareService
(
function
()
{
////////////////////////////////////
// Check field validity when the value changes
////////////////////////////////////
var
gadget
=
this
;
function
notifyChange
()
{
return
gadget
.
notifyChange
();
}
return
loopEventListener
(
gadget
.
props
.
element
.
querySelector
(
'
input
'
),
'
change
'
,
false
,
notifyChange
);
});
}(
window
,
rJS
));
\ No newline at end of file
}(
window
,
rJS
,
RSVP
,
URI
,
loopEventListener
,
promiseEventListener
,
SimpleQuery
,
ComplexQuery
,
Query
,
QueryFactory
,
Handlebars
));
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_relationstringfield_js.xml
View file @
5e2ef471
...
...
@@ -230,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
952.
33013.17443.54510
</string>
</value>
<value>
<string>
952.
22746.50500.24354
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
146
8331859.64
</float>
<float>
146
7710574.65
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
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