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