1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
36 function treeinit() {}
38 if(typeof('console') == 'undefined'){
40 log: function(message){
46 Event = YAHOO.util.Event,
47 Connect = YAHOO.util.Connect,
50 function createTreePanel(treeData, params) {
51 var tree = new YAHOO.widget.TreeView(params.id);
52 var root = tree.getRoot();
53 addChildNodes(root, treeData);
58 function addChildNodes(parentNode, parentData) {
59 var nodes = parentData.nodes || parentData.children;
61 if (typeof(nodes[i]) == 'object') {
62 nodes[i].data.href = 'javascript:void(0);';
63 var node = new YAHOO.widget.TextNode(nodes[i].data, parentNode)
64 node.action = nodes[i].data.action;
65 if (typeof(nodes[i].nodes) == 'object') {
66 addChildNodes(node, nodes[i]);
72 if (typeof(ModuleBuilder) == 'undefined') {
75 //Check if we shoudln't be in studio and need to load the normal ajaxUI
76 var aRegex = /#.*ajaxUILoc=([^&]*)/.exec(window.location);
77 var ajaxLoc = aRegex ? aRegex[1] : false;
79 window.location = "index.php?action=ajaxui#ajaxUILoc=" + ajaxLoc;
82 //Setup the basic ajax request settings
83 Connect.extraParams = {
86 Connect.url = 'index.php?to_pdf=1&sugar_body_only=1';
87 Connect.method = 'POST';
88 Connect.timeout = 300000;
90 //Setup and read cookie settings
91 //Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
93 if (SUGAR.themes.tempHideLeftCol)
94 SUGAR.themes.tempHideLeftCol();
96 var Ck = YAHOO.util.Cookie;
98 //Setup the main layout
99 var tp = ModuleBuilder.tabPanel = new YAHOO.widget.TabView("mbtabs");
100 tp.addTab(new YAHOO.widget.Tab({
101 label: SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_MAIN'),
103 content : "<div> </div>",
108 var viewHeight = document.documentElement ? document.documentElement.clientHeight : self.innerHeight;
109 var mp = ModuleBuilder.mainPanel = new YAHOO.widget.Layout('mblayout', {
111 height: viewHeight - (document.getElementById('header').clientHeight ) - 40,
114 units: [//ModuleBuilder.tree, ModuleBuilder.tabPanel,
127 body : "<div id='mbTree'/>"
130 header: SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_HELP'),
139 header: SUGAR.util.getAndRemove("footerHTML").innerHTML,
148 ModuleBuilder.nextYear = new Date();
149 ModuleBuilder.nextYear.setDate(ModuleBuilder.nextYear.getDate() + 360);
151 var nextyear = ModuleBuilder.nextYear;
153 if (Ck.getSub("ModuleBuilder", "helpHidden") == "true") {
154 mp.getUnitByPosition('right').collapse();
156 if (Ck.getSub("ModuleBuilder", "treeHidden") == "true") {
157 mp.getUnitByPosition('left').collapse();
160 var centerEl = mp.getUnitByPosition('center').get('wrap');
161 tp.appendTo(centerEl);
163 //YUI does not take the resizers into account when calculating panel size.
164 var correctW = function(){
165 var w = (this.body.offsetWidth - 7) + "px";
166 this.body.style.width = w;
167 this.header.style.width = w;
168 if (typeof Studio2 != "undefined")
169 Studio2.resizeDivs();
170 if (typeof resizeDDLists == "function")
173 mp.getUnitByPosition('right').on("resize", correctW);
174 mp.getUnitByPosition('right').on("collapse", function(){
175 Ck.setSub("ModuleBuilder", "helpHidden", "true");
176 mp.get("element").querySelector(".yui-layout-clip-right .collapse").id = "expand_help";
178 mp.getUnitByPosition('right').on("expand", function(){
179 Ck.setSub("ModuleBuilder", "helpHidden", "false");
181 mp.getUnitByPosition('left').on("resize", correctW);
182 mp.getUnitByPosition('left').on("collapse", function(){
183 Ck.setSub("ModuleBuilder", "treeHidden", "true");
184 mp.get("element").querySelector(".yui-layout-clip-left .collapse").id = "expand_tree";
186 mp.getUnitByPosition('left').on("expand", function(){
187 Ck.setSub("ModuleBuilder", "treeHidden", "false");
190 Event.on(window, 'resize', ModuleBuilder.autoSetLayout, this, true);
192 var tree = ModuleBuilder.tree = createTreePanel(TREE_DATA, {
195 tree.setCollapseAnim("TVSlideOut");
196 tree.setExpandAnim("TVSlideIn");
197 //tree.subscribe("labelClick", ModuleBuilder.handleTreeClick);
198 tree.subscribe("clickEvent", ModuleBuilder.handleTreeClick);
201 //Setup Browser History
202 var mbContent = YAHOO.util.History.getBookmarkedState('mbContent');
204 if (ModuleBuilder.mode == 'mb') {
205 mp.getUnitByPosition('left').header.firstChild.innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_PACKAGES');
206 mbContent = mbContent ? mbContent : 'module=ModuleBuilder&action=package&package=';
208 else if (ModuleBuilder.mode == 'studio') {
209 ModuleBuilder.MBpackage = ''; // set to empty so other views can recognize that dealing with an deployed, rather than undeployed, module
210 mp.getUnitByPosition('left').header.firstChild.innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_MODULES');
211 mbContent = mbContent ? mbContent :'module=ModuleBuilder&action=wizard';
213 else if (ModuleBuilder.mode == 'dropdowns') {
214 mp.getUnitByPosition('left').header.firstChild.innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_DROPDOWNS');
215 mbContent = mbContent ? mbContent : 'module=ModuleBuilder&action=dropdowns';
218 mp.getUnitByPosition('left').collapse(false);
219 mbContent = mbContent ? mbContent : 'module=ModuleBuilder&action=home';
222 YAHOO.util.History.register('mbContent', mbContent, ModuleBuilder.navigate);
223 YAHOO.util.History.initialize("yui-history-field", "yui-history-iframe");
224 ModuleBuilder.getContent(mbContent);
226 if (SUGAR.themes.tempHideLeftCol) SUGAR.themes.tempHideLeftCol();
227 ModuleBuilder.autoSetLayout();
229 ModuleBuilder.tabPanel.on('activeTabChange', function(e) {
230 ModuleBuilder.helpLoad( e.newValue.get("id") ) ;
233 if (Dom.get("HideHandle")){
234 if (SUGAR.themes.tempHideLeftCol){
235 SUGAR.themes.tempHideLeftCol();
238 //We need to add ID's to the collapse buttons for automated testing
239 Dom.getElementsByClassName("collapse", "div", mp.getUnitByPosition('left').header)[0].id = "collapse_tree";
240 Dom.getElementsByClassName("collapse", "div", mp.getUnitByPosition('right').header)[0].id = "collapse_help";
243 //Empty layout manager
247 ModuleBuilder.layoutValidation.popup_window = new YAHOO.widget.SimpleDialog("emptyLayout", {
250 constraintoviewport: true,
253 text: SUGAR.language.get('ModuleBuilder', 'ERROR_MINIMUM_FIELDS'),
254 bodyStyle: "padding:5px",
256 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_CLOSE'),
259 ModuleBuilder.layoutValidation.popup_window.hide()
263 ModuleBuilder.layoutValidation.popup_window.render(document.body);
264 ModuleBuilder.layoutValidation.popup_window.show();
267 //Layout history manager
272 browse: function(module, layout, subpanel){
273 subpanel = subpanel ? subpanel : "";
274 if (!module && ModuleBuilder.module != "undefined") {
275 module = ModuleBuilder.module;
277 if (!ModuleBuilder.history.popup_window) {
278 ModuleBuilder.history.popup_window = new YAHOO.SUGAR.AsyncPanel('histWindow', {
282 constraintoviewport: true,
286 var module_str = module;
287 if(typeof SUGAR.language.languages['app_list_strings']['moduleList'][module] != 'undefined'){
288 module_str = SUGAR.language.languages['app_list_strings']['moduleList'][module];
290 ModuleBuilder.history.popup_window.setHeader( module_str + ' : ' + SUGAR.language.get('ModuleBuilder', 'LBL_' + layout.toUpperCase()) + SUGAR.language.get('ModuleBuilder', 'LBL_HISTORY_TITLE'));
291 ModuleBuilder.history.popup_window.setBody("test");
292 ModuleBuilder.history.popup_window.render(document.body);
293 ModuleBuilder.history.params = {
294 module: 'ModuleBuilder',
295 histAction: 'browse',
297 view_package: ModuleBuilder.MBpackage,
302 ModuleBuilder.history.popup_window.load(ModuleBuilder.paramsToUrl(ModuleBuilder.history.params));
303 ModuleBuilder.history.popup_window.show();
304 ModuleBuilder.history.popup_window.center();
306 preview: function(module, layout, id, subpanel) {
307 var prevPanel = ModuleBuilder.findTabById('preview:' + id);
309 ModuleBuilder.history.params = {
310 module: 'ModuleBuilder',
311 histAction: 'preview',
313 view_package: ModuleBuilder.MBpackage,
319 prevPanel = new YAHOO.SUGAR.ClosableTab({
320 dataSrc: Connect.url + "&" + ModuleBuilder.paramsToUrl(ModuleBuilder.history.params),
321 label: SUGAR.language.get("ModuleBuilder", "LBL_MB_PREVIEW"),
326 }, ModuleBuilder.tabPanel);
327 prevPanel.closable = true;
328 ModuleBuilder.tabPanel.addTab(prevPanel);
330 ModuleBuilder.tabPanel.set("activeTab", prevPanel);
334 revert: function(module, layout, id, subpanel){
335 var prevTab = ModuleBuilder.tabPanel.getTabIndex("preview:" + id);
336 if(prevTab) ModuleBuilder.tabPanel.removeTab(prevTab);
338 ModuleBuilder.history.params = {
339 module: 'ModuleBuilder',
340 histAction: 'restore',
342 view_package: ModuleBuilder.MBpackage,
348 ModuleBuilder.asyncRequest(ModuleBuilder.history.params, function(){
349 ModuleBuilder.history.reverted = true;
350 ModuleBuilder.getContent(ModuleBuilder.contentURL);
351 ModuleBuilder.state.isDirty = true;
354 cleanup: function() {
355 if (ModuleBuilder.history.reverted && ModuleBuilder.history.params.histAction) {
356 ModuleBuilder.history.params.histAction = 'unrestore';
357 ModuleBuilder.asyncRequest({params: ModuleBuilder.history.params});
359 ModuleBuilder.history.params = { };
360 ModuleBuilder.history.reverted = false;
363 if (ModuleBuilder.history.popup_window && ModuleBuilder.history.popup_window.cfg.getProperty("visible")) {
364 var historyButton = YAHOO.util.Dom.get('historyBtn');
366 historyButton.onclick();
368 ModuleBuilder.history.popup_window.hide();
376 hideFailedMesage: false,
385 save_url_for_current_view: null,
387 setupState: function(){
388 //ModuleBuilder.state.popup();
389 document.body.setAttribute("onclose", "ModuleBuilder.state.popup(); ModuleBuilder.state.popup_window.show()");
392 onSaveClick: function(){
394 //call the save method of the current view.
395 //call the intended action.
396 ModuleBuilder.state.isDirty = false;
397 var saveBtn = document.getElementById("saveBtn");
399 var mbForm = document.forms[1];
401 var mbButtons = mbForm.getElementsByTagName("input");
403 for (var button = 0; button < mbButtons.length; button++) {
404 var name = mbButtons[button].getAttribute("name");
405 if (name && (name.toUpperCase() == "SAVEBTN" || name.toUpperCase() == "LSAVEBTN")) {
406 saveBtn = mbButtons[button];
412 alert("Could not find the save action for this view.");
416 //After the save call completes, load the next page
417 ModuleBuilder.state.saving = true;
418 eval(saveBtn.getAttributeNode('onclick').value);
420 ModuleBuilder.state.popup_window.hide();
422 onDontSaveClick: function(){
424 //call the intended action.
425 ModuleBuilder.state.isDirty = false;
426 ModuleBuilder.history.cleanup();
427 ModuleBuilder.getContent(ModuleBuilder.state.intended_view.url, ModuleBuilder.state.intended_view.successCall);
428 ModuleBuilder.state.popup_window.hide();
430 loadOnSaveComplete: function() {
431 ModuleBuilder.state.saving = false;
432 ModuleBuilder.getContent(ModuleBuilder.state.intended_view.url, ModuleBuilder.state.intended_view.successCall);
435 ModuleBuilder.state.popup_window = new YAHOO.widget.SimpleDialog("confirmUnsaved", {
438 constraintoviewport: true,
441 text: SUGAR.language.get('ModuleBuilder', 'LBL_CONFIRM_DONT_SAVE'),
442 bodyStyle: "padding:5px",
444 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_DONT_SAVE'),
445 handler: ModuleBuilder.state.onDontSaveClick
447 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_CANCEL'),
450 ModuleBuilder.state.popup_window.hide()
453 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_SAVE_CHANGES'),
454 handler: ModuleBuilder.state.onSaveClick
457 ModuleBuilder.state.popup_window.setHeader(SUGAR.language.get('ModuleBuilder', 'LBL_CONFIRM_DONT_SAVE_TITLE'));
458 if(ModuleBuilder.disablePopupPrompt != 1){
459 ModuleBuilder.state.popup_window.render(document.body);
461 ModuleBuilder.state.onDontSaveClick();
465 copyFromView: function(module, layout){
466 var url = ModuleBuilder.contentURL;
467 ModuleBuilder.getContent(url+"©FromEditView=true");
468 ModuleBuilder.contentURL = url;
469 ModuleBuilder.state.intended_view.url = url;
470 ModuleBuilder.state.isDirty = true;
472 //AJAX Navigation Functions
473 navigate : function(url) {
474 //Check if we are just registering the url
475 if (url != ModuleBuilder.contentURL) {
476 ModuleBuilder.getContent(url);
479 getContent: function(url, successCall){
482 if (url.substring(0, 11) == "javascript:")
484 eval(url.substring(11));
488 //save a pointer to intended action
489 ModuleBuilder.state.intended_view.url = url;
490 ModuleBuilder.state.intended_view.successCall = successCall;
491 if(ModuleBuilder.state.isDirty){ //prompt to save current data.
492 //check if we are editing a property of the current view (such views open up in new tabs)
493 //if so we leave the state dirty and return
494 temp_url = url.toLowerCase();
495 if(null == temp_url.match(/&action=editproperty/)){
496 ModuleBuilder.state.popup();
497 ModuleBuilder.state.popup_window.show();
502 ModuleBuilder.state.current_view.url = url;
503 ModuleBuilder.state.current_view.successCall = successCall;
506 ModuleBuilder.contentURL = url;
507 if (typeof(successCall) != 'function') {
508 if (ModuleBuilder.callInProgress)
510 ModuleBuilder.callInProgress = true;
511 successCall = ModuleBuilder.updateContent;
513 ModuleBuilder.asyncRequest(url, successCall);
515 updateContent: function(o){
516 ModuleBuilder.callInProgress = false;
517 //Check if a save action was called and now we need to move-on
518 if (ModuleBuilder.state.saving) {
519 ModuleBuilder.state.loadOnSaveComplete();
522 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
523 if(ModuleBuilder.checkForErrors(o))
527 var ajaxResponse = YAHOO.lang.JSON.parse((o.responseText));
529 YAHOO.SUGAR.MessageBox.show({
530 title: SUGAR.language.get('ModuleBuilder', 'ERROR_GENERIC_TITLE'),
538 if (ajaxResponse.tpl){
539 var t = new YAHOO.SUGAR.Template(ajaxResponse.tpl);
540 ModuleBuilder.ajaxData = ajaxResponse.data;
541 ModuleBuilder.tabPanel.getTab(0).set(t.exec(ajaxResponse.data));
542 SUGAR.util.evalScript(t.exec(ajaxResponse.data));
546 for (var maj in ajaxResponse) {
547 var name = 'mb' + maj;
548 var comp = ModuleBuilder.mainPanel.getUnitById(maj);
550 var tabs = ModuleBuilder.tabPanel.get("tabs");
552 if (tabs[i].get && tabs[i].get("id") == maj)
557 if (name == 'mbwest') { //refresh package_tree!
558 var tree = ModuleBuilder.tree;
559 var root = tree.root;
562 while (root.hasChildren()) {
563 tree.removeNode(root.children[0], true);
565 addChildNodes(root, ajaxResponse.west.content.tree_data);
571 if(ajaxResponse[maj].action == 'deactivate') continue;
572 comp = new YAHOO.SUGAR.ClosableTab({
573 content: "<div class='bodywrapper'><script>ModuleBuilder.scriptTest=true;</script>" + ((maj == 'center') ? "<div>" + ajaxResponse[maj].crumb + "</div>" :"")
574 + ajaxResponse[maj].content + "</div>",
575 label: ajaxResponse[maj].title,
580 }, ModuleBuilder.tabPanel);
581 comp.closable = true;
582 ModuleBuilder.scriptTest = false;
583 ModuleBuilder.tabPanel.set("activeTab", comp);
584 ModuleBuilder.tabPanel.addTab(comp);
585 //Text if the browser automatically evaluated the content's script tags or not. If not, manually evaluate them.
586 if (!ModuleBuilder.scriptTest)
587 SUGAR.util.evalScript(ajaxResponse[maj].content);
589 //Store Center pane changes in browser history
590 YAHOO.util.History.navigate('mbContent', ModuleBuilder.contentURL);
591 if (name == 'mbcenter') {
592 ModuleBuilder.closeAllTabs();
593 comp = ModuleBuilder.tabPanel.getTab(0);
595 ModuleBuilder.tabPanel.set("activeTab", comp);
596 comp.set('content', "<div class='bodywrapper'><div>" + ajaxResponse[maj].crumb + "</div>" + ajaxResponse[maj].content + "</div>");
597 if (ajaxResponse[maj].title != "no_change")
598 comp.set('label', ajaxResponse[maj].title);
599 SUGAR.util.evalScript(ajaxResponse[maj].content);
602 ModuleBuilder.history.update();
605 checkForErrors: function(o){
606 if (SUGAR.util.isLoginPage(o.responseText))
608 if (o.responseText.substr(0, 1) == "<") {
609 YAHOO.SUGAR.MessageBox.show({
610 title: SUGAR.language.get('ModuleBuilder', 'ERROR_GENERIC_TITLE'),
620 submitForm: function(formname, successCall){
621 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_LOADING'));
622 if (typeof(successCall) == 'undefined') {
623 successCall = ModuleBuilder.updateContent;
626 ModuleBuilder.callLock = true;
628 Connect.setForm(document.getElementById(formname) || document.forms[formname]);
629 Connect.asyncRequest(
632 {success: successCall, failure: ModuleBuilder.failed}
635 setMode: function(reqMode){
636 ModuleBuilder.mode = reqMode;
638 main: function(type){
639 document.location.href = 'index.php?module=ModuleBuilder&action=index&type=' + type;
642 if(!ModuleBuilder.state.hideFailedMesage){
643 ajaxStatus.flashStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_FAILED_DATA'), 2000);
647 buttonDown: function(button, name, list){
648 if (typeof(name) != 'undefined') {
649 for (i in ModuleBuilder.buttons[list]) {
650 ModuleBuilder.buttons[list][i].className = 'wizardButton';
652 ModuleBuilder.buttonSelect(name, list);
654 button.className = 'wizardButtonDown';
657 buttonOver: function(button){
658 button.className = 'button';
660 buttonOut: function(button, name, list){
661 if (typeof(name) != 'undefined') {
662 if (ModuleBuilder.buttonGetSelected(list) != name) {
663 button.className = 'wizardButton'
667 button.className = 'wizardButton'
671 buttonAdd: function(id, name, list){
672 if (typeof(ModuleBuilder.buttons[list]) == 'undefined') {
673 ModuleBuilder.buttons[list] = {};
676 ModuleBuilder.buttons[list][name] = document.getElementById(id);
679 buttonGetSelected: function(list){
680 if (typeof(ModuleBuilder.selected[list]) == 'undefined') {
683 return ModuleBuilder.selected[list];
685 buttonSelect: function(name, list){
686 ModuleBuilder.selected[list] = name;
688 buttonToForm: function(form, field, list){
689 var theField = eval('document.' + form + '.' + field);
690 theField.value = ModuleBuilder.buttonGetSelected(list);
693 getTitle: function(title, breadCrumb){
694 return "<h2>" + title + "</h2><br>" + breadCrumb;
696 closeAllTabs: function() {
697 var tabs = ModuleBuilder.tabPanel.get('tabs');
698 for (var i = tabs.length - 1; i > -1; i--) {
706 helpRegister: function(name){
707 var formname = 'document.' + name;
708 var form = eval(formname);
710 for (i = 0; i < form.elements.length; i++) {
711 if (typeof(form.elements[i].type) != 'undefined' && typeof(form.elements[i].name) != 'undefined' && form.elements[i].type != 'hidden') {
712 form.elements[i].onmouseover = function(){
713 ModuleBuilder.helpToggle(this.name)
715 form.elements[i].onmouseout = function(){
716 ModuleBuilder.helpToggle('default')
722 helpUnregisterByID: function (id){
723 var elm = document.getElementById(id);
725 elm.onmouseover = function() {};
726 elm.onmouseout = function() {};
730 helpRegisterByID: function(name, tag){
731 var parent = document.getElementById(name);
732 var children = parent.getElementsByTagName(tag);
733 for (var i = 0; i < children.length; i++) {
734 if (children[i].id != 'undefined') {
735 children[i].onmouseover = function(){
736 ModuleBuilder.helpToggle(this.id)
738 //children[i].onmouseover = function(){alert(this.id)};
739 children[i].onmouseout = function(){
740 ModuleBuilder.helpToggle('default')
745 helpSetup: function(group, def, panel){
746 if (!ModuleBuilder.panelHelp) ModuleBuilder.panelHelp = [];
748 // setup the linkage between this tab/panel and the relevant help
749 var id = ModuleBuilder.tabPanel.get("activeTab").get("id") ;
750 ModuleBuilder.panelHelp [ id ] = { lang: group , def: def } ;
752 // get the help text if required
753 if ( ! ModuleBuilder.AllHelpLang ) ModuleBuilder.AllHelpLang = SUGAR.language.get('ModuleBuilder', 'help');
756 ModuleBuilder.helpLang = ModuleBuilder.AllHelpLang[group];
757 ModuleBuilder.helpDefault = def;
760 ModuleBuilder.helpToggle('default');
762 helpLoad: function(panelId){
763 if (!ModuleBuilder.panelHelp) return;
765 if ( ! ModuleBuilder.AllHelpLang ) ModuleBuilder.AllHelpLang = SUGAR.language.get('ModuleBuilder', 'help');
767 if ( ModuleBuilder.panelHelp [ panelId ] )
769 ModuleBuilder.helpLang = ModuleBuilder.AllHelpLang[ ModuleBuilder.panelHelp [ panelId ].lang ];
770 ModuleBuilder.helpDefault = ModuleBuilder.panelHelp [ panelId ].def ;
771 ModuleBuilder.helpToggle('default');
774 helpToggle: function(name){
775 if (name == 'default')
776 name = ModuleBuilder.helpDefault;
777 if (ModuleBuilder.helpLang != null && typeof(ModuleBuilder.helpLang[name]) != 'undefined') {
778 document.getElementById('mbhelp').innerHTML = ModuleBuilder.helpLang[name];
781 handleSave: function(form, callBack){
782 if (check_form(form)) {
783 ModuleBuilder.state.isDirty=false;
784 ModuleBuilder.submitForm(form, callBack);
788 handleTreeClick: function(o) {
790 ModuleBuilder.getContent(node.data.action);
793 treeSubscribe:function(tree){
794 tree.subscribe("labelClick", ModuleBuilder.treeLabelClick);
796 treeRefresh:function(type){
797 ModuleBuilder.getContent('module=ModuleBuilder&action=ViewTree&tree=' + type);
800 addModule: function(MBpackage){
801 ModuleBuilder.getContent('module=ModuleBuilder&action=module&view_package=' + MBpackage);
803 viewModule: function(MBpackage, module){
804 ModuleBuilder.getContent('module=ModuleBuilder&action=module&view_package=' + MBpackage + '&view_module=' + module);
806 packageDelete: function(MBpackage){
807 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DELETING'));
808 if (confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_REMOVE_PACKAGE'))) {
809 ModuleBuilder.getContent('module=ModuleBuilder&action=DeletePackage&package=' + MBpackage);
810 var node = ModuleBuilder.tree.getNodeByProperty('id', 'package_tree/' + MBpackage);
811 if (node) ModuleBuilder.tree.removeNode(node, true);
814 packagePublish: function(form){
815 if (check_form(form)) {
816 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_BUILDPROGRESS'));
817 ModuleBuilder.submitForm(form, ModuleBuilder.packageBuild);
820 packageBuild: function(o){
821 //make sure no user changes were made
822 document.CreatePackage.action.value = 'BuildPackage';
823 document.CreatePackage.submit();
824 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
825 ModuleBuilder.callLock = false;
827 packageDeploy: function(form, deployed){
828 var confirmed = true;
830 confirmed = confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_DEPLOY_PACKAGE'));
832 if (confirmed && check_form(form)) {
833 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DEPLOYPROGRESS'));
834 ModuleBuilder.submitForm(form, ModuleBuilder.packageInstall);
837 packageInstall: function(o){
838 //make sure no user changes were made
839 document.CreatePackage.action.value = 'displaydeploy';
840 ModuleBuilder.callLock = false;
841 ModuleBuilder.submitForm('CreatePackage', ModuleBuilder.packageInstallCleanup);
843 packageInstallCleanup: function(o){
844 //make sure no user changes were made
845 document.CreatePackage.action.value = 'displaydeploy';
846 ModuleBuilder.callLock = false;
847 ModuleBuilder.submitForm('CreatePackage');
849 beginDeploy: function(p){
850 ModuleBuilder.asyncRequest('module=ModuleBuilder&action=DeployPackage&package=' + p, ModuleBuilder.deployComplete);
852 deployComplete: function(o){
853 var resp = o.responseText;
855 //check if the deploy completed
856 if (!resp.match(/^\s*(\s*(Table already exists : [\w_]*)(<br>)*\s*)*complete$/m))
858 //Unknown error occured, warn the user
859 alert(SUGAR.language.get("ModuleBuilder", "LBL_DEPLOY_FAILED"));
861 //Cleanup in the background
862 ModuleBuilder.asyncRequest(
863 'module=Administration&action=RebuildRelationship&silent=true',
866 ModuleBuilder.asyncRequest(
867 'module=Administration&action=RebuildDashlets&silent=true',
871 ModuleBuilder.failed = function(){};
872 ModuleBuilder.state.hideFailedMesage = true;
874 window.setTimeout("window.location.assign(window.location.href.split('#')[0])", 2000);
878 packageExport: function(form){
879 if (check_form(form)) {
880 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_BUILDPROGRESS'));
881 ModuleBuilder.submitForm(form, ModuleBuilder.packageExportProject);
884 packageExportProject: function(o){
885 //make sure no user changes were made
886 document.CreatePackage.action.value = 'ExportPackage';
887 document.CreatePackage.submit();
888 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
889 ModuleBuilder.callLock = false;
891 moduleDelete: function(MBpackage, module){
892 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DELETING'));
893 if (confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_REMOVE_MODULE'))) {
894 ModuleBuilder.getContent('module=ModuleBuilder&action=DeleteModule&package=' + MBpackage + '&view_module=' + module);
895 var node = ModuleBuilder.tree.getNodeByProperty('id', 'package_tree/' + MBpackage + '/' + module);
896 if (node) ModuleBuilder.tree.removeNode(node, true);
899 moduleViewFields: function(o){
901 ModuleBuilder.callLock = false;
903 ModuleBuilder.getContent('module=ModuleBuilder&action=modulefields&view_package=' + ModuleBuilder.MBpackage +
904 '&view_module=' + ModuleBuilder.module);
906 moduleLoadField: function(name, type){
907 if (typeof(type) == 'undefined')
909 if (typeof(formsWithFieldLogic) != 'undefined')
910 formsWithFieldLogic = 'undefined';
911 ModuleBuilder.getContent('module=ModuleBuilder&action=modulefield&view_package=' + ModuleBuilder.MBpackage +
912 '&view_module=' + ModuleBuilder.module + '&field=' + name + '&type=' + type);
914 moduleLoadLabels: function(type){
915 if (typeof(type) == 'undefined')
918 if (type == "studio") {
919 ModuleBuilder.getContent('module=ModuleBuilder&action=editLabels&view_module=' + ModuleBuilder.module);
923 ModuleBuilder.getContent('module=ModuleBuilder&action=modulelabels&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module + '&type=' + type);
926 moduleViewRelationships: function(o){
927 ModuleBuilder.callLock = false;
928 ModuleBuilder.getContent('module=ModuleBuilder&action=relationships&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module);
930 moduleLoadRelationship2: function(name, resetLabel, checkLanguage) {
931 if (resetLabel && Dom.get('rhs_label')) {
932 Dom.get('rhs_label').value = "";
934 var panel = ModuleBuilder.findTabById('relEditor');
936 panel = new YAHOO.SUGAR.ClosableTab({
937 label: SUGAR.language.get("ModuleBuilder", "LBL_RELATIONSHIP_EDIT"),
942 }, ModuleBuilder.tabPanel);
943 ModuleBuilder.tabPanel.addTab(panel);
945 ModuleBuilder.tabPanel.set("activeTab", panel);
947 var rtField = Dom.get('relationship_type_field');
948 var relType = rtField ? rtField.options[rtField.selectedIndex].value: "";
950 name = Dom.get('rel_name_id') ? Dom.get('rel_name_id').value : "";
953 module: 'ModuleBuilder',
954 action: 'relationship',
955 view_package: ModuleBuilder.MBpackage,
956 view_module: ModuleBuilder.module,
957 relationship_name: name,
958 relationship_type: relType,
959 lhs_module: Dom.get('lhs_mod_field') ? Dom.get('lhs_mod_field').value : document.forms.relform ? document.forms.relform.lhs_module.value : "",
960 rhs_module: Dom.get('rhs_mod_field') ? Dom.get('rhs_mod_field').value : "",
961 lhs_label: Dom.get('lhs_label') ? Dom.get('lhs_label').value : "",
962 rhs_label: Dom.get('rhs_label') ? Dom.get('rhs_label').value : "",
967 params['relationship_lang'] = Dom.get('relationship_lang').value;
968 params['ajaxLoad'] = '1';
970 ModuleBuilder.asyncRequest(params, function(o) {
971 ajaxStatus.hideStatus();
972 var tab = ModuleBuilder.findTabById('relEditor');
973 tab.set("content", o.responseText);
974 SUGAR.util.evalScript(o.responseText);
977 moduleDropDown: function(name, field){
978 ModuleBuilder.getContent('module=ModuleBuilder&action=dropdown&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module + '&dropdown_name=' + name + '&field=' + field);
980 moduleViewLayouts: function(o){
981 ModuleBuilder.callLock = false;
982 ModuleBuilder.getContent('module=ModuleBuilder&MB=1&action=wizard&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module);
984 findTabById : function(id) {
985 var tabs = ModuleBuilder.tabPanel.get("tabs");
986 for (var i = 0; i < tabs.length; i++) {
987 if (tabs[i].get("id") == id)
992 autoSetLayout: function(){
993 var mp = ModuleBuilder.mainPanel;
994 var c = Dom.get("mblayout");
995 mp.set("height", Dom.getViewportHeight() - Dom.getY(c) - 30);
996 mp.set("width", Dom.getViewportWidth() - 40);
998 var tabEl = ModuleBuilder.tabPanel.get("element");
999 Dom.setStyle(tabEl.firstChild.nextSibling, "overflow-y", "auto");
1000 Dom.setStyle(tabEl.firstChild.nextSibling, "height", tabEl.offsetHeight - ModuleBuilder.tabPanel.get("element").firstChild.offsetHeight - 5 + "px");
1001 //Resize editor layouts
1002 if (document.getElementById('toolbox')) Studio2.resizeDivs();
1003 if (document.getElementById('edittabs')) resizeDDLists();
1005 paramsToUrl : function (params) {
1008 url += i + "=" + params[i] + "&";
1012 asyncRequest : function(params, callback) {
1014 if (typeof params == "object") {
1015 url = ModuleBuilder.paramsToUrl(params);
1019 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE'));
1020 Connect.asyncRequest(
1022 Connect.url + '&' + url,
1023 {success: callback, failure: ModuleBuilder.failed}
1026 refreshGlobalDropDown: function(o){
1027 // just clear the callLock; the convention is that this is done in a handler rather than in updateContent
1028 ModuleBuilder.callLock = false;
1029 ModuleBuilder.updateContent(o);
1031 refreshDropDown: function(){
1032 ModuleBuilder.callLock = false;
1033 document.popup_form.action.value = 'RefreshField';
1034 document.popup_form.new_dropdown.value = ModuleBuilder.refreshDD_name;
1035 SimpleList.refreshDD_name = '';
1036 ModuleBuilder.submitForm("popup_form");
1038 dropdownChanged: function(value){
1039 var select = document.getElementById('default[]').options;
1040 while(select.length > 0) {
1043 ModuleBuilder.asyncRequest(
1044 'module=ModuleBuilder&action=get_app_list_string&key=' + value +
1045 '&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module,
1046 ModuleBuilder.dropdownChangedCallback
1049 dropdownChangedCallback : function(o) {
1050 var ajaxResponse = YAHOO.lang.JSON.parse(o.responseText);
1051 var select = document.getElementById('default[]').options;
1053 for (var key in ajaxResponse) {
1054 select[count] = new Option(ajaxResponse[key], key);
1057 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
1059 setSelectedOption : function (sel, option)
1061 var sel = Dom.get(sel);
1062 for (var i = 0; i < sel.options.length; i++)
1064 if(sel.options[i].value == option) {
1065 sel.selectedIndex = i;
1072 ModuleBuilder.buttons = {};
1073 ModuleBuilder.selected = {};
1074 ModuleBuilder.callLock = false;