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 heightOffset = $('#dcmenu').length > 0 ? $('#dcmenu').height() : $('#header').height();
110 var mp = ModuleBuilder.mainPanel = new YAHOO.widget.Layout('mblayout', {
112 height: viewHeight - heightOffset - 40,
115 units: [//ModuleBuilder.tree, ModuleBuilder.tabPanel,
128 body : "<div id='mbTree'/>"
131 header: SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_HELP'),
140 header: SUGAR.util.getAndRemove("footerHTML").innerHTML,
149 ModuleBuilder.nextYear = new Date();
150 ModuleBuilder.nextYear.setDate(ModuleBuilder.nextYear.getDate() + 360);
152 var nextyear = ModuleBuilder.nextYear;
154 if (Ck.getSub("ModuleBuilder", "helpHidden") == "true") {
155 mp.getUnitByPosition('right').collapse();
157 if (Ck.getSub("ModuleBuilder", "treeHidden") == "true") {
158 mp.getUnitByPosition('left').collapse();
161 var centerEl = mp.getUnitByPosition('center').get('wrap');
162 tp.appendTo(centerEl);
164 //YUI does not take the resizers into account when calculating panel size.
165 var correctW = function(){
166 var w = (this.body.offsetWidth - 7) + "px";
167 this.body.style.width = w;
168 this.header.style.width = w;
169 if (typeof Studio2 != "undefined")
170 Studio2.resizeDivs();
171 if (typeof resizeDDLists == "function")
174 mp.getUnitByPosition('right').on("resize", correctW);
175 mp.getUnitByPosition('right').on("collapse", function(){
176 Ck.setSub("ModuleBuilder", "helpHidden", "true");
177 mp.get("element").querySelector(".yui-layout-clip-right .collapse").id = "expand_help";
179 mp.getUnitByPosition('right').on("expand", function(){
180 Ck.setSub("ModuleBuilder", "helpHidden", "false");
182 mp.getUnitByPosition('left').on("resize", correctW);
183 mp.getUnitByPosition('left').on("collapse", function(){
184 Ck.setSub("ModuleBuilder", "treeHidden", "true");
185 mp.get("element").querySelector(".yui-layout-clip-left .collapse").id = "expand_tree";
187 mp.getUnitByPosition('left').on("expand", function(){
188 Ck.setSub("ModuleBuilder", "treeHidden", "false");
191 Event.on(window, 'resize', ModuleBuilder.autoSetLayout, this, true);
193 var tree = ModuleBuilder.tree = createTreePanel(TREE_DATA, {
196 tree.setCollapseAnim("TVSlideOut");
197 tree.setExpandAnim("TVSlideIn");
198 //tree.subscribe("labelClick", ModuleBuilder.handleTreeClick);
199 tree.subscribe("clickEvent", ModuleBuilder.handleTreeClick);
202 //Setup Browser History
203 var mbContent = YAHOO.util.History.getBookmarkedState('mbContent');
205 if (ModuleBuilder.mode == 'mb') {
206 mp.getUnitByPosition('left').header.firstChild.innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_PACKAGES');
207 mbContent = mbContent ? mbContent : 'module=ModuleBuilder&action=package&package=';
209 else if (ModuleBuilder.mode == 'studio') {
210 ModuleBuilder.MBpackage = ''; // set to empty so other views can recognize that dealing with an deployed, rather than undeployed, module
211 mp.getUnitByPosition('left').header.firstChild.innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_MODULES');
212 mbContent = mbContent ? mbContent :'module=ModuleBuilder&action=wizard';
214 else if (ModuleBuilder.mode == 'dropdowns') {
215 mp.getUnitByPosition('left').header.firstChild.innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_DROPDOWNS');
216 mbContent = mbContent ? mbContent : 'module=ModuleBuilder&action=dropdowns';
219 mp.getUnitByPosition('left').collapse(false);
220 mbContent = mbContent ? mbContent : 'module=ModuleBuilder&action=home';
223 YAHOO.util.History.register('mbContent', mbContent, ModuleBuilder.navigate);
224 YAHOO.util.History.initialize("yui-history-field", "yui-history-iframe");
225 ModuleBuilder.getContent(mbContent);
227 if (SUGAR.themes.tempHideLeftCol) SUGAR.themes.tempHideLeftCol();
228 ModuleBuilder.autoSetLayout();
230 ModuleBuilder.tabPanel.on('activeTabChange', function(e) {
231 ModuleBuilder.helpLoad( e.newValue.get("id") ) ;
234 if (Dom.get("HideHandle")){
235 if (SUGAR.themes.tempHideLeftCol){
236 SUGAR.themes.tempHideLeftCol();
239 //We need to add ID's to the collapse buttons for automated testing
240 Dom.getElementsByClassName("collapse", "div", mp.getUnitByPosition('left').header)[0].id = "collapse_tree";
241 Dom.getElementsByClassName("collapse", "div", mp.getUnitByPosition('right').header)[0].id = "collapse_help";
244 //Empty layout manager
248 ModuleBuilder.layoutValidation.popup_window = new YAHOO.widget.SimpleDialog("emptyLayout", {
251 constraintoviewport: true,
254 text: SUGAR.language.get('ModuleBuilder', 'ERROR_MINIMUM_FIELDS'),
255 bodyStyle: "padding:5px",
257 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_CLOSE'),
260 ModuleBuilder.layoutValidation.popup_window.hide()
264 ModuleBuilder.layoutValidation.popup_window.render(document.body);
265 ModuleBuilder.layoutValidation.popup_window.show();
268 //Layout history manager
273 browse: function(module, layout, subpanel){
274 subpanel = subpanel ? subpanel : "";
275 if (!module && ModuleBuilder.module != "undefined") {
276 module = ModuleBuilder.module;
278 if (!ModuleBuilder.history.popup_window) {
279 ModuleBuilder.history.popup_window = new YAHOO.SUGAR.AsyncPanel('histWindow', {
283 constraintoviewport: true,
287 var module_str = module;
288 if(typeof SUGAR.language.languages['app_list_strings']['moduleList'][module] != 'undefined'){
289 module_str = SUGAR.language.languages['app_list_strings']['moduleList'][module];
291 ModuleBuilder.history.popup_window.setHeader( module_str + ' : ' + SUGAR.language.get('ModuleBuilder', 'LBL_' + layout.toUpperCase()) + SUGAR.language.get('ModuleBuilder', 'LBL_HISTORY_TITLE'));
292 ModuleBuilder.history.popup_window.setBody("test");
293 ModuleBuilder.history.popup_window.render(document.body);
294 ModuleBuilder.history.params = {
295 module: 'ModuleBuilder',
296 histAction: 'browse',
298 view_package: ModuleBuilder.MBpackage,
303 ModuleBuilder.history.popup_window.load(ModuleBuilder.paramsToUrl(ModuleBuilder.history.params));
304 ModuleBuilder.history.popup_window.show();
305 ModuleBuilder.history.popup_window.center();
307 preview: function(module, layout, id, subpanel) {
308 var prevPanel = ModuleBuilder.findTabById('preview:' + id);
310 ModuleBuilder.history.params = {
311 module: 'ModuleBuilder',
312 histAction: 'preview',
314 view_package: ModuleBuilder.MBpackage,
320 prevPanel = new YAHOO.SUGAR.ClosableTab({
321 dataSrc: Connect.url + "&" + ModuleBuilder.paramsToUrl(ModuleBuilder.history.params),
322 label: SUGAR.language.get("ModuleBuilder", "LBL_MB_PREVIEW"),
327 }, ModuleBuilder.tabPanel);
328 prevPanel.closable = true;
329 ModuleBuilder.tabPanel.addTab(prevPanel);
331 ModuleBuilder.tabPanel.set("activeTab", prevPanel);
335 revert: function(module, layout, id, subpanel){
336 var prevTab = ModuleBuilder.tabPanel.getTabIndex("preview:" + id);
337 if(prevTab) ModuleBuilder.tabPanel.removeTab(prevTab);
339 ModuleBuilder.history.params = {
340 module: 'ModuleBuilder',
341 histAction: 'restore',
343 view_package: ModuleBuilder.MBpackage,
349 ModuleBuilder.asyncRequest(ModuleBuilder.history.params, function(){
350 ModuleBuilder.history.reverted = true;
351 ModuleBuilder.getContent(ModuleBuilder.contentURL);
352 ModuleBuilder.state.isDirty = true;
355 cleanup: function() {
356 if (ModuleBuilder.history.reverted && ModuleBuilder.history.params.histAction) {
357 ModuleBuilder.history.params.histAction = 'unrestore';
358 ModuleBuilder.asyncRequest({params: ModuleBuilder.history.params});
360 ModuleBuilder.history.params = { };
361 ModuleBuilder.history.reverted = false;
364 if (ModuleBuilder.history.popup_window && ModuleBuilder.history.popup_window.cfg.getProperty("visible")) {
365 var historyButton = YAHOO.util.Dom.get('historyBtn');
367 historyButton.onclick();
369 ModuleBuilder.history.popup_window.hide();
377 hideFailedMesage: false,
386 save_url_for_current_view: null,
388 setupState: function(){
389 //ModuleBuilder.state.popup();
390 document.body.setAttribute("onclose", "ModuleBuilder.state.popup(); ModuleBuilder.state.popup_window.show()");
393 onSaveClick: function(){
395 //call the save method of the current view.
396 //call the intended action.
397 ModuleBuilder.state.isDirty = false;
398 var saveBtn = document.getElementById("saveBtn");
400 var mbForm = document.forms[1];
402 var mbButtons = mbForm.getElementsByTagName("input");
404 for (var button = 0; button < mbButtons.length; button++) {
405 var name = mbButtons[button].getAttribute("name");
406 if (name && (name.toUpperCase() == "SAVEBTN" || name.toUpperCase() == "LSAVEBTN")) {
407 saveBtn = mbButtons[button];
413 alert("Could not find the save action for this view.");
417 //After the save call completes, load the next page
418 ModuleBuilder.state.saving = true;
419 eval(saveBtn.getAttributeNode('onclick').value);
421 ModuleBuilder.state.popup_window.hide();
423 onDontSaveClick: function(){
425 //call the intended action.
426 ModuleBuilder.state.isDirty = false;
427 ModuleBuilder.history.cleanup();
428 ModuleBuilder.getContent(ModuleBuilder.state.intended_view.url, ModuleBuilder.state.intended_view.successCall);
429 ModuleBuilder.state.popup_window.hide();
431 loadOnSaveComplete: function() {
432 ModuleBuilder.state.saving = false;
433 ModuleBuilder.getContent(ModuleBuilder.state.intended_view.url, ModuleBuilder.state.intended_view.successCall);
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'));
459 if(ModuleBuilder.disablePopupPrompt != 1){
460 ModuleBuilder.state.popup_window.render(document.body);
462 ModuleBuilder.state.onDontSaveClick();
466 copyFromView: function(module, layout){
467 var url = ModuleBuilder.contentURL;
468 ModuleBuilder.getContent(url+"©FromEditView=true");
469 ModuleBuilder.contentURL = url;
470 ModuleBuilder.state.intended_view.url = url;
471 ModuleBuilder.state.isDirty = true;
473 //AJAX Navigation Functions
474 navigate : function(url) {
475 //Check if we are just registering the url
476 if (url != ModuleBuilder.contentURL) {
477 ModuleBuilder.getContent(url);
480 getContent: function(url, successCall){
483 if (url.substring(0, 11) == "javascript:")
485 eval(url.substring(11));
489 //save a pointer to intended action
490 ModuleBuilder.state.intended_view.url = url;
491 ModuleBuilder.state.intended_view.successCall = successCall;
492 if(ModuleBuilder.state.isDirty){ //prompt to save current data.
493 //check if we are editing a property of the current view (such views open up in new tabs)
494 //if so we leave the state dirty and return
495 temp_url = url.toLowerCase();
496 if(null == temp_url.match(/&action=editproperty/)){
497 ModuleBuilder.state.popup();
498 ModuleBuilder.state.popup_window.show();
503 ModuleBuilder.state.current_view.url = url;
504 ModuleBuilder.state.current_view.successCall = successCall;
507 ModuleBuilder.contentURL = url;
508 if (typeof(successCall) != 'function') {
509 if (ModuleBuilder.callInProgress)
511 ModuleBuilder.callInProgress = true;
512 successCall = ModuleBuilder.updateContent;
514 ModuleBuilder.asyncRequest(url, successCall);
516 updateContent: function(o){
517 ModuleBuilder.callInProgress = false;
518 //Check if a save action was called and now we need to move-on
519 if (ModuleBuilder.state.saving) {
520 ModuleBuilder.state.loadOnSaveComplete();
523 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
524 if(ModuleBuilder.checkForErrors(o))
528 var ajaxResponse = YAHOO.lang.JSON.parse((o.responseText));
530 YAHOO.SUGAR.MessageBox.show({
531 title: SUGAR.language.get('ModuleBuilder', 'ERROR_GENERIC_TITLE'),
539 if (ajaxResponse.tpl){
540 var t = new YAHOO.SUGAR.Template(ajaxResponse.tpl);
541 ModuleBuilder.ajaxData = ajaxResponse.data;
542 ModuleBuilder.tabPanel.getTab(0).set(t.exec(ajaxResponse.data));
543 SUGAR.util.evalScript(t.exec(ajaxResponse.data));
547 for (var maj in ajaxResponse) {
548 var name = 'mb' + maj;
549 var comp = ModuleBuilder.mainPanel.getUnitById(maj);
551 var tabs = ModuleBuilder.tabPanel.get("tabs");
553 if (tabs[i].get && tabs[i].get("id") == maj)
558 if (name == 'mbwest') { //refresh package_tree!
559 var tree = ModuleBuilder.tree;
560 var root = tree.root;
563 while (root.hasChildren()) {
564 tree.removeNode(root.children[0], true);
566 addChildNodes(root, ajaxResponse.west.content.tree_data);
572 if(ajaxResponse[maj].action == 'deactivate') continue;
573 comp = new YAHOO.SUGAR.ClosableTab({
574 content: "<div class='bodywrapper'><script>ModuleBuilder.scriptTest=true;</script>" + ((maj == 'center') ? "<div>" + ajaxResponse[maj].crumb + "</div>" :"")
575 + ajaxResponse[maj].content + "</div>",
576 label: ajaxResponse[maj].title,
581 }, ModuleBuilder.tabPanel);
582 comp.closable = true;
583 ModuleBuilder.scriptTest = false;
584 ModuleBuilder.tabPanel.set("activeTab", comp);
585 ModuleBuilder.tabPanel.addTab(comp);
586 //Text if the browser automatically evaluated the content's script tags or not. If not, manually evaluate them.
587 if (!ModuleBuilder.scriptTest)
588 SUGAR.util.evalScript(ajaxResponse[maj].content);
590 //Store Center pane changes in browser history
591 YAHOO.util.History.navigate('mbContent', ModuleBuilder.contentURL);
592 if (name == 'mbcenter') {
593 ModuleBuilder.closeAllTabs();
594 comp = ModuleBuilder.tabPanel.getTab(0);
596 ModuleBuilder.tabPanel.set("activeTab", comp);
597 comp.set('content', "<div class='bodywrapper'><div>" + ajaxResponse[maj].crumb + "</div>" + ajaxResponse[maj].content + "</div>");
598 if (ajaxResponse[maj].title != "no_change")
599 comp.set('label', ajaxResponse[maj].title);
600 SUGAR.util.evalScript(ajaxResponse[maj].content);
603 ModuleBuilder.history.update();
606 checkForErrors: function(o){
607 if (SUGAR.util.isLoginPage(o.responseText))
609 if (o.responseText.substr(0, 1) == "<") {
610 YAHOO.SUGAR.MessageBox.show({
611 title: SUGAR.language.get('ModuleBuilder', 'ERROR_GENERIC_TITLE'),
621 submitForm: function(formname, successCall){
622 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_LOADING'));
623 if (typeof(successCall) == 'undefined') {
624 successCall = ModuleBuilder.updateContent;
627 ModuleBuilder.callLock = true;
629 Connect.setForm(document.getElementById(formname) || document.forms[formname]);
630 Connect.asyncRequest(
633 {success: successCall, failure: ModuleBuilder.failed}
636 setMode: function(reqMode){
637 ModuleBuilder.mode = reqMode;
639 main: function(type){
640 document.location.href = 'index.php?module=ModuleBuilder&action=index&type=' + type;
643 if(!ModuleBuilder.state.hideFailedMesage){
644 ajaxStatus.flashStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_FAILED_DATA'), 2000);
648 buttonDown: function(button, name, list){
649 if (typeof(name) != 'undefined') {
650 for (i in ModuleBuilder.buttons[list]) {
651 ModuleBuilder.buttons[list][i].className = 'wizardButton';
653 ModuleBuilder.buttonSelect(name, list);
655 button.className = 'wizardButtonDown';
658 buttonOver: function(button){
659 button.className = 'button';
661 buttonOut: function(button, name, list){
662 if (typeof(name) != 'undefined') {
663 if (ModuleBuilder.buttonGetSelected(list) != name) {
664 button.className = 'wizardButton'
668 button.className = 'wizardButton'
672 buttonAdd: function(id, name, list){
673 if (typeof(ModuleBuilder.buttons[list]) == 'undefined') {
674 ModuleBuilder.buttons[list] = {};
677 ModuleBuilder.buttons[list][name] = document.getElementById(id);
680 buttonGetSelected: function(list){
681 if (typeof(ModuleBuilder.selected[list]) == 'undefined') {
684 return ModuleBuilder.selected[list];
686 buttonSelect: function(name, list){
687 ModuleBuilder.selected[list] = name;
689 buttonToForm: function(form, field, list){
690 var theField = eval('document.' + form + '.' + field);
691 theField.value = ModuleBuilder.buttonGetSelected(list);
694 getTitle: function(title, breadCrumb){
695 return "<h2>" + title + "</h2><br>" + breadCrumb;
697 closeAllTabs: function() {
698 var tabs = ModuleBuilder.tabPanel.get('tabs');
699 for (var i = tabs.length - 1; i > -1; i--) {
707 helpRegister: function(name){
708 var formname = 'document.' + name;
709 var form = eval(formname);
711 for (i = 0; i < form.elements.length; i++) {
712 if (typeof(form.elements[i].type) != 'undefined' && typeof(form.elements[i].name) != 'undefined' && form.elements[i].type != 'hidden') {
713 form.elements[i].onmouseover = function(){
714 ModuleBuilder.helpToggle(this.name)
716 form.elements[i].onmouseout = function(){
717 ModuleBuilder.helpToggle('default')
723 helpUnregisterByID: function (id){
724 var elm = document.getElementById(id);
726 elm.onmouseover = function() {};
727 elm.onmouseout = function() {};
731 helpRegisterByID: function(name, tag){
732 var parent = document.getElementById(name);
733 var children = parent.getElementsByTagName(tag);
734 for (var i = 0; i < children.length; i++) {
735 if (children[i].id != 'undefined') {
736 children[i].onmouseover = function(){
737 ModuleBuilder.helpToggle(this.id)
739 //children[i].onmouseover = function(){alert(this.id)};
740 children[i].onmouseout = function(){
741 ModuleBuilder.helpToggle('default')
746 helpSetup: function(group, def, panel){
747 if (!ModuleBuilder.panelHelp) ModuleBuilder.panelHelp = [];
749 // setup the linkage between this tab/panel and the relevant help
750 var id = ModuleBuilder.tabPanel.get("activeTab").get("id") ;
751 ModuleBuilder.panelHelp [ id ] = { lang: group , def: def } ;
753 // get the help text if required
754 if ( ! ModuleBuilder.AllHelpLang ) ModuleBuilder.AllHelpLang = SUGAR.language.get('ModuleBuilder', 'help');
757 ModuleBuilder.helpLang = ModuleBuilder.AllHelpLang[group];
758 ModuleBuilder.helpDefault = def;
761 ModuleBuilder.helpToggle('default');
763 helpLoad: function(panelId){
764 if (!ModuleBuilder.panelHelp) return;
766 if ( ! ModuleBuilder.AllHelpLang ) ModuleBuilder.AllHelpLang = SUGAR.language.get('ModuleBuilder', 'help');
768 if ( ModuleBuilder.panelHelp [ panelId ] )
770 ModuleBuilder.helpLang = ModuleBuilder.AllHelpLang[ ModuleBuilder.panelHelp [ panelId ].lang ];
771 ModuleBuilder.helpDefault = ModuleBuilder.panelHelp [ panelId ].def ;
772 ModuleBuilder.helpToggle('default');
775 helpToggle: function(name){
776 if (name == 'default')
777 name = ModuleBuilder.helpDefault;
778 if (ModuleBuilder.helpLang != null && typeof(ModuleBuilder.helpLang[name]) != 'undefined') {
779 document.getElementById('mbhelp').innerHTML = ModuleBuilder.helpLang[name];
782 handleSave: function(form, callBack){
783 if (check_form(form)) {
784 ModuleBuilder.state.isDirty=false;
785 ModuleBuilder.submitForm(form, callBack);
789 handleTreeClick: function(o) {
791 ModuleBuilder.getContent(node.data.action);
794 treeSubscribe:function(tree){
795 tree.subscribe("labelClick", ModuleBuilder.treeLabelClick);
797 treeRefresh:function(type){
798 ModuleBuilder.getContent('module=ModuleBuilder&action=ViewTree&tree=' + type);
801 addModule: function(MBpackage){
802 ModuleBuilder.getContent('module=ModuleBuilder&action=module&view_package=' + MBpackage);
804 viewModule: function(MBpackage, module){
805 ModuleBuilder.getContent('module=ModuleBuilder&action=module&view_package=' + MBpackage + '&view_module=' + module);
807 packageDelete: function(MBpackage){
808 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DELETING'));
809 if (confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_REMOVE_PACKAGE'))) {
810 ModuleBuilder.getContent('module=ModuleBuilder&action=DeletePackage&package=' + MBpackage);
811 var node = ModuleBuilder.tree.getNodeByProperty('id', 'package_tree/' + MBpackage);
812 if (node) ModuleBuilder.tree.removeNode(node, true);
815 packagePublish: function(form){
816 if (check_form(form)) {
817 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_BUILDPROGRESS'));
818 ModuleBuilder.submitForm(form, ModuleBuilder.packageBuild);
821 packageBuild: function(o){
822 //make sure no user changes were made
823 document.CreatePackage.action.value = 'BuildPackage';
824 document.CreatePackage.submit();
825 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
826 ModuleBuilder.callLock = false;
828 packageDeploy: function(form, deployed){
829 var confirmed = true;
831 confirmed = confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_DEPLOY_PACKAGE'));
833 if (confirmed && check_form(form)) {
834 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DEPLOYPROGRESS'));
835 ModuleBuilder.submitForm(form, ModuleBuilder.packageInstall);
838 packageInstall: function(o){
839 //make sure no user changes were made
840 document.CreatePackage.action.value = 'displaydeploy';
841 ModuleBuilder.callLock = false;
842 ModuleBuilder.submitForm('CreatePackage', ModuleBuilder.packageInstallCleanup);
844 packageInstallCleanup: function(o){
845 //make sure no user changes were made
846 document.CreatePackage.action.value = 'displaydeploy';
847 ModuleBuilder.callLock = false;
848 ModuleBuilder.submitForm('CreatePackage');
850 beginDeploy: function(p){
851 ModuleBuilder.asyncRequest('module=ModuleBuilder&action=DeployPackage&package=' + p, ModuleBuilder.deployComplete);
853 deployComplete: function(o){
854 var resp = o.responseText;
856 //check if the deploy completed
857 if (!resp.match(/^\s*(\s*(Table already exists : [\w_]*)(<br>)*\s*)*complete$/m))
859 //Unknown error occured, warn the user
860 alert(SUGAR.language.get("ModuleBuilder", "LBL_DEPLOY_FAILED"));
862 //Cleanup in the background
863 ModuleBuilder.asyncRequest(
864 'module=Administration&action=RebuildRelationship&silent=true',
867 ModuleBuilder.asyncRequest(
868 'module=Administration&action=RebuildDashlets&silent=true',
872 ModuleBuilder.failed = function(){};
873 ModuleBuilder.state.hideFailedMesage = true;
875 window.setTimeout("window.location.assign(window.location.href.split('#')[0])", 2000);
879 packageExport: function(form){
880 if (check_form(form)) {
881 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_BUILDPROGRESS'));
882 ModuleBuilder.submitForm(form, ModuleBuilder.packageExportProject);
885 packageExportProject: function(o){
886 //make sure no user changes were made
887 document.CreatePackage.action.value = 'ExportPackage';
888 document.CreatePackage.submit();
889 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
890 ModuleBuilder.callLock = false;
892 moduleDelete: function(MBpackage, module){
893 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DELETING'));
894 if (confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_REMOVE_MODULE'))) {
895 ModuleBuilder.getContent('module=ModuleBuilder&action=DeleteModule&package=' + MBpackage + '&view_module=' + module);
896 var node = ModuleBuilder.tree.getNodeByProperty('id', 'package_tree/' + MBpackage + '/' + module);
897 if (node) ModuleBuilder.tree.removeNode(node, true);
900 moduleViewFields: function(o){
902 ModuleBuilder.callLock = false;
904 ModuleBuilder.getContent('module=ModuleBuilder&action=modulefields&view_package=' + ModuleBuilder.MBpackage +
905 '&view_module=' + ModuleBuilder.module);
907 moduleLoadField: function(name, type){
908 if (typeof(type) == 'undefined')
910 if (typeof(formsWithFieldLogic) != 'undefined')
911 formsWithFieldLogic = 'undefined';
912 ModuleBuilder.getContent('module=ModuleBuilder&action=modulefield&view_package=' + ModuleBuilder.MBpackage +
913 '&view_module=' + ModuleBuilder.module + '&field=' + name + '&type=' + type);
915 moduleLoadLabels: function(type){
916 if (typeof(type) == 'undefined')
919 if (type == "studio") {
920 ModuleBuilder.getContent('module=ModuleBuilder&action=editLabels&view_module=' + ModuleBuilder.module);
924 ModuleBuilder.getContent('module=ModuleBuilder&action=modulelabels&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module + '&type=' + type);
927 moduleViewRelationships: function(o){
928 ModuleBuilder.callLock = false;
929 ModuleBuilder.getContent('module=ModuleBuilder&action=relationships&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module);
931 moduleLoadRelationship2: function(name, resetLabel, checkLanguage) {
932 if (resetLabel && Dom.get('rhs_label')) {
933 Dom.get('rhs_label').value = "";
935 var panel = ModuleBuilder.findTabById('relEditor');
937 panel = new YAHOO.SUGAR.ClosableTab({
938 label: SUGAR.language.get("ModuleBuilder", "LBL_RELATIONSHIP_EDIT"),
943 }, ModuleBuilder.tabPanel);
944 ModuleBuilder.tabPanel.addTab(panel);
946 ModuleBuilder.tabPanel.set("activeTab", panel);
948 var rtField = Dom.get('relationship_type_field');
949 var relType = rtField ? rtField.options[rtField.selectedIndex].value: "";
951 name = Dom.get('rel_name_id') ? Dom.get('rel_name_id').value : "";
954 module: 'ModuleBuilder',
955 action: 'relationship',
956 view_package: ModuleBuilder.MBpackage,
957 view_module: ModuleBuilder.module,
958 relationship_name: name,
959 relationship_type: relType,
960 lhs_module: Dom.get('lhs_mod_field') ? Dom.get('lhs_mod_field').value : document.forms.relform ? document.forms.relform.lhs_module.value : "",
961 rhs_module: Dom.get('rhs_mod_field') ? Dom.get('rhs_mod_field').value : "",
962 lhs_label: Dom.get('lhs_label') ? Dom.get('lhs_label').value : "",
963 rhs_label: Dom.get('rhs_label') ? Dom.get('rhs_label').value : "",
968 params['relationship_lang'] = Dom.get('relationship_lang').value;
969 params['ajaxLoad'] = '1';
971 ModuleBuilder.asyncRequest(params, function(o) {
972 ajaxStatus.hideStatus();
973 var tab = ModuleBuilder.findTabById('relEditor');
974 tab.set("content", o.responseText);
975 SUGAR.util.evalScript(o.responseText);
978 moduleDropDown: function(name, field){
979 ModuleBuilder.getContent('module=ModuleBuilder&action=dropdown&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module + '&dropdown_name=' + name + '&field=' + field);
981 moduleViewLayouts: function(o){
982 ModuleBuilder.callLock = false;
983 ModuleBuilder.getContent('module=ModuleBuilder&MB=1&action=wizard&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module);
985 findTabById : function(id) {
986 var tabs = ModuleBuilder.tabPanel.get("tabs");
987 for (var i = 0; i < tabs.length; i++) {
988 if (tabs[i].get("id") == id)
993 autoSetLayout: function(){
994 var mp = ModuleBuilder.mainPanel;
995 var c = Dom.get("mblayout");
996 mp.set("height", Dom.getViewportHeight() - Dom.getY(c) - 30);
997 mp.set("width", Dom.getViewportWidth() - 40);
999 var tabEl = ModuleBuilder.tabPanel.get("element");
1000 Dom.setStyle(tabEl.firstChild.nextSibling, "overflow-y", "auto");
1001 Dom.setStyle(tabEl.firstChild.nextSibling, "height", tabEl.offsetHeight - ModuleBuilder.tabPanel.get("element").firstChild.offsetHeight - 5 + "px");
1002 //Resize editor layouts
1003 if (document.getElementById('toolbox')) Studio2.resizeDivs();
1004 if (document.getElementById('edittabs')) resizeDDLists();
1006 paramsToUrl : function (params) {
1009 url += i + "=" + params[i] + "&";
1013 asyncRequest : function(params, callback) {
1015 if (typeof params == "object") {
1016 url = ModuleBuilder.paramsToUrl(params);
1020 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE'));
1021 Connect.asyncRequest(
1023 Connect.url + '&' + url,
1024 {success: callback, failure: ModuleBuilder.failed}
1027 refreshGlobalDropDown: function(o){
1028 // just clear the callLock; the convention is that this is done in a handler rather than in updateContent
1029 ModuleBuilder.callLock = false;
1030 ModuleBuilder.updateContent(o);
1032 refreshDropDown: function(){
1033 ModuleBuilder.callLock = false;
1034 document.popup_form.action.value = 'RefreshField';
1035 document.popup_form.new_dropdown.value = ModuleBuilder.refreshDD_name;
1036 SimpleList.refreshDD_name = '';
1037 ModuleBuilder.submitForm("popup_form");
1039 dropdownChanged: function(value){
1040 var select = document.getElementById('default[]').options;
1041 while(select.length > 0) {
1044 ModuleBuilder.asyncRequest(
1045 'module=ModuleBuilder&action=get_app_list_string&key=' + value +
1046 '&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module,
1047 ModuleBuilder.dropdownChangedCallback
1050 dropdownChangedCallback : function(o) {
1051 var ajaxResponse = YAHOO.lang.JSON.parse(o.responseText);
1052 var select = document.getElementById('default[]').options;
1054 for (var key in ajaxResponse) {
1055 select[count] = new Option(ajaxResponse[key], key);
1058 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
1060 setSelectedOption : function (sel, option)
1062 var sel = Dom.get(sel);
1063 for (var i = 0; i < sel.options.length; i++)
1065 if(sel.options[i].value == option) {
1066 sel.selectedIndex = i;
1073 ModuleBuilder.buttons = {};
1074 ModuleBuilder.selected = {};
1075 ModuleBuilder.callLock = false;