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
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
d5cc854b
Commit
d5cc854b
authored
Sep 27, 2019
by
Roque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_officejs: refactor in form view
parent
86d8cb0b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
127 deletions
+131
-127
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_form_view_js.js
...plateItem/web_page_module/gadget_officejs_form_view_js.js
+129
-125
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_form_view_js.xml
...lateItem/web_page_module/gadget_officejs_form_view_js.xml
+2
-2
No files found.
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_form_view_js.js
View file @
d5cc854b
...
@@ -85,6 +85,120 @@
...
@@ -85,6 +85,120 @@
return
form_json
;
return
form_json
;
}
}
//TODO this should be in a custom view
//use: portal_type_dict.custom_view_gadget (handled by controller gadget)
function
renderOnlyOffice
(
gadget
,
options
,
portal_type_dict
,
state_dict
)
{
//TODO doc should come with filename. for now hardcoded if undefined
//get format extension from portal_type_dict
if
(
!
options
.
doc
.
filename
)
{
options
.
doc
.
filename
=
"
default.docx
"
;
}
state_dict
.
mime_type
=
portal_type_dict
.
file_extension
;
state_dict
.
only_office
=
true
;
if
(
options
.
doc
.
action
)
{
return
gadget
.
changeState
(
state_dict
);
}
state_dict
.
content_editable
=
options
.
doc
.
content_type
===
undefined
||
options
.
doc
.
content_type
.
indexOf
(
"
application/x-asc
"
)
===
0
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
!
state_dict
.
content_editable
)
{
return
gadget
.
jio_getAttachment
(
options
.
jio_key
,
"
data
"
);
}
return
gadget
.
declareGadget
(
"
gadget_ojs_cloudooo.html
"
)
.
push
(
function
(
ojs_cloudooo
)
{
return
ojs_cloudooo
.
getConvertedBlob
({
jio_key
:
options
.
jio_key
,
format
:
state_dict
.
mime_type
,
filename
:
options
.
doc
.
filename
});
});
})
.
push
(
undefined
,
function
(
error
)
{
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
404
)
{
return
new
Blob
();
}
throw
error
;
})
.
push
(
function
(
blob
)
{
if
(
state_dict
.
content_editable
)
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
}
return
jIO
.
util
.
readBlobAsText
(
blob
);
})
.
push
(
function
(
result
)
{
state_dict
.
data
=
result
.
target
.
result
;
if
(
portal_type_dict
.
blob_type
)
{
state_dict
.
blob_type
=
portal_type_dict
.
blob_type
;
}
else
{
state_dict
.
blob_type
=
"
ooffice
"
;
}
return
gadget
.
changeState
(
state_dict
);
});
}
function
handleSubmit
(
gadget
,
child_gadget
,
content_dict
)
{
var
data
,
name_list
;
return
gadget
.
notifySubmitting
()
.
push
(
function
()
{
if
(
gadget
.
state
.
blob_type
)
{
//submit doc metadata
data
=
content_dict
.
text_content
;
delete
content_dict
.
text_content
;
//TODO this should be in a custom view
//use: portal_type_dict.custom_view_gadget
//ONLY OFFICE
if
(
gadget
.
state
.
only_office
)
{
name_list
=
gadget
.
state
.
doc
.
filename
.
split
(
'
.
'
);
if
(
name_list
.
pop
()
!==
gadget
.
state
.
mime_type
)
{
name_list
.
push
(
gadget
.
state
.
mime_type
);
content_dict
.
filename
=
name_list
.
join
(
'
.
'
);
}
content_dict
.
content_type
=
gadget
.
state
.
blob_type
;
}
//
}
return
child_gadget
.
submitContent
(
child_gadget
.
state
.
jio_key
,
undefined
,
content_dict
);
})
.
push
(
function
()
{
if
(
gadget
.
state
.
blob_type
)
{
//submit doc blob data
return
gadget
.
jio_putAttachment
(
child_gadget
.
state
.
jio_key
,
'
data
'
,
jIO
.
util
.
dataURItoBlob
(
data
))
//TODO this should be in a custom view
//use: portal_type_dict.custom_view_gadget
//ONLY OFFICE
.
push
(
function
()
{
if
(
gadget
.
state
.
only_office
)
{
return
gadget
.
declareGadget
(
"
gadget_ojs_cloudooo.html
"
);
}
})
.
push
(
function
(
cloudooo
)
{
if
(
gadget
.
state
.
only_office
)
{
return
cloudooo
.
putAllCloudoooConvertionOperation
({
format
:
gadget
.
state
.
mime_type
,
jio_key
:
child_gadget
.
state
.
jio_key
});
}
});
//
}
},
function
(
error
)
{
console
.
log
(
error
);
return
gadget
.
notifySubmitted
({
message
:
"
Submit failed
"
,
status
:
"
error
"
});
});
}
rJS
(
window
)
rJS
(
window
)
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// Acquired methods
// Acquired methods
...
@@ -139,82 +253,19 @@
...
@@ -139,82 +253,19 @@
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
.
declareMethod
(
"
triggerSubmit
"
,
function
(
argument_list
)
{
.
declareMethod
(
"
triggerSubmit
"
,
function
(
argument_list
)
{
var
gadget
=
this
,
data
,
name_list
;
var
gadget
=
this
,
child_gadget
,
content_dict
;
return
gadget
.
notifySubmitting
()
.
push
(
function
()
{
return
gadget
.
getDeclaredGadget
(
'
erp5_pt_gadget
'
)
return
gadget
.
getDeclaredGadget
(
'
erp5_pt_gadget
'
)
.
push
(
function
(
child_gadget
)
{
.
push
(
function
(
result
)
{
child_gadget
=
result
;
if
(
!
child_gadget
.
state
.
editable
)
{
if
(
!
child_gadget
.
state
.
editable
)
{
return
child_gadget
.
triggerSubmit
(
argument_list
);
return
child_gadget
.
triggerSubmit
(
argument_list
);
}
}
return
child_gadget
.
getDeclaredGadget
(
"
erp5_form
"
)
.
push
(
function
(
sub_gadget
)
{
return
sub_gadget
.
checkValidity
();
})
.
push
(
function
(
is_valid
)
{
if
(
!
is_valid
)
{
return
null
;
}
return
child_gadget
.
getContent
();
return
child_gadget
.
getContent
();
})
})
.
push
(
function
(
content_dict
)
{
.
push
(
function
(
result
)
{
if
(
content_dict
===
null
)
{
content_dict
=
result
;
return
;
if
(
!
content_dict
)
{
return
;
}
}
return
handleSubmit
(
gadget
,
child_gadget
,
content_dict
);
if
(
gadget
.
state
.
blob_type
)
{
data
=
content_dict
.
text_content
;
delete
content_dict
.
text_content
;
//ONLY OFFICE
if
(
gadget
.
state
.
only_office
)
{
name_list
=
gadget
.
state
.
doc
.
filename
.
split
(
'
.
'
);
if
(
name_list
.
pop
()
!==
gadget
.
state
.
mime_type
)
{
name_list
.
push
(
gadget
.
state
.
mime_type
);
content_dict
.
filename
=
name_list
.
join
(
'
.
'
);
}
content_dict
.
content_type
=
gadget
.
state
.
blob_type
;
}
//
}
return
child_gadget
.
submitContent
(
child_gadget
.
state
.
jio_key
,
undefined
,
content_dict
)
.
push
(
function
()
{
if
(
gadget
.
state
.
blob_type
)
{
return
gadget
.
jio_putAttachment
(
child_gadget
.
state
.
jio_key
,
'
data
'
,
jIO
.
util
.
dataURItoBlob
(
data
))
//ONLY OFFICE
.
push
(
function
()
{
if
(
gadget
.
state
.
only_office
)
{
return
gadget
.
declareGadget
(
"
gadget_ojs_cloudooo.html
"
);
}
})
.
push
(
function
(
cloudooo
)
{
if
(
gadget
.
state
.
only_office
)
{
return
cloudooo
.
putAllCloudoooConvertionOperation
({
format
:
gadget
.
state
.
mime_type
,
jio_key
:
child_gadget
.
state
.
jio_key
});
}
});
//
}
});
});
});
},
function
(
error
)
{
console
.
log
(
error
);
return
gadget
.
notifySubmitted
({
message
:
"
Submit failed
"
,
status
:
"
error
"
});
});
});
})
})
...
@@ -229,56 +280,9 @@
...
@@ -229,56 +280,9 @@
portal_type_dict
=
options
.
form_definition
.
portal_type_dict
,
portal_type_dict
=
options
.
form_definition
.
portal_type_dict
,
blob
;
blob
;
//ONLY OFFICE
if
(
portal_type_dict
.
only_office
&&
options
.
doc
)
{
if
(
portal_type_dict
.
only_office
&&
options
.
doc
)
{
//TODO doc should come with filename. for now hardcoded if undefined
return
renderOnlyOffice
(
gadget
,
options
,
portal_type_dict
,
state_dict
);
if
(
!
options
.
doc
.
filename
)
{
options
.
doc
.
filename
=
"
default.docx
"
;
}
state_dict
.
mime_type
=
portal_type_dict
.
file_extension
;
state_dict
.
only_office
=
true
;
if
(
options
.
doc
.
action
)
{
return
gadget
.
changeState
(
state_dict
);
}
state_dict
.
content_editable
=
options
.
doc
.
content_type
===
undefined
||
options
.
doc
.
content_type
.
indexOf
(
"
application/x-asc
"
)
===
0
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
!
state_dict
.
content_editable
)
{
return
gadget
.
jio_getAttachment
(
options
.
jio_key
,
"
data
"
);
}
return
gadget
.
declareGadget
(
"
gadget_ojs_cloudooo.html
"
)
.
push
(
function
(
ojs_cloudooo
)
{
return
ojs_cloudooo
.
getConvertedBlob
({
jio_key
:
options
.
jio_key
,
format
:
state_dict
.
mime_type
,
filename
:
options
.
doc
.
filename
});
});
})
.
push
(
undefined
,
function
(
error
)
{
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
404
)
{
return
new
Blob
();
}
throw
error
;
})
.
push
(
function
(
blob
)
{
if
(
state_dict
.
content_editable
)
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
}
}
return
jIO
.
util
.
readBlobAsText
(
blob
);
})
.
push
(
function
(
result
)
{
state_dict
.
data
=
result
.
target
.
result
;
if
(
portal_type_dict
.
blob_type
)
{
state_dict
.
blob_type
=
portal_type_dict
.
blob_type
;
}
else
{
state_dict
.
blob_type
=
"
ooffice
"
;
}
return
gadget
.
changeState
(
state_dict
);
});
}
//
if
(
portal_type_dict
.
blob_type
)
{
if
(
portal_type_dict
.
blob_type
)
{
if
(
options
.
jio_key
)
{
if
(
options
.
jio_key
)
{
...
...
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_form_view_js.xml
View file @
d5cc854b
...
@@ -269,7 +269,7 @@
...
@@ -269,7 +269,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
serial
</string>
</key>
<key>
<string>
serial
</string>
</key>
<value>
<string>
978.
32380.21754.21845
</string>
</value>
<value>
<string>
978.
46851.17123.15906
</string>
</value>
</item>
</item>
<item>
<item>
<key>
<string>
state
</string>
</key>
<key>
<string>
state
</string>
</key>
...
@@ -287,7 +287,7 @@
...
@@ -287,7 +287,7 @@
</tuple>
</tuple>
<state>
<state>
<tuple>
<tuple>
<float>
156
8708910.31
</float>
<float>
156
9577593.67
</float>
<string>
UTC
</string>
<string>
UTC
</string>
</tuple>
</tuple>
</state>
</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