Commit c935aca2 authored by Gabriel L. Oliveira's avatar Gabriel L. Oliveira

Refactor javascript to apply inside new ung structure

- Refactor to apply new way to render ung listbox
- Increase performance by loading some elements only when necessary
parent 99825fef
......@@ -30,6 +30,18 @@
<key> <string>raw</string> </key>
<value> <string encoding="cdata"><![CDATA[
$.fn.outerHTML = function() {\n
$t = $(this);\n
if( "outerHTML" in $t[0] )\n
{ return $t[0].outerHTML; }\n
else\n
{\n
var content = $t.wrap(\'<div></div>\').parent().html();\n
$t.unwrap();\n
return content;\n
}\n
}\n
\n
function getCurrentObjectUrl(){\n
return window.location.href.split("?")[0];\n
}\n
......@@ -79,7 +91,7 @@ function showNotImplementedMessage(tag){\n
\n
function updateWebPage(){\n
var parameterList = getUrlParameterList();\n
url = "WebPage_updateWebDocument?document_path=" + \n
url = "WebPage_updateWebDocument?document_path=" +\n
parameterList.document_path;\n
$.get(url, {}, function(data, textStatus, XMLHttpRequest){\n
response = jQuery.parseJSON(data);\n
......@@ -101,7 +113,7 @@ function checkConversion(){\n
case "converted":\n
$("a#loading_message").text("Opening your Document...");\n
clearTimeout();\n
setTimeout(updateWebPage(), 1000); \n
setTimeout(updateWebPage(), 1000);\n
break;\n
case "conversion_failed":\n
clearTimeout();\n
......@@ -109,7 +121,7 @@ function checkConversion(){\n
setTimeout(window.location.href = window.location.href.match("^http.*\\/ung")[0], 3000);\n
break;\n
default:\n
setTimeout(checkConversion(), 1500); \n
setTimeout(checkConversion(), 1500);\n
break;\n
}\n
});\n
......@@ -120,6 +132,7 @@ function setObjectPropertyValue(method_name, value, parameter){\n
type: "POST",\n
url: method_name,\n
data: parameter + "=" + value,\n
async: false,\n
});\n
return true;\n
}\n
......@@ -149,13 +162,22 @@ function displayFormMessage(message, delay){\n
}\n
\n
function displayLoginForm(){\n
var tagToHide = "a.ung_docs, img[alt=\'calendar_logo_box\']," + \n
"table#create-new-user, img[alt=\'mail_logo_box\']" + \n
var tagToHide = "a.ung_docs, img[alt=\'calendar_logo_box\']," +\n
"table#create-new-user, img[alt=\'mail_logo_box\']" +\n
", div.navigation";\n
$(tagToHide).hide();\n
$("div.header-left div.field input, div.main-right, div.main-left").hide();\n
$.get("WebSection_loginDialog", function(data){\n
// set body\n
$("div.header-left fieldset.widget").append("<p>" + data + "</p>");\n
// fix \'ENTER\' key to form submit on firefox browser\n
$("//input[id=\'name\'], //input[id=\'password\']").bind(\'keyup\', function(e) {\n
if (e.which == 13) {\n
$(\'form#main_form\').submit();\n
e.preventDefault();\n
}\n
});\n
// set "new account form" behaviour\n
$("td#new-account-form").click(function(event){\n
$("table#field_table, table#new-account-table").hide();\n
$("table#create-new-user input[type=\'text\'], table#create-new-user input[type=\'password\']").each(function(){\n
......@@ -185,7 +207,7 @@ function displayLoginForm(){\n
else {\n
displayFormMessage("The user " + formHash.login_name + " will be created in few seconds...", 8000);\n
var paramStr = "reference=" + formHash.login_name;\n
setTimeout(waitCreateUNGUser(paramStr), 2000); \n
setTimeout(waitCreateUNGUser(paramStr), 2000);\n
}\n
});\n
});\n
......@@ -246,7 +268,7 @@ $().ready(function(){\n
link.attr({type: \'text/css\', rel:\'stylesheet\', href:data});\n
$("head").append(link);\n
});\n
}); \n
});\n
break;\n
}\n
}\n
......@@ -263,69 +285,14 @@ $().ready(function(){\n
$(this).css("padding-right", "24px")\n
}\n
});\n
if ($("div.listbox-domain-tree-container").length >= 1) {\n
$("a.domain_selected").text($("a.tree-open:last").text());\n
var listboxTreeHeight = $("div.listbox-tree").css("height").replace("px", "");\n
var domainTreeHeight = $("div.listbox-domain-tree-container").css("height").replace("px", "");\n
if (parseInt(listboxTreeHeight) > parseInt(domainTreeHeight)){\n
window.onload = function() {\n
$("div.listbox-tree").css("height", $("div.listbox-domain-tree-container").css("height"));\n
}\n
}\n
if (parseInt(domainTreeHeight) > 233) {\n
window.onload = function() {\n
$("div.listbox-tree").css("overflow-y", "scroll");\n
}\n
}\n
$("body").css("overflow", "hidden");\n
var navigation_html = $("div.listbox-footer div.listbox-page-navigation").html();\n
$("div.listbox-footer div.listbox-page-navigation").remove();\n
var navigation_div = "<div class=\'listbox-navigation\'>" + navigation_html + "</div>";\n
$("div.toolbar").append(navigation_div);\n
var listbox_tree_html = $("div.listbox-tree").html();\n
var listbox_tree_div = "<div class=\'listbox-tree\'>" + listbox_tree_html + "</div>";\n
$("div.listbox-tree").remove();\n
$("div.file-quick-search").append(listbox_tree_div);\n
var tr_length = $("div.main-right tbody tr").length;\n
if (tr_length < 16){\n
var height = tr_length * 1.5;\n
$("div.main-right tbody").css("height", height + "em");\n
}\n
if ($("div.listbox-navigation").text() == "null")\n
$("div.listbox-navigation").hide();\n
$.getJSON("WebSection_getGadgetPathList", function(data){\n
gadgetList = jQuery(data);\n
gadgetList.each(function(){\n
$("div.gadget-listbox table#gadget-table")\n
.append($(\'<tr>\')\n
.append($(\'<td>\')\n
.append($(\'<input>\')\n
.attr(\'type\', \'checkbox\')\n
.attr(\'id\', this.id)\n
) \n
)\n
.append($(\'<td>\')\n
.append($(\'<a>\')\n
.text(this.title)\n
)\n
)\n
.append($(\'<td>\')\n
.append($(\'<img>\')\n
.attr(\'src\', this.image_url)\n
.text(this.title)\n
)\n
)\n
);\n
});\n
});\n
}\n
else {\n
\n
if ($("div.listbox-domain-tree-container").length < 1) {\n
$("div.action_menu ul li a").click(function(event){\n
event.preventDefault();\n
herfList = this.getAttribute("href").split("?");\n
action_name = herfList[herfList.length-1].split("=")[1];\n
$.ajax({\n
url: "Base_changeWorkflowState", \n
url: "Base_changeWorkflowState",\n
data: "action_name=" + action_name,\n
success: function(){\n
window.location.reload();\n
......@@ -333,7 +300,7 @@ $().ready(function(){\n
});\n
});\n
if ($("a[name=\'document_state\']").text() == "Draft") {\n
$("div.action_menu li ul").append("<li><a id=\'share_document\' href=\'#\'>" + \n
$("div.action_menu li ul").append("<li><a id=\'share_document\' href=\'#\'>" +\n
"<h6>Share this Document</h6></a></li>");\n
$("div.action_menu ul li a#share_document").click(function(event){\n
event.preventDefault();\n
......@@ -346,6 +313,7 @@ $().ready(function(){\n
};\n
$("div.action_menu li ul").css("height", $("div.action_menu li ul li").length * 25.3 + "px");\n
};\n
\n
$("#edit_document").dialog({\n
autoOpen: false,\n
height: 131,\n
......@@ -367,7 +335,7 @@ $().ready(function(){\n
setObjectPropertyValue("setLanguage", new_language, "language");\n
setObjectPropertyValue("setVersion", new_version, "value");\n
setObjectPropertyValue("setIntIndex", new_int_index, "value");\n
setObjectPropertyValue("WebPage_setSubjectList", new_subject_list, "value"); \n
setObjectPropertyValue("WebPage_setSubjectList", new_subject_list, "value");\n
$("#edit_document").dialog("close");\n
save_button.click();\n
},\n
......@@ -400,7 +368,7 @@ $().ready(function(){\n
};\n
var tabTitle = $("div#tabs ul li.tab_selected span").html();\n
$.ajax({\n
type: "post", \n
type: "post",\n
url:"WebSection_addGadgetList",\n
data: [{name:"gadget_id_list", value: gadgetIdList}],\n
success: function(data) {\n
......@@ -419,11 +387,13 @@ $().ready(function(){\n
"Save": function(){\n
var erp5PreferenceArgument = $("form#erp5_preference").serialize();\n
$.ajax({\n
async: false,\n
url: ungPreferencePath + "/Base_edit",\n
data: erp5PreferenceArgument + "&form_id=Preference_viewHtmlStyle",\n
});\n
var ungPreferenceArgument = $("form#ung_preference").serialize();\n
$.ajax({\n
async: false,\n
url: ungPreferencePath + "/Base_edit",\n
data: ungPreferenceArgument + "&form_id=UNGPreference_view",\n
});\n
......@@ -467,14 +437,14 @@ $().ready(function(){\n
$.getJSON("Base_getPreferencePathList", function(data){\n
ungPreferencePath = data.preference;\n
$.get(ungPreferencePath + \'/Preference_viewHtmlStyle?editable_mode:int=1\', function(data){\n
$("div#preference_dialog").append("<form id=\'erp5_preference\'>" + \n
"<fieldset class=\'center editable\'>" + \n
$("div#preference_dialog").append("<form id=\'erp5_preference\'>" +\n
"<fieldset class=\'center editable\'>" +\n
$(data).find(\'fieldset.center.editable\').html() +\n
"</fieldset></form>");\n
});\n
$.get(ungPreferencePath + \'/UNGPreference_view?editable_mode:int=1\', function(data){ \n
$("div#preference_dialog").append("<form id=\'ung_preference\'>" + \n
"<fieldset class=\'center editable\'>" + \n
$.get(ungPreferencePath + \'/UNGPreference_view?editable_mode:int=1\', function(data){\n
$("div#preference_dialog").append("<form id=\'ung_preference\'>" +\n
"<fieldset class=\'center editable\'>" +\n
$(data).find(\'fieldset.center.editable\').html() +\n
"</fieldset></form>");\n
});\n
......@@ -482,7 +452,90 @@ $().ready(function(){\n
}\n
$("div#preference_dialog").dialog("open");\n
});\n
$("button.ui-button, span.ui-icon").click(function(){$("p#hide_properties").click()}); \n
\n
$("button#change_state")\n
.click(function(event){\n
event.preventDefault();\n
$("div#change_state_dialog").html(\'\');\n
$.ajax({\n
async: false,\n
url: \'WebSection_changeStateHelperUpdatePortalSelections\',\n
data: $("form#main_form").serialize(),\n
success: function(datax){\n
}\n
});\n
$.ajax({\n
async: false,\n
url: \'erp5/Folder_viewWorkflowActionDialog\',\n
data: {selection_name: $(\'input[name=list_selection_name]\').val(),\n
form_id: $(\'input[name=gadget_form_id]\').val(),\n
editable_mode: 1,\n
},\n
success: function(data2) {\n
folder_workflow_action_dialog_data = data2\n
$("div#change_state_dialog").append("<form id=\'change_state_form\'>" +\n
"<div class=\'xunda\'>" +\n
"<table class=\'listbox listbox-table\'>" +\n
" <thead>" +\n
" <tr class=\'listbox-label-line\'>" +\n
" <th class=\'listbox-table-header-cell\'>Count</th>" +\n
" <th class=\'listbox-table-header-cell\'>Type</th>" +\n
" <th class=\'listbox-table-header-cell\'>State</th>" +\n
" <th class=\'listbox-table-header-cell\'>Workflow</th>" +\n
" <th class=\'listbox-table-header-cell\'>Action</th>" +\n
" </tr>" +\n
" </thead>" +\n
" <tbody>" +\n
$(data2).find(\'div.listbox-body > table > tbody\').html() +\n
" </tbody></table>" +\n
" </div>" +\n
$(data2).find(\'textarea[name*="comment"]\').parent().parent().html() +\n
"</form>");\n
$("div#change_state_dialog").dialog("open");\n
}\n
});\n
});\n
$("div#change_state_dialog").dialog({\n
autoOpen: false,\n
height: 400,\n
width: 600,\n
modal:true,\n
buttons: {\n
\'Change State\': function() {\n
var folder_workflow_data = $(folder_workflow_action_dialog_data).find(\'input[type="hidden"]\').serializeArray();\n
var change_state_data = $(\'form#change_state_form\').serializeArray();\n
var merge = {};\n
$.map(folder_workflow_data, function(n,i){merge[n.name] = n.value});\n
$.map(change_state_data, function(n,i){merge[n.name] = n.value});\n
merge[\'form_id\'] = \'WebSection_viewUNGDocumentList\';\n
$.ajax({\n
async: false,\n
url: \'web_site_module\' + "/Base_callDialogMethod",\n
data: merge,\n
success: function(result){\n
var form_data = $(result).find(\'input[type="hidden"]\').serializeArray();\n
var merge2 = {};\n
$.map(form_data, function(n,i){merge2[n.name] = n.value});\n
$.ajax({\n
async: false,\n
url: \'web_site_module\' + "/Base_callDialogMethod",\n
data: merge2,\n
success: function(result2){\n
$("div#change_state_dialog").dialog("close");\n
setPortalStatusMessage("Workflow in progress. Please refresh your page to take changes.");\n
}\n
});\n
}\n
});\n
},\n
Cancel: function() {\n
$( this ).dialog("close");\n
},\n
\n
}\n
});\n
\n
$("button.ui-button, span.ui-icon").click(function(){$("p#hide_properties").click()});\n
$("input#submit_document").click(function(event){\n
if (document.getElementById("upload-file").value == ""){\n
event.preventDefault();\n
......@@ -504,22 +557,17 @@ $().ready(function(){\n
$("input#language.language").attr("value", getObjectPropertyValue("getLanguage"));\n
$("input#sort_index.sort_index").attr("value", getObjectPropertyValue("getIntIndex"));\n
var subjectList = jQuery.parseJSON(getObjectPropertyValue(\'getSubjectList\').replace(/\'/g,\'"\'));\n
if (subjectList != null)\n
if (subjectList != null) {\n
$("textarea#keyword_list").attr("value", subjectList.join("\\n"));\n
$("#edit_document").dialog("open"); \n
} else {\n
$("textarea#keyword_list").attr("value", "");\n
}\n
$("#edit_document").dialog("open");\n
});\n
$("a#help").click(function(event){\n
event.preventDefault();\n
showNotImplementedMessage("a#right_message");\n
});\n
$("input.listbox-check-all").click(function(event){\n
event.preventDefault();\n
changeCheckBoxValue(true);\n
});\n
$("input.listbox-uncheck-all").click(function(event){\n
event.preventDefault();\n
changeCheckBoxValue(false);\n
});\n
$("span#knowledge_pad_module_8_titlean").text("1");\n
if ($("#tab-list-container #tabs ul li").length > 2) {\n
$("li#add_new_tab_dialog_link.tab").hide()\n
......@@ -527,6 +575,32 @@ $().ready(function(){\n
$("div#add_new_gadget_link a#add-gadgets").removeAttr("onclick");\n
$("div#add_new_gadget_link a#add-gadgets").click(function(event){\n
event.preventDefault();\n
// fill gadget list\n
$.getJSON("WebSection_getGadgetPathList", function(to_parse_data){\n
gadgetList = jQuery(to_parse_data);\n
gadgetList.each(function(){\n
$("div.gadget-listbox table#gadget-table")\n
.append($(\'<tr>\')\n
.append($(\'<td>\')\n
.append($(\'<input>\')\n
.attr(\'type\', \'checkbox\')\n
.attr(\'id\', this.id)\n
)\n
)\n
.append($(\'<td>\')\n
.append($(\'<a>\')\n
.text(this.title)\n
)\n
)\n
.append($(\'<td>\')\n
.append($(\'<img>\')\n
.attr(\'src\', this.image_url)\n
.text(this.title)\n
)\n
)\n
);\n
});\n
});\n
$("div.gadget-listbox").dialog("open");\n
});\n
$("div#page_wrapper div#portal-column-1.portal-column, div#page_wrapper div#portal-column-2.portal-column").remove();\n
......@@ -545,8 +619,184 @@ $().ready(function(){\n
if (h3Tag.text().replace(/^\\s+/,\'\').replace(/\\s+$/,\'\') == "Your tab is empty."){\n
h3Tag.hide();\n
}\n
\n
// render main document listbox\n
$.ajax({\n
async: false,\n
url: \'WebSection_getUNGDocumentListPadAsJSON\',\n
data: {pad_relative_url: \'knowledge_pad_module/ung_knowledge_pad\', mode: \'web_front\'},\n
dataType: \'json\',\n
success: function(data){\n
external_data = data\n
var data_html = $(data.body)[0]\n
//var data_script = $(data.body)[1].text\n
var data_script = data.javascript\n
\n
ung_listbox_container = $(\'div#main_listbox-container\')\n
// fill body\n
ung_listbox_container.html(data_html);\n
// attach listener\n
ung_listbox_container.live(\'DOMSubtreeModified\', checkUNGListbox)\n
// eval script\n
eval(data_script)\n
// remove class \'portal-column\' from main listbox\n
// (as it should not interfere in user\'s box layout)\n
// updateServerBoxColumnLayout method uses \'div.portal-column\' as selector\n
ung_listbox_container.find(\'div.portal-column\')[0].className = \'\'\n
\n
configureUNGSearch(data_script);\n
\n
wrapUpdater();\n
}\n
});\n
\n
return false;\n
});
});\n
\n
function configureUNGSearch(data_script) {\n
$(\'input#search_button\').click(function(event){\n
event.preventDefault();\n
var searched_text = $(\'input[name="field_your_search_text"]\').val()\n
\n
// keep old function to call\n
var originalUpdater = updater;\n
// overwrite (shadowing) to change \'params\' param on the fly\n
updater = function() {\n
// \'params\' is the fifth param, so treat it\n
params = arguments[4]\n
params[\'SearchableText\'] = searched_text\n
originalUpdater.apply(this, arguments);\n
}\n
// eval script\n
eval(data_script)\n
\n
// restore old function\n
updater = originalUpdater;\n
})\n
}\n
\n
function wrapUpdater() {\n
originalUpdater = updater;\n
updater = wrappedUpdater;\n
}\n
\n
function wrappedUpdater() {\n
dom_id = arguments[2];\n
additional_request_params = arguments[4];\n
\n
// let UNG save checked itens of main listbox under portal_selections\n
enabled_checkboxes = $(\'#\'+dom_id).find(\'input[type="checkbox"]:checked\');\n
enabled_checkboxes.each(function(key, value){\n
element = $(value);\n
element_name = element.attr("name");\n
element_value = element.val();\n
if (typeof(additional_request_params[element_name]) == "undefined") {\n
additional_request_params[element_name] = new Array();\n
}\n
additional_request_params[element_name].push(element_value);\n
})\n
originalUpdater.apply(this, arguments);\n
}\n
\n
function checkUNGListbox() {\n
gadget_listbox_container = $(\'div#main_listbox-container div.listbox-container\')\n
if (gadget_listbox_container.length >= 1) {\n
// XXX: the .die and .live calls are because of the call to .find function\n
// that is triggered recursively without stop if parent has the .live\n
// listener, like in this case\n
ung_listbox_container.die(\'DOMSubtreeModified\');\n
\n
// look if there\'s a listbox-tree (listbox-domain navigation) inside\n
// main content of listbox. If it finds someone, then call\n
// separate_script to detach fields of main content of listbox [again]\n
if (gadget_listbox_container.find("div.listbox-tree").length >= 1) {\n
separateUNGListboxGadgetFields();\n
}\n
\n
// re-attach listener\n
ung_listbox_container.live(\'DOMSubtreeModified\', checkUNGListbox);\n
};\n
}\n
\n
function separateUNGListboxGadgetFields() {\n
// get gadget listbox container\n
var data = gadget_listbox_container;\n
\n
// remove menu of listbox container gadget\n
ung_listbox_container.find(\'h3.handle\').remove();\n
\n
// detach domain_selected\n
$("a.domain_selected").text(data.find("button.tree-open:last").text());\n
\n
// XXX: temporaly commented while developing\n
// TODO: analyze if this css is breaking layout of \'global scope\'\n
// $("body").css("overflow", "hidden");\n
\n
// detach listbox-page-navigation\n
var gadget_navigation = data.find("div.listbox-footer div.listbox-page-navigation");\n
if (gadget_navigation) {\n
ung_toolbar_navigation = $(\'div.toolbar\').find(\'div.listbox-navigation\');\n
ung_toolbar_navigation.html(gadget_navigation.html());\n
gadget_navigation.remove();\n
}\n
\n
// detach css of listbox-tree\n
var listboxTreeHeight = data.find("div.listbox-tree").css("height").replace("px", "");\n
try {\n
var domainTreeHeight = data.find("div.listbox-domain-tree-container").css("height").replace("px", "");\n
} catch(e) {\n
// this maybe categorize first access of user, needing\n
// to reload page, in time to create \'selection\' in portal_selections\n
window.location.reload();\n
return false;\n
}\n
if (parseInt(listboxTreeHeight) > parseInt(domainTreeHeight)){\n
data.find("div.listbox-tree").css("height", data.find("div.listbox-domain-tree-container").css("height"));\n
}\n
if (parseInt(domainTreeHeight) > 233) {\n
data.find("div.listbox-tree").css("overflow-y", "scroll");\n
}\n
\n
// detach listbox-tree\n
var listbox_tree_div = data.find("div.listbox-tree").outerHTML();\n
data.find("div.listbox-tree").remove();\n
// XXX: improve this behaviour of replacing\n
file_listbox_tree = $(\'div.file-quick-search\').find(\'div.listbox-tree\')\n
if (file_listbox_tree.length >= 1) {\n
file_listbox_tree.replaceWith(listbox_tree_div);\n
} else {\n
$("div.file-quick-search").append(listbox_tree_div);\n
}\n
\n
// detach css of listbox-body\n
var tr_length = data.find("div.listbox-body tbody tr").length;\n
if (tr_length < 16){\n
var height = tr_length * 1.5;\n
data.find("div.listbox-body tbody").css("height", height + "em");\n
}\n
\n
// hide listbox-page-navigation if doesn\'t need it\n
if (data.find("div.listbox-page-navigation").text() == "null")\n
data.find("div.listbox-page-navigation").hide();\n
\n
// update checkAll and uncheckAll buttons under listbox\n
$("input.listbox-check-all").click(function(event){\n
event.preventDefault();\n
changeCheckBoxValue(true);\n
});\n
$("input.listbox-uncheck-all").click(function(event){\n
event.preventDefault();\n
changeCheckBoxValue(false);\n
});\n
}\n
\n
function setPortalStatusMessage(status_message) {\n
//display warning\n
status_message_tag = $(\'div.portal_status_message\')\n
status_message_tag.css("font-weight", "bold")\n
status_message_tag.text(status_message)\n
}\n
]]></string> </value>
</item>
......
2011-07-01 gabriel.oliveira
* Refactor javascript to apply inside new ung structure
2011-07-01 gabriel.oliveira
* Refactor css to apply inside new ung structure
......
376
\ No newline at end of file
377
\ No newline at end of file
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