Commit b1e8b649 authored by Boris Kocherov's avatar Boris Kocherov

erp5_officejs, erp5_xhtml_style: triggerMaximize(), triggerSubmit(),...

erp5_officejs, erp5_xhtml_style: triggerMaximize(), triggerSubmit(), setFillStyle() move to erp5_gadgetfield.js
parent 2d3e1380
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
/*globals window, rJS, Handlebars, RSVP, loopEventListener, console, document*/\n /*globals window, rJS, Handlebars, RSVP, loopEventListener, console, document*/\n
/*jslint indent: 2, nomen: true, maxlen: 80*/\n /*jslint indent: 2, nomen: true, maxlen: 80*/\n
(function (window, RSVP, rJS, Handlebars, loopEventListener) {\n (function (window, document, RSVP, rJS, Handlebars, loopEventListener) {\n
"use strict";\n "use strict";\n
\n \n
function saveContent(gadget, submit_event) {\n function saveContent(gadget, submit_event) {\n
...@@ -138,23 +138,16 @@ ...@@ -138,23 +138,16 @@
return gadget.put(gadget.options.jio_key, doc);\n return gadget.put(gadget.options.jio_key, doc);\n
});\n });\n
}\n }\n
\n \n
function maximize(gadget) {\n function setFillStyle(gadget) {\n
var iframe = gadget.props.element.querySelector(\'iframe\'),\n var iframe = gadget.props.element.querySelector(\'iframe\'),\n
iframe_class_string = iframe.getAttribute(\'class\') || "",\n height = getMaxHeight(iframe),\n
class_name = "ui-content-maximize",\n width = "100%";\n
class_index = iframe_class_string.indexOf(class_name);\n iframe.setAttribute(\n
if (class_index === -1) {\n \'style\',\n
iframe_class_string += \' \' + class_name;\n \'width: \' + width + \'; border: 0 none; height: \' + height\n
iframe.setAttribute(\'style\', \'\');\n );\n
iframe.setAttribute(\'class\', iframe_class_string);\n return {height: height, width: width};\n
return;\n
}\n
iframe_class_string = iframe_class_string.substring(0, class_index)\n
+ iframe_class_string.substring(class_index + class_name.length);\n
iframe.setAttribute(\'style\', \'width:100%; border: 0 none; height: 600px\');\n
iframe.setAttribute(\'class\', iframe_class_string);\n
return;\n
}\n }\n
\n \n
function getMaxHeight(wrap_obj) {\n function getMaxHeight(wrap_obj) {\n
...@@ -170,7 +163,7 @@ ...@@ -170,7 +163,7 @@
return height + "px";\n return height + "px";\n
}\n }\n
\n \n
function switchFullscreenMode(gadget) {\n function switchMaximizeMode(gadget) {\n
var fullscreen_classname = "ui-content-fullscreen",\n var fullscreen_classname = "ui-content-fullscreen",\n
wrap = gadget.props.element.querySelector(\'iframe\'),\n wrap = gadget.props.element.querySelector(\'iframe\'),\n
info = gadget.props.fullScreenRestore;\n info = gadget.props.fullScreenRestore;\n
...@@ -184,7 +177,6 @@ ...@@ -184,7 +177,6 @@
\n \n
wrap.style.width = "100%";\n wrap.style.width = "100%";\n
wrap.style.height = getMaxHeight();\n wrap.style.height = getMaxHeight();\n
// wrap.style.height = "auto";\n
wrap.className += " " + fullscreen_classname;\n wrap.className += " " + fullscreen_classname;\n
document.documentElement.style.overflow = "hidden";\n document.documentElement.style.overflow = "hidden";\n
} else {\n } else {\n
...@@ -195,6 +187,7 @@ ...@@ -195,6 +187,7 @@
wrap.style.height = getMaxHeight(wrap);\n wrap.style.height = getMaxHeight(wrap);\n
window.scrollTo(info.scrollLeft, info.scrollTop);\n window.scrollTo(info.scrollLeft, info.scrollTop);\n
}\n }\n
return { height: wrap.style.height, width: wrap.style.width }\n
}\n }\n
\n \n
var gadget_klass = rJS(window),\n var gadget_klass = rJS(window),\n
...@@ -222,22 +215,19 @@ ...@@ -222,22 +215,19 @@
.declareAcquiredMethod(\'allDocs\', \'jio_allDocs\')\n .declareAcquiredMethod(\'allDocs\', \'jio_allDocs\')\n
.declareAcquiredMethod("redirect", "redirect")\n .declareAcquiredMethod("redirect", "redirect")\n
\n \n
.allowPublicAcquisition(\'triggerMaximize\', function () {\n .allowPublicAcquisition(\'setFillStyle\', function () {\n
var gadget = this;\n return setFillStyle(this);\n
return RSVP.Queue()\n
.push(function () {\n
return maximize(gadget);\n
})\n })\n
.fail(function (e) {\n \n
console.log(e);\n .declareMethod(\'setFillStyle\', function () {\n
});\n return setFillStyle(this);\n
})\n })\n
\n \n
.allowPublicAcquisition(\'triggerFullscreen\', function () {\n .allowPublicAcquisition(\'triggerMaximize\', function () {\n
var gadget = this;\n var gadget = this;\n
return RSVP.Queue()\n return RSVP.Queue()\n
.push(function () {\n .push(function () {\n
return switchFullscreenMode(gadget);\n return switchMaximizeMode(gadget);\n
})\n })\n
.fail(function (e) {\n .fail(function (e) {\n
console.log(e);\n console.log(e);\n
...@@ -247,7 +237,7 @@ ...@@ -247,7 +237,7 @@
.allowPublicAcquisition(\'triggerSubmit\', function () {\n .allowPublicAcquisition(\'triggerSubmit\', function () {\n
return this.props.element.querySelector(\'button\').click();\n return this.props.element.querySelector(\'button\').click();\n
})\n })\n
\n \n
.declareMethod(\'triggerSubmit\', function () {\n .declareMethod(\'triggerSubmit\', function () {\n
return this.props.element.querySelector(\'button\').click();\n return this.props.element.querySelector(\'button\').click();\n
})\n })\n
...@@ -255,6 +245,7 @@ ...@@ -255,6 +245,7 @@
.declareMethod("render", function (options) {\n .declareMethod("render", function (options) {\n
var gadget = this;\n var gadget = this;\n
gadget.options = options;\n gadget.options = options;\n
\n
return gadget.jio_get(options.jio_key)\n return gadget.jio_get(options.jio_key)\n
.push(function (doc) {\n .push(function (doc) {\n
gadget.options.doc = doc;\n gadget.options.doc = doc;\n
...@@ -302,13 +293,9 @@ ...@@ -302,13 +293,9 @@
);\n );\n
})\n })\n
.push(function (text_content_gadget) {\n .push(function (text_content_gadget) {\n
var iframe = gadget.props.element.querySelector(\'iframe\');\n
iframe.setAttribute(\n
\'style\',\n
\'width:100%; border: 0 none; height: \' + getMaxHeight(iframe)\n
);\n
text_gadget = text_content_gadget;\n text_gadget = text_content_gadget;\n
switchFullscreenMode(gadget);\n gadget.setFillStyle();\n
// switchMaximizeMode(gadget);\n
return text_content_gadget.render({\n return text_content_gadget.render({\n
"key": \'text_content\',\n "key": \'text_content\',\n
"value": gadget.options.doc.data,\n "value": gadget.options.doc.data,\n
...@@ -342,7 +329,7 @@ ...@@ -342,7 +329,7 @@
});\n });\n
});\n });\n
\n \n
}(window, RSVP, rJS, Handlebars, loopEventListener)); }(window, document, RSVP, rJS, Handlebars, loopEventListener));
]]></string> </value> ]]></string> </value>
</item> </item>
...@@ -481,7 +468,7 @@ ...@@ -481,7 +468,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>947.62818.19237.36403</string> </value> <value> <string>948.31999.56515.17117</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -499,7 +486,7 @@ ...@@ -499,7 +486,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1450798287.45</float> <float>1452882676.55</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -125,7 +125,6 @@ ...@@ -125,7 +125,6 @@
<script src="rsvp.js" type="text/javascript"></script>\n <script src="rsvp.js" type="text/javascript"></script>\n
<script src="renderjs.js" type="text/javascript"></script>\n <script src="renderjs.js" type="text/javascript"></script>\n
\n \n
<script type="text/javascript" src="ooffice/vendor/underscore/underscore-min.js"></script>\n
<script type="text/javascript" src="ooffice/apps/api/documents/api.js"></script>\n <script type="text/javascript" src="ooffice/apps/api/documents/api.js"></script>\n
<script src="gadget_ooffice.js" type="text/javascript"></script>\n <script src="gadget_ooffice.js" type="text/javascript"></script>\n
\n \n
...@@ -273,7 +272,7 @@ ...@@ -273,7 +272,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>947.29411.54037.32699</string> </value> <value> <string>948.29298.60056.13943</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -291,7 +290,7 @@ ...@@ -291,7 +290,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1450885798.7</float> <float>1452880107.0</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -113,11 +113,9 @@ ...@@ -113,11 +113,9 @@
</item> </item>
<item> <item>
<key> <string>text_content</string> </key> <key> <string>text_content</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>/*global window, rJS, DocsAPI, console, document*/\n
/*global window, rJS, DocsAPI, _, console, document*/\n
/*jslint nomen: true, maxlen:80, indent:2*/\n /*jslint nomen: true, maxlen:80, indent:2*/\n
(function (rJS, DocsAPI, _) {\n (function (rJS, DocsAPI) {\n
"use strict";\n "use strict";\n
// Document Editor event handlers\n // Document Editor event handlers\n
//function onRequestHistory() {\n //function onRequestHistory() {\n
...@@ -229,48 +227,6 @@ ...@@ -229,48 +227,6 @@
// critical error happened\n // critical error happened\n
// examine event.data.errorCode and event.data.errorDescription for details\n // examine event.data.errorCode and event.data.errorDescription for details\n
}\n }\n
\n
function getMaxHeight(wrap_obj) {\n
var height;\n
if (wrap_obj) {\n
height = window.innerHeight - wrap_obj.offsetTop - 280;\n
} else {\n
height = window.innerHeight;\n
}\n
if (height < 400) {\n
height = 400;\n
}\n
return height + "px";\n
}\n
\n
function switchFullscreenMode(gadget) {\n
return function (event) {\n
var fullscreen_classname = "ui-content-fullscreen",\n
info,\n
wrap = gadget.props.element.querySelector(\'iframe\');\n
if (wrap.className.search(" " + fullscreen_classname) === -1) {\n
gadget.props.fullScreenRestore = {\n
scrollTop: window.pageYOffset,\n
scrollLeft: window.pageXOffset,\n
width: wrap.width,\n
height: wrap.height\n
};\n
\n
wrap.style.width = "100%";\n
wrap.style.height = getMaxHeight();\n
wrap.className += " " + fullscreen_classname;\n
document.documentElement.style.overflow = "hidden";\n
} else {\n
wrap.className = wrap.className\n
.replace(new RegExp("\\\\s*" + fullscreen_classname + "\\\\b"), "");\n
document.documentElement.style.overflow = "";\n
info = gadget.props.fullScreenRestore;\n
wrap.style.width = info.width;\n
wrap.style.height = getMaxHeight(wrap);\n
window.scrollTo(info.scrollLeft, info.scrollTop);\n
}\n
};\n
}\n
\n \n
rJS(window)\n rJS(window)\n
.ready(function (g) {\n .ready(function (g) {\n
...@@ -359,44 +315,31 @@ ...@@ -359,44 +315,31 @@
g.props.element = element;\n g.props.element = element;\n
});\n });\n
})\n })\n
.declareAcquiredMethod("submitContent", "triggerSubmit")\n .declareAcquiredMethod("triggerSubmit", "triggerSubmit")\n
.declareAcquiredMethod("maximize", "triggerMaximize")\n .declareAcquiredMethod("triggerMaximize", "triggerMaximize")\n
.declareAcquiredMethod("fullscreen", "triggerFullscreen")\n .declareAcquiredMethod("setFillStyle", "setFillStyle")\n
.declareMethod(\'render\', function (options) {\n .declareMethod(\'render\', function (options) {\n
var placehodler = \'oospreadsheet_gadget\',\n var placeholder = \'oospreadsheet_gadget\',\n
placehodler_obj = document.getElementById(placehodler),\n g = this,\n
save_button = document.querySelector("button[name=\'Base_edit:method\']"),\n
height,\n
onBack,\n
documentType,\n documentType,\n
magic_to_format_map = {\n magic_to_format_map = {\n
\'DOCY;\' : \'text\',\n \'DOCY;\' : \'text\',\n
\'XLSY;\' : \'spreadsheet\',\n \'XLSY;\' : \'spreadsheet\',\n
\'PPTY;\' : \'presentation\'\n \'PPTY;\' : \'presentation\'\n
};\n };\n
if (save_button) {\n
this.props.erp5_mode = true;\n
save_button.hidden = true;\n
height = getMaxHeight(placehodler_obj);\n
onBack = switchFullscreenMode(this);\n
} else {\n
height = \'100%\';\n
onBack = _.bind(function (event) {\n
this.fullscreen();\n
}, this);\n
}\n
if (options.value === undefined) {\n if (options.value === undefined) {\n
options.value = \'\';\n options.value = \'\';\n
documentType = options.portal_type;\n documentType = options.portal_type;\n
} else {\n } else {\n
documentType = magic_to_format_map[options.value.substring(0, 5)];\n documentType = magic_to_format_map[options.value.substring(0, 5)];\n
}\n }\n
this.props.docEditor = new DocsAPI.DocEditor(placehodler, {\n return g.setFillStyle()\n
.push(function (size) {\n
g.props.docEditor = new DocsAPI.DocEditor(placeholder, {\n
//type: urlParams[\'type\'],\n //type: urlParams[\'type\'],\n
width: \'100%\',\n width: size.width,\n
height: height,\n height: size.height,\n
// height: getMaxHeight(placehodler_obj),\n documentType: documentType,\n
//documentType: urlParams[\'doctype\'],\n
document: {\n document: {\n
//key: undefined,\n //key: undefined,\n
//url: undefined,\n //url: undefined,\n
...@@ -410,47 +353,47 @@ ...@@ -410,47 +353,47 @@
reader: true\n reader: true\n
}\n }\n
},\n },\n
documentType: documentType,\n editorConfig: g.props.cfg,\n
editorConfig: this.props.cfg,\n
events: {\n events: {\n
\'onReady\': onDocEditorReady,\n \'onReady\': onDocEditorReady,\n
\'onBack\': onBack,\n \'onBack\': function (event) {\n
g.triggerMaximize()\n
.push(function (size) {\n
var iframe = g.props.element.querySelector(\'iframe\');\n
iframe.style.height = size.height;\n
iframe.style.width = size.width;\n
\n
});\n
},\n
// \'onDocumentStateChange\': function (event) {\n // \'onDocumentStateChange\': function (event) {\n
// if (!event.data) {\n // if (!event.data) {\n
// save_button.click();\n // save_button.click();\n
// }\n // }\n
// },\n // },\n
\'onRequestEditRights\': _.bind(function (event) {\n \'onRequestEditRights\': function (event) {\n
// occurs whenever the user tryes to enter edit mode\n // occurs whenever the user tryes to enter edit mode\n
this.props.docEditor.applyEditRights(true,\n g.props.docEditor.applyEditRights(true,\n
"Someone is editing this document right now." +\n "Someone is editing this document right now." +\n
" Please try again later.");\n " Please try again later.");\n
}, this),\n },\n
//\'onRequestHistory\': onRequestHistory,\n //\'onRequestHistory\': onRequestHistory,\n
//\'onRequestHistoryData\': onRequestHistoryData,\n //\'onRequestHistoryData\': onRequestHistoryData,\n
//\'onRequestHistoryClose\': onRequestHistoryClose,\n //\'onRequestHistoryClose\': onRequestHistoryClose,\n
\'onSave\': _.bind(function (event) {\n \'onSave\': function (event) {\n
this.props.value = event.data;\n g.props.value = event.data;\n
if (this.props.erp5_mode) {\n g.triggerSubmit();\n
save_button.click();\n
} else {\n
this.submitContent();\n
}\n
// clickSaveButton(\'Base_edit\');\n
return true;\n return true;\n
// if you want to async save process return false\n // if you want to async save process return false\n
// and call api.processSaveResult when ready\n // and call api.processSaveResult when ready\n
}, this),\n },\n
\'onError\': onError\n \'onError\': onError\n
}\n }\n
});\n });\n
this.props.key = options.key || "text_content";\n g.props.key = options.key || "text_content";\n
this.props.value = options.value;\n g.props.value = options.value;\n
// default FullscreenMode\n // g.fullscreen();\n
if (this.props.erp5_mode) {\n
switchFullscreenMode(this)();\n
}\n
return {};\n return {};\n
});\n
})\n })\n
\n \n
.declareMethod(\'getContent\', function () {\n .declareMethod(\'getContent\', function () {\n
...@@ -462,9 +405,7 @@ ...@@ -462,9 +405,7 @@
return result;\n return result;\n
});\n });\n
\n \n
}(rJS, DocsAPI, _)); }(rJS, DocsAPI));</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>version</string> </key> <key> <string>version</string> </key>
...@@ -591,7 +532,7 @@ ...@@ -591,7 +532,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>947.64367.38968.33962</string> </value> <value> <string>948.31979.10733.53111</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -609,7 +550,7 @@ ...@@ -609,7 +550,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1450904842.41</float> <float>1452885806.26</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -177,7 +177,7 @@ ...@@ -177,7 +177,7 @@
</item> </item>
<item> <item>
<key> <string>css_class</string> </key> <key> <string>css_class</string> </key>
<value> <string></string> </value> <value> <string>page</string> </value>
</item> </item>
<item> <item>
<key> <string>data_url</string> </key> <key> <string>data_url</string> </key>
...@@ -229,7 +229,7 @@ ...@@ -229,7 +229,7 @@
</item> </item>
<item> <item>
<key> <string>js_sandbox</string> </key> <key> <string>js_sandbox</string> </key>
<value> <string></string> </value> <value> <string>iframe</string> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</item> </item>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts20545059.65</string> </value> <value> <string>ts53113105.03</string> </value>
</item> </item>
<item> <item>
<key> <string>__name__</string> </key> <key> <string>__name__</string> </key>
...@@ -54,6 +54,19 @@ ...@@ -54,6 +54,19 @@
}\n }\n
return new RSVP.Promise(resolver, canceller);\n return new RSVP.Promise(resolver, canceller);\n
}\n }\n
\n
function getMaxHeight(wrap_obj) {\n
var height;\n
if (wrap_obj) {\n
height = window.innerHeight - wrap_obj.offsetTop - 280;\n
} else {\n
height = window.innerHeight;\n
}\n
if (height < 400) {\n
height = 400;\n
}\n
return height + "px";\n
}\n
\n \n
rJS(window)\n rJS(window)\n
/////////////////////////////////////////////////////////////////\n /////////////////////////////////////////////////////////////////\n
...@@ -74,6 +87,53 @@ ...@@ -74,6 +87,53 @@
/////////////////////////////////////////////////////////////////\n /////////////////////////////////////////////////////////////////\n
// declared methods\n // declared methods\n
/////////////////////////////////////////////////////////////////\n /////////////////////////////////////////////////////////////////\n
.allowPublicAcquisition(\'setFillStyle\', function () {\n
var gadget = this,\n
iframe = gadget.props.element.querySelector(\'iframe\'),\n
height = getMaxHeight(iframe),\n
width = "100%";\n
iframe.setAttribute(\n
\'style\',\n
\'width: \' + width + \'; border: 0 none; height: \' + height\n
);\n
return {height: height, width: width};\n
})\n
.allowPublicAcquisition(\'triggerMaximize\', function () {\n
var gadget = this,\n
fullscreen_classname = "ui-content-fullscreen",\n
info,\n
wrap = gadget.props.element.querySelector(\'iframe\'),\n
subiframe = wrap.contentDocument.querySelector(\'iframe\');\n
if (wrap.className.search(" " + fullscreen_classname) === -1) {\n
gadget.props.fullScreenRestore = {\n
scrollTop: window.pageYOffset,\n
scrollLeft: window.pageXOffset,\n
width: wrap.width,\n
height: wrap.height\n
};\n
\n
wrap.style.width = "100%";\n
wrap.style.height = getMaxHeight();\n
wrap.className += " " + fullscreen_classname;\n
document.documentElement.style.overflow = "hidden";\n
} else {\n
wrap.className = wrap.className\n
.replace(new RegExp("\\\\s*" + fullscreen_classname + "\\\\b"), "");\n
document.documentElement.style.overflow = "";\n
info = gadget.props.fullScreenRestore;\n
// wrap.style.width = info.width;\n
wrap.style.width = "100%";\n
wrap.style.height = getMaxHeight(wrap);\n
window.scrollTo(info.scrollLeft, info.scrollTop);\n
}\n
if (subiframe) {\n
subiframe.style.height = wrap.style.height;\n
}\n
})\n
\n
.allowPublicAcquisition(\'triggerSubmit\', function () {\n
return document.querySelector("button[name=\'Base_edit:method\']").click();\n
})\n
.declareService(function () {\n .declareService(function () {\n
var g = this,\n var g = this,\n
i,\n i,\n
...@@ -233,7 +293,7 @@ ...@@ -233,7 +293,7 @@
</item> </item>
<item> <item>
<key> <string>size</string> </key> <key> <string>size</string> </key>
<value> <int>7063</int> </value> <value> <int>9114</int> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment