1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2012 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 if(false == YAHOO.lang.isObject(ModuleBuilder.state.popup_window) || ModuleBuilder.state.popup_window.id != 'confirmUnsaved'){
436 ModuleBuilder.state.popup_window = new YAHOO.widget.SimpleDialog("confirmUnsaved", {
439 constraintoviewport: true,
442 text: SUGAR.language.get('ModuleBuilder', 'LBL_CONFIRM_DONT_SAVE'),
443 bodyStyle: "padding:5px",
445 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_DONT_SAVE'),
446 handler: ModuleBuilder.state.onDontSaveClick
448 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_CANCEL'),
451 ModuleBuilder.state.popup_window.hide()
454 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_SAVE_CHANGES'),
455 handler: ModuleBuilder.state.onSaveClick
458 ModuleBuilder.state.popup_window.setHeader(SUGAR.language.get('ModuleBuilder', 'LBL_CONFIRM_DONT_SAVE_TITLE'));
460 if(ModuleBuilder.disablePopupPrompt != 1){
461 ModuleBuilder.state.popup_window.render(document.body);
463 ModuleBuilder.state.onDontSaveClick();
467 copyFromView: function(module, layout){
468 var url = ModuleBuilder.contentURL;
469 ModuleBuilder.getContent(url+"©FromEditView=true");
470 ModuleBuilder.contentURL = url;
471 ModuleBuilder.state.intended_view.url = url;
472 ModuleBuilder.state.isDirty = true;
474 //AJAX Navigation Functions
475 navigate : function(url) {
476 //Check if we are just registering the url
477 if (url != ModuleBuilder.contentURL) {
478 ModuleBuilder.getContent(url);
481 getContent: function(url, successCall){
484 if (url.substring(0, 11) == "javascript:")
486 eval(url.substring(11));
490 //save a pointer to intended action
491 ModuleBuilder.state.intended_view.url = url;
492 ModuleBuilder.state.intended_view.successCall = successCall;
493 if(ModuleBuilder.state.isDirty){ //prompt to save current data.
494 //check if we are editing a property of the current view (such views open up in new tabs)
495 //if so we leave the state dirty and return
496 temp_url = url.toLowerCase();
497 if(null == temp_url.match(/&action=editproperty/)){
498 ModuleBuilder.state.popup();
499 ModuleBuilder.state.popup_window.show();
504 ModuleBuilder.state.current_view.url = url;
505 ModuleBuilder.state.current_view.successCall = successCall;
508 ModuleBuilder.contentURL = url;
509 if (typeof(successCall) != 'function') {
510 if (ModuleBuilder.callInProgress)
512 ModuleBuilder.callInProgress = true;
513 successCall = ModuleBuilder.updateContent;
515 ModuleBuilder.asyncRequest(url, successCall);
517 updateContent: function(o){
518 ModuleBuilder.callInProgress = false;
519 //Check if a save action was called and now we need to move-on
520 if (ModuleBuilder.state.saving) {
521 ModuleBuilder.state.loadOnSaveComplete();
524 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
525 if(ModuleBuilder.checkForErrors(o))
529 var ajaxResponse = YAHOO.lang.JSON.parse((o.responseText));
531 YAHOO.SUGAR.MessageBox.show({
532 title: SUGAR.language.get('ModuleBuilder', 'ERROR_GENERIC_TITLE'),
540 if (ajaxResponse.tpl){
541 var t = new YAHOO.SUGAR.Template(ajaxResponse.tpl);
542 ModuleBuilder.ajaxData = ajaxResponse.data;
543 ModuleBuilder.tabPanel.getTab(0).set(t.exec(ajaxResponse.data));
544 SUGAR.util.evalScript(t.exec(ajaxResponse.data));
548 for (var maj in ajaxResponse) {
549 var name = 'mb' + maj;
550 var comp = ModuleBuilder.mainPanel.getUnitById(maj);
552 var tabs = ModuleBuilder.tabPanel.get("tabs");
554 if (tabs[i].get && tabs[i].get("id") == maj)
559 if (name == 'mbwest') { //refresh package_tree!
560 var tree = ModuleBuilder.tree;
561 var root = tree.root;
564 while (root.hasChildren()) {
565 tree.removeNode(root.children[0], true);
567 addChildNodes(root, ajaxResponse.west.content.tree_data);
573 if(ajaxResponse[maj].action == 'deactivate') continue;
574 comp = new YAHOO.SUGAR.ClosableTab({
575 content: "<div class='bodywrapper'><script>ModuleBuilder.scriptTest=true;</script>" + ((maj == 'center') ? "<div>" + ajaxResponse[maj].crumb + "</div>" :"")
576 + ajaxResponse[maj].content + "</div>",
577 label: ajaxResponse[maj].title,
582 }, ModuleBuilder.tabPanel);
583 comp.closable = true;
584 ModuleBuilder.scriptTest = false;
585 ModuleBuilder.tabPanel.set("activeTab", comp);
586 ModuleBuilder.tabPanel.addTab(comp);
587 //Text if the browser automatically evaluated the content's script tags or not. If not, manually evaluate them.
588 if (!ModuleBuilder.scriptTest)
589 SUGAR.util.evalScript(ajaxResponse[maj].content);
591 //Store Center pane changes in browser history
592 YAHOO.util.History.navigate('mbContent', ModuleBuilder.contentURL);
593 if (name == 'mbcenter') {
594 ModuleBuilder.closeAllTabs();
595 comp = ModuleBuilder.tabPanel.getTab(0);
597 ModuleBuilder.tabPanel.set("activeTab", comp);
598 comp.set('content', "<div class='bodywrapper'><div>" + ajaxResponse[maj].crumb + "</div>" + ajaxResponse[maj].content + "</div>");
599 if (ajaxResponse[maj].title != "no_change")
600 comp.set('label', ajaxResponse[maj].title);
601 SUGAR.util.evalScript(ajaxResponse[maj].content);
604 ModuleBuilder.history.update();
607 checkForErrors: function(o){
608 if (SUGAR.util.isLoginPage(o.responseText))
610 if (o.responseText.substr(0, 1) == "<") {
611 YAHOO.SUGAR.MessageBox.show({
612 title: SUGAR.language.get('ModuleBuilder', 'ERROR_GENERIC_TITLE'),
622 submitForm: function(formname, successCall){
623 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_LOADING'));
624 if (typeof(successCall) == 'undefined') {
625 successCall = ModuleBuilder.updateContent;
628 ModuleBuilder.callLock = true;
630 Connect.setForm(document.getElementById(formname) || document.forms[formname]);
631 Connect.asyncRequest(
634 {success: successCall, failure: ModuleBuilder.failed}
637 setMode: function(reqMode){
638 ModuleBuilder.mode = reqMode;
640 main: function(type){
641 document.location.href = 'index.php?module=ModuleBuilder&action=index&type=' + type;
644 if(!ModuleBuilder.state.hideFailedMesage){
645 ajaxStatus.flashStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_FAILED_DATA'), 2000);
649 buttonDown: function(button, name, list){
650 if (typeof(name) != 'undefined') {
651 for (i in ModuleBuilder.buttons[list]) {
652 ModuleBuilder.buttons[list][i].className = 'wizardButton';
654 ModuleBuilder.buttonSelect(name, list);
656 button.className = 'wizardButtonDown';
659 buttonOver: function(button){
660 button.className = 'button';
662 buttonOut: function(button, name, list){
663 if (typeof(name) != 'undefined') {
664 if (ModuleBuilder.buttonGetSelected(list) != name) {
665 button.className = 'wizardButton'
669 button.className = 'wizardButton'
673 buttonAdd: function(id, name, list){
674 if (typeof(ModuleBuilder.buttons[list]) == 'undefined') {
675 ModuleBuilder.buttons[list] = {};
678 ModuleBuilder.buttons[list][name] = document.getElementById(id);
681 buttonGetSelected: function(list){
682 if (typeof(ModuleBuilder.selected[list]) == 'undefined') {
685 return ModuleBuilder.selected[list];
687 buttonSelect: function(name, list){
688 ModuleBuilder.selected[list] = name;
690 buttonToForm: function(form, field, list){
691 var theField = eval('document.' + form + '.' + field);
692 theField.value = ModuleBuilder.buttonGetSelected(list);
695 getTitle: function(title, breadCrumb){
696 return "<h2>" + title + "</h2><br>" + breadCrumb;
698 closeAllTabs: function() {
699 var tabs = ModuleBuilder.tabPanel.get('tabs');
700 for (var i = tabs.length - 1; i > -1; i--) {
708 helpRegister: function(name){
709 var formname = 'document.' + name;
710 var form = eval(formname);
712 for (i = 0; i < form.elements.length; i++) {
713 if (typeof(form.elements[i].type) != 'undefined' && typeof(form.elements[i].name) != 'undefined' && form.elements[i].type != 'hidden') {
714 form.elements[i].onmouseover = function(){
715 ModuleBuilder.helpToggle(this.name)
717 form.elements[i].onmouseout = function(){
718 ModuleBuilder.helpToggle('default')
724 helpUnregisterByID: function (id){
725 var elm = document.getElementById(id);
727 elm.onmouseover = function() {};
728 elm.onmouseout = function() {};
732 helpRegisterByID: function(name, tag){
733 var parent = document.getElementById(name);
734 var children = parent.getElementsByTagName(tag);
735 for (var i = 0; i < children.length; i++) {
736 if (children[i].id != 'undefined') {
737 children[i].onmouseover = function(){
738 ModuleBuilder.helpToggle(this.id)
740 //children[i].onmouseover = function(){alert(this.id)};
741 children[i].onmouseout = function(){
742 ModuleBuilder.helpToggle('default')
747 helpSetup: function(group, def, panel){
748 if (!ModuleBuilder.panelHelp) ModuleBuilder.panelHelp = [];
750 // setup the linkage between this tab/panel and the relevant help
751 var id = ModuleBuilder.tabPanel.get("activeTab").get("id") ;
752 ModuleBuilder.panelHelp [ id ] = { lang: group , def: def } ;
754 // get the help text if required
755 if ( ! ModuleBuilder.AllHelpLang ) ModuleBuilder.AllHelpLang = SUGAR.language.get('ModuleBuilder', 'help');
758 ModuleBuilder.helpLang = ModuleBuilder.AllHelpLang[group];
759 ModuleBuilder.helpDefault = def;
762 ModuleBuilder.helpToggle('default');
764 helpLoad: function(panelId){
765 if (!ModuleBuilder.panelHelp) return;
767 if ( ! ModuleBuilder.AllHelpLang ) ModuleBuilder.AllHelpLang = SUGAR.language.get('ModuleBuilder', 'help');
769 if ( ModuleBuilder.panelHelp [ panelId ] )
771 ModuleBuilder.helpLang = ModuleBuilder.AllHelpLang[ ModuleBuilder.panelHelp [ panelId ].lang ];
772 ModuleBuilder.helpDefault = ModuleBuilder.panelHelp [ panelId ].def ;
773 ModuleBuilder.helpToggle('default');
776 helpToggle: function(name){
777 if (name == 'default')
778 name = ModuleBuilder.helpDefault;
779 if (ModuleBuilder.helpLang != null && typeof(ModuleBuilder.helpLang[name]) != 'undefined') {
780 document.getElementById('mbhelp').innerHTML = ModuleBuilder.helpLang[name];
783 handleSave: function(form, callBack){
784 if (check_form(form)) {
785 ModuleBuilder.state.isDirty=false;
786 ModuleBuilder.submitForm(form, callBack);
790 handleTreeClick: function(o) {
792 ModuleBuilder.getContent(node.data.action);
795 treeSubscribe:function(tree){
796 tree.subscribe("labelClick", ModuleBuilder.treeLabelClick);
798 treeRefresh:function(type){
799 ModuleBuilder.getContent('module=ModuleBuilder&action=ViewTree&tree=' + type);
802 addModule: function(MBpackage){
803 ModuleBuilder.getContent('module=ModuleBuilder&action=module&view_package=' + MBpackage);
805 viewModule: function(MBpackage, module){
806 ModuleBuilder.getContent('module=ModuleBuilder&action=module&view_package=' + MBpackage + '&view_module=' + module);
808 packageDelete: function(MBpackage){
809 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DELETING'));
810 if (confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_REMOVE_PACKAGE'))) {
811 ModuleBuilder.getContent('module=ModuleBuilder&action=DeletePackage&package=' + MBpackage);
812 var node = ModuleBuilder.tree.getNodeByProperty('id', 'package_tree/' + MBpackage);
813 if (node) ModuleBuilder.tree.removeNode(node, true);
816 packagePublish: function(form){
817 if (check_form(form)) {
818 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_BUILDPROGRESS'));
819 ModuleBuilder.submitForm(form, ModuleBuilder.packageBuild);
822 packageBuild: function(o){
823 //make sure no user changes were made
824 document.CreatePackage.action.value = 'BuildPackage';
825 document.CreatePackage.submit();
826 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
827 ModuleBuilder.callLock = false;
829 packageDeploy: function(form, deployed){
830 var confirmed = true;
832 confirmed = confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_DEPLOY_PACKAGE'));
834 if (confirmed && check_form(form)) {
835 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DEPLOYPROGRESS'));
836 ModuleBuilder.submitForm(form, ModuleBuilder.packageInstall);
839 packageInstall: function(o){
840 //make sure no user changes were made
841 document.CreatePackage.action.value = 'displaydeploy';
842 ModuleBuilder.callLock = false;
843 ModuleBuilder.submitForm('CreatePackage', ModuleBuilder.packageInstallCleanup);
845 packageInstallCleanup: function(o){
846 //make sure no user changes were made
847 document.CreatePackage.action.value = 'displaydeploy';
848 ModuleBuilder.callLock = false;
849 ModuleBuilder.submitForm('CreatePackage');
851 beginDeploy: function(p){
852 ModuleBuilder.asyncRequest('module=ModuleBuilder&action=DeployPackage&package=' + p, ModuleBuilder.deployComplete);
854 deployComplete: function(o){
855 var resp = o.responseText;
857 //check if the deploy completed
858 if (!resp.match(/^\s*(\s*(Table already exists : [\w_]*)(<br>)*\s*)*complete$/m))
860 //Unknown error occured, warn the user
861 alert(SUGAR.language.get("ModuleBuilder", "LBL_DEPLOY_FAILED"));
863 //Cleanup in the background
864 ModuleBuilder.asyncRequest(
865 'module=Administration&action=RebuildRelationship&silent=true',
868 ModuleBuilder.asyncRequest(
869 'module=Administration&action=RebuildDashlets&silent=true',
873 ModuleBuilder.failed = function(){};
874 ModuleBuilder.state.hideFailedMesage = true;
876 window.setTimeout("window.location.assign(window.location.href.split('#')[0])", 2000);
880 packageExport: function(form){
881 if (check_form(form)) {
882 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_BUILDPROGRESS'));
883 ModuleBuilder.submitForm(form, ModuleBuilder.packageExportProject);
886 packageExportProject: function(o){
887 //make sure no user changes were made
888 document.CreatePackage.action.value = 'ExportPackage';
889 document.CreatePackage.submit();
890 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
891 ModuleBuilder.callLock = false;
893 moduleDelete: function(MBpackage, module){
894 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DELETING'));
895 if (confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_REMOVE_MODULE'))) {
896 ModuleBuilder.getContent('module=ModuleBuilder&action=DeleteModule&package=' + MBpackage + '&view_module=' + module);
897 var node = ModuleBuilder.tree.getNodeByProperty('id', 'package_tree/' + MBpackage + '/' + module);
898 if (node) ModuleBuilder.tree.removeNode(node, true);
901 moduleViewFields: function(o){
903 ModuleBuilder.callLock = false;
905 ModuleBuilder.getContent('module=ModuleBuilder&action=modulefields&view_package=' + ModuleBuilder.MBpackage +
906 '&view_module=' + ModuleBuilder.module);
908 moduleLoadField: function(name, type){
909 if (typeof(type) == 'undefined')
911 if (typeof(formsWithFieldLogic) != 'undefined')
912 formsWithFieldLogic = 'undefined';
913 ModuleBuilder.getContent('module=ModuleBuilder&action=modulefield&view_package=' + ModuleBuilder.MBpackage +
914 '&view_module=' + ModuleBuilder.module + '&field=' + name + '&type=' + type);
916 moduleLoadLabels: function(type){
917 if (typeof(type) == 'undefined')
920 if (type == "studio") {
921 ModuleBuilder.getContent('module=ModuleBuilder&action=editLabels&view_module=' + ModuleBuilder.module);
925 ModuleBuilder.getContent('module=ModuleBuilder&action=modulelabels&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module + '&type=' + type);
928 moduleViewRelationships: function(o){
929 ModuleBuilder.callLock = false;
930 ModuleBuilder.getContent('module=ModuleBuilder&action=relationships&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module);
932 moduleLoadRelationship2: function(name, resetLabel, checkLanguage) {
933 if (resetLabel && Dom.get('rhs_label')) {
934 Dom.get('rhs_label').value = "";
936 var panel = ModuleBuilder.findTabById('relEditor');
938 panel = new YAHOO.SUGAR.ClosableTab({
939 label: SUGAR.language.get("ModuleBuilder", "LBL_RELATIONSHIP_EDIT"),
944 }, ModuleBuilder.tabPanel);
945 ModuleBuilder.tabPanel.addTab(panel);
947 ModuleBuilder.tabPanel.set("activeTab", panel);
949 var rtField = Dom.get('relationship_type_field');
950 var relType = rtField ? rtField.options[rtField.selectedIndex].value: "";
952 name = Dom.get('rel_name_id') ? Dom.get('rel_name_id').value : "";
955 module: 'ModuleBuilder',
956 action: 'relationship',
957 view_package: ModuleBuilder.MBpackage,
958 view_module: ModuleBuilder.module,
959 relationship_name: name,
960 relationship_type: relType,
961 lhs_module: Dom.get('lhs_mod_field') ? Dom.get('lhs_mod_field').value : document.forms.relform ? document.forms.relform.lhs_module.value : "",
962 rhs_module: Dom.get('rhs_mod_field') ? Dom.get('rhs_mod_field').value : "",
963 lhs_label: Dom.get('lhs_label') ? Dom.get('lhs_label').value : "",
964 rhs_label: Dom.get('rhs_label') ? Dom.get('rhs_label').value : "",
969 params['relationship_lang'] = Dom.get('relationship_lang').value;
970 params['ajaxLoad'] = '1';
972 ModuleBuilder.asyncRequest(params, function(o) {
973 ajaxStatus.hideStatus();
974 var tab = ModuleBuilder.findTabById('relEditor');
975 tab.set("content", o.responseText);
976 SUGAR.util.evalScript(o.responseText);
979 moduleDropDown: function(name, field){
980 ModuleBuilder.getContent('module=ModuleBuilder&action=dropdown&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module + '&dropdown_name=' + name + '&field=' + field);
982 moduleViewLayouts: function(o){
983 ModuleBuilder.callLock = false;
984 ModuleBuilder.getContent('module=ModuleBuilder&MB=1&action=wizard&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module);
986 findTabById : function(id) {
987 var tabs = ModuleBuilder.tabPanel.get("tabs");
988 for (var i = 0; i < tabs.length; i++) {
989 if (tabs[i].get("id") == id)
994 autoSetLayout: function(){
995 var mp = ModuleBuilder.mainPanel;
996 var c = Dom.get("mblayout");
997 mp.set("height", Dom.getViewportHeight() - Dom.getY(c) - 30);
998 mp.set("width", Dom.getViewportWidth() - 40);
1000 var tabEl = ModuleBuilder.tabPanel.get("element");
1001 Dom.setStyle(tabEl.firstChild.nextSibling, "overflow-y", "auto");
1002 Dom.setStyle(tabEl.firstChild.nextSibling, "height", tabEl.offsetHeight - ModuleBuilder.tabPanel.get("element").firstChild.offsetHeight - 5 + "px");
1003 //Resize editor layouts
1004 if (document.getElementById('toolbox')) Studio2.resizeDivs();
1005 if (document.getElementById('edittabs')) resizeDDLists();
1007 paramsToUrl : function (params) {
1010 url += i + "=" + params[i] + "&";
1014 asyncRequest : function(params, callback) {
1016 if (typeof params == "object") {
1017 url = ModuleBuilder.paramsToUrl(params);
1021 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE'));
1022 Connect.asyncRequest(
1024 Connect.url + '&' + url,
1025 {success: callback, failure: ModuleBuilder.failed}
1028 refreshGlobalDropDown: function(o){
1029 // just clear the callLock; the convention is that this is done in a handler rather than in updateContent
1030 ModuleBuilder.callLock = false;
1031 ModuleBuilder.updateContent(o);
1033 refreshDropDown: function(){
1034 ModuleBuilder.callLock = false;
1035 document.popup_form.action.value = 'RefreshField';
1036 document.popup_form.new_dropdown.value = ModuleBuilder.refreshDD_name;
1037 SimpleList.refreshDD_name = '';
1038 ModuleBuilder.submitForm("popup_form");
1040 dropdownChanged: function(value){
1041 var select = document.getElementById('default[]').options;
1042 while(select.length > 0) {
1045 ModuleBuilder.asyncRequest(
1046 'module=ModuleBuilder&action=get_app_list_string&key=' + value +
1047 '&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module,
1048 ModuleBuilder.dropdownChangedCallback
1051 dropdownChangedCallback : function(o) {
1052 var ajaxResponse = YAHOO.lang.JSON.parse(o.responseText);
1053 var select = document.getElementById('default[]').options;
1055 for (var key in ajaxResponse) {
1056 select[count] = new Option(ajaxResponse[key], key);
1059 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
1061 setSelectedOption : function (sel, option)
1063 var sel = Dom.get(sel);
1064 for (var i = 0; i < sel.options.length; i++)
1066 if(sel.options[i].value == option) {
1067 sel.selectedIndex = i;
1074 ModuleBuilder.buttons = {};
1075 ModuleBuilder.selected = {};
1076 ModuleBuilder.callLock = false;