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') {
76 //Setup the basic ajax request settings
77 Connect.extraParams = {
80 Connect.url = 'index.php?to_pdf=1&sugar_body_only=1';
81 Connect.method = 'POST';
82 Connect.timeout = 300000;
84 //Setup and read cookie settings
85 //Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
87 if (SUGAR.themes.tempHideLeftCol)
88 SUGAR.themes.tempHideLeftCol();
90 var Ck = YAHOO.util.Cookie;
92 //Setup the main layout
93 var tp = ModuleBuilder.tabPanel = new YAHOO.widget.TabView("mbtabs");
94 tp.addTab(new YAHOO.widget.Tab({
95 label: SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_MAIN'),
97 content : "<div> </div>",
102 var viewHeight = document.documentElement ? document.documentElement.clientHeight : self.innerHeight;
103 var mp = ModuleBuilder.mainPanel = new YAHOO.widget.Layout('mblayout', {
105 height: viewHeight - (document.getElementById('header').clientHeight ) - 40,
108 units: [//ModuleBuilder.tree, ModuleBuilder.tabPanel,
121 body : "<div id='mbTree'/>"
124 header: SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_HELP'),
133 header: SUGAR.util.getAndRemove("footerHTML").innerHTML,
142 ModuleBuilder.nextYear = new Date();
143 ModuleBuilder.nextYear.setDate(ModuleBuilder.nextYear.getDate() + 360);
145 var nextyear = ModuleBuilder.nextYear;
147 if (Ck.getSub("ModuleBuilder", "helpHidden") == "true") {
148 mp.getUnitByPosition('right').collapse();
150 if (Ck.getSub("ModuleBuilder", "treeHidden") == "true") {
151 mp.getUnitByPosition('left').collapse();
154 var centerEl = mp.getUnitByPosition('center').get('wrap');
155 tp.appendTo(centerEl);
157 //YUI does not take the resizers into account when calculating panel size.
158 var correctW = function(){
159 var w = (this.body.offsetWidth - 7) + "px";
160 this.body.style.width = w;
161 this.header.style.width = w;
163 mp.getUnitByPosition('right').on("resize", correctW);
164 mp.getUnitByPosition('right').on("collapse", function(){
165 Ck.setSub("ModuleBuilder", "helpHidden", "true");
167 mp.getUnitByPosition('right').on("expand", function(){
168 Ck.setSub("ModuleBuilder", "helpHidden", "false");
170 mp.getUnitByPosition('left').on("resize", correctW);
171 mp.getUnitByPosition('left').on("collapse", function(){
172 Ck.setSub("ModuleBuilder", "treeHidden", "true");
174 mp.getUnitByPosition('left').on("expand", function(){
175 Ck.setSub("ModuleBuilder", "treeHidden", "false");
178 Event.on(window, 'resize', ModuleBuilder.autoSetLayout, this, true);
180 var tree = ModuleBuilder.tree = createTreePanel(TREE_DATA, {
183 tree.setCollapseAnim("TVSlideOut");
184 tree.setExpandAnim("TVSlideIn");
185 //tree.subscribe("labelClick", ModuleBuilder.handleTreeClick);
186 tree.subscribe("clickEvent", ModuleBuilder.handleTreeClick);
189 //Setup Browser History
190 var mbContent = YAHOO.util.History.getBookmarkedState('mbContent');
192 if (ModuleBuilder.mode == 'mb') {
193 mp.getUnitByPosition('left').header.firstChild.innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_PACKAGES');
194 mbContent = mbContent ? mbContent : 'module=ModuleBuilder&action=package&package=';
196 else if (ModuleBuilder.mode == 'studio') {
197 ModuleBuilder.MBpackage = ''; // set to empty so other views can recognize that dealing with an deployed, rather than undeployed, module
198 mp.getUnitByPosition('left').header.firstChild.innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_MODULES');
199 mbContent = mbContent ? mbContent :'module=ModuleBuilder&action=wizard';
201 else if (ModuleBuilder.mode == 'dropdowns') {
202 mp.getUnitByPosition('left').header.firstChild.innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_SECTION_DROPDOWNS');
203 mbContent = mbContent ? mbContent : 'module=ModuleBuilder&action=dropdowns';
206 mp.getUnitByPosition('left').collapse(false);
207 mbContent = mbContent ? mbContent : 'module=ModuleBuilder&action=home';
210 YAHOO.util.History.register('mbContent', mbContent, ModuleBuilder.navigate);
211 YAHOO.util.History.initialize("yui-history-field", "yui-history-iframe");
212 ModuleBuilder.getContent(mbContent);
214 if (SUGAR.themes.tempHideLeftCol) SUGAR.themes.tempHideLeftCol();
215 ModuleBuilder.autoSetLayout();
217 ModuleBuilder.tabPanel.on('activeTabChange', function(e) {
218 ModuleBuilder.helpLoad( e.newValue.get("id") ) ;
221 if (Dom.get("HideHandle")){
222 if (SUGAR.themes.tempHideLeftCol){
223 SUGAR.themes.tempHideLeftCol();
228 //Empty layout manager
232 ModuleBuilder.layoutValidation.popup_window = new YAHOO.widget.SimpleDialog("emptyLayout", {
235 constraintoviewport: true,
238 text: SUGAR.language.get('ModuleBuilder', 'ERROR_MINIMUM_FIELDS'),
239 bodyStyle: "padding:5px",
241 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_CLOSE'),
244 ModuleBuilder.layoutValidation.popup_window.hide()
248 ModuleBuilder.layoutValidation.popup_window.render(document.body);
249 ModuleBuilder.layoutValidation.popup_window.show();
252 //Layout history manager
257 browse: function(module, layout, subpanel){
258 subpanel = subpanel ? subpanel : "";
259 if (!module && ModuleBuilder.module != "undefined") {
260 module = ModuleBuilder.module;
262 if (!ModuleBuilder.history.popup_window) {
263 ModuleBuilder.history.popup_window = new YAHOO.SUGAR.AsyncPanel('histWindow', {
267 constraintoviewport: true,
271 var module_str = module;
272 if(typeof SUGAR.language.languages['app_list_strings']['moduleList'][module] != 'undefined'){
273 module_str = SUGAR.language.languages['app_list_strings']['moduleList'][module];
275 ModuleBuilder.history.popup_window.setHeader( module_str + ' : ' + SUGAR.language.get('ModuleBuilder', 'LBL_' + layout.toUpperCase()) + SUGAR.language.get('ModuleBuilder', 'LBL_HISTORY_TITLE'));
276 ModuleBuilder.history.popup_window.setBody("test");
277 ModuleBuilder.history.popup_window.render(document.body);
278 ModuleBuilder.history.params = {
279 module: 'ModuleBuilder',
280 histAction: 'browse',
282 view_package: ModuleBuilder.MBpackage,
287 ModuleBuilder.history.popup_window.load(ModuleBuilder.paramsToUrl(ModuleBuilder.history.params));
288 ModuleBuilder.history.popup_window.show();
289 ModuleBuilder.history.popup_window.center();
291 preview: function(module, layout, id, subpanel) {
292 var prevPanel = ModuleBuilder.findTabById('preview:' + id);
294 ModuleBuilder.history.params = {
295 module: 'ModuleBuilder',
296 histAction: 'preview',
298 view_package: ModuleBuilder.MBpackage,
304 prevPanel = new YAHOO.SUGAR.ClosableTab({
305 dataSrc: Connect.url + "&" + ModuleBuilder.paramsToUrl(ModuleBuilder.history.params),
306 label: SUGAR.language.get("ModuleBuilder", "LBL_MB_PREVIEW"),
311 }, ModuleBuilder.tabPanel);
312 prevPanel.closable = true;
313 ModuleBuilder.tabPanel.addTab(prevPanel);
315 ModuleBuilder.tabPanel.set("activeTab", prevPanel);
319 revert: function(module, layout, id, subpanel){
320 var prevTab = ModuleBuilder.tabPanel.getTabIndex("preview:" + id);
321 if(prevTab) ModuleBuilder.tabPanel.removeTab(prevTab);
323 ModuleBuilder.history.params = {
324 module: 'ModuleBuilder',
325 histAction: 'restore',
327 view_package: ModuleBuilder.MBpackage,
333 ModuleBuilder.asyncRequest(ModuleBuilder.history.params, function(){
334 ModuleBuilder.history.reverted = true;
335 ModuleBuilder.getContent(ModuleBuilder.contentURL);
336 ModuleBuilder.state.isDirty = true;
339 cleanup: function() {
340 if (ModuleBuilder.history.reverted && ModuleBuilder.history.params.histAction) {
341 ModuleBuilder.history.params.histAction = 'unrestore';
342 ModuleBuilder.asyncRequest({params: ModuleBuilder.history.params});
344 ModuleBuilder.history.params = { };
345 ModuleBuilder.history.reverted = false;
348 if (ModuleBuilder.history.popup_window && ModuleBuilder.history.popup_window.cfg.getProperty("visible")) {
349 var historyButton = YAHOO.util.Dom.get('historyBtn');
351 historyButton.onclick();
353 ModuleBuilder.history.popup_window.hide();
361 hideFailedMesage: false,
370 save_url_for_current_view: null,
372 setupState: function(){
373 //ModuleBuilder.state.popup();
374 document.body.setAttribute("onclose", "ModuleBuilder.state.popup(); ModuleBuilder.state.popup_window.show()");
377 onSaveClick: function(){
379 //call the save method of the current view.
380 //call the intended action.
381 ModuleBuilder.state.isDirty = false;
382 var saveBtn = document.getElementById("saveBtn");
384 var mbForm = document.forms[1];
386 var mbButtons = mbForm.getElementsByTagName("input");
388 for (var button = 0; button < mbButtons.length; button++) {
389 var name = mbButtons[button].getAttribute("name");
390 if (name && (name.toUpperCase() == "SAVEBTN" || name.toUpperCase() == "LSAVEBTN")) {
391 saveBtn = mbButtons[button];
397 alert("Could not find the save action for this view.");
401 //After the save call completes, load the next page
402 ModuleBuilder.state.saving = true;
403 eval(saveBtn.getAttributeNode('onclick').value);
405 ModuleBuilder.state.popup_window.hide();
407 onDontSaveClick: function(){
409 //call the intended action.
410 ModuleBuilder.state.isDirty = false;
411 ModuleBuilder.history.cleanup();
412 ModuleBuilder.getContent(ModuleBuilder.state.intended_view.url, ModuleBuilder.state.intended_view.successCall);
413 ModuleBuilder.state.popup_window.hide();
415 loadOnSaveComplete: function() {
416 ModuleBuilder.state.saving = false;
417 ModuleBuilder.getContent(ModuleBuilder.state.intended_view.url, ModuleBuilder.state.intended_view.successCall);
420 ModuleBuilder.state.popup_window = new YAHOO.widget.SimpleDialog("confirmUnsaved", {
423 constraintoviewport: true,
426 text: SUGAR.language.get('ModuleBuilder', 'LBL_CONFIRM_DONT_SAVE'),
427 bodyStyle: "padding:5px",
429 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_DONT_SAVE'),
430 handler: ModuleBuilder.state.onDontSaveClick
432 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_CANCEL'),
435 ModuleBuilder.state.popup_window.hide()
438 text: SUGAR.language.get('ModuleBuilder', 'LBL_BTN_SAVE_CHANGES'),
439 handler: ModuleBuilder.state.onSaveClick
442 ModuleBuilder.state.popup_window.setHeader(SUGAR.language.get('ModuleBuilder', 'LBL_CONFIRM_DONT_SAVE_TITLE'));
443 if(ModuleBuilder.disablePopupPrompt != 1){
444 ModuleBuilder.state.popup_window.render(document.body);
446 ModuleBuilder.state.onDontSaveClick();
450 copyFromView: function(module, layout){
451 var url = ModuleBuilder.contentURL;
452 ModuleBuilder.getContent(url+"©FromEditView=true");
453 ModuleBuilder.contentURL = url;
454 ModuleBuilder.state.intended_view.url = url;
455 ModuleBuilder.state.isDirty = true;
457 //AJAX Navigation Functions
458 navigate : function(url) {
459 //Check if we are just registering the url
460 if (url != ModuleBuilder.contentURL) {
461 ModuleBuilder.getContent(url);
464 getContent: function(url, successCall){
467 if (url.substring(0, 11) == "javascript:")
469 eval(url.substring(11));
473 //save a pointer to intended action
474 ModuleBuilder.state.intended_view.url = url;
475 ModuleBuilder.state.intended_view.successCall = successCall;
476 if(ModuleBuilder.state.isDirty){ //prompt to save current data.
477 //check if we are editing a property of the current view (such views open up in new tabs)
478 //if so we leave the state dirty and return
479 temp_url = url.toLowerCase();
480 if(null == temp_url.match(/&action=editproperty/)){
481 ModuleBuilder.state.popup();
482 ModuleBuilder.state.popup_window.show();
487 ModuleBuilder.state.current_view.url = url;
488 ModuleBuilder.state.current_view.successCall = successCall;
491 ModuleBuilder.contentURL = url;
492 if (typeof(successCall) != 'function') {
493 if (ModuleBuilder.callInProgress)
495 ModuleBuilder.callInProgress = true;
496 successCall = ModuleBuilder.updateContent;
498 ModuleBuilder.asyncRequest(url, successCall);
500 updateContent: function(o){
501 ModuleBuilder.callInProgress = false;
502 //Check if a save action was called and now we need to move-on
503 if (ModuleBuilder.state.saving) {
504 ModuleBuilder.state.loadOnSaveComplete();
507 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
508 if(ModuleBuilder.checkForErrors(o))
512 var ajaxResponse = YAHOO.lang.JSON.parse((o.responseText));
514 YAHOO.SUGAR.MessageBox.show({
515 title: SUGAR.language.get('ModuleBuilder', 'ERROR_GENERIC_TITLE'),
523 if (ajaxResponse.tpl){
524 var t = new YAHOO.SUGAR.Template(ajaxResponse.tpl);
525 ModuleBuilder.ajaxData = ajaxResponse.data;
526 ModuleBuilder.tabPanel.getTab(0).set(t.exec(ajaxResponse.data));
527 SUGAR.util.evalScript(t.exec(ajaxResponse.data));
531 for (var maj in ajaxResponse) {
532 var name = 'mb' + maj;
533 var comp = ModuleBuilder.mainPanel.getUnitById(maj);
535 var tabs = ModuleBuilder.tabPanel.get("tabs");
537 if (tabs[i].get && tabs[i].get("id") == maj)
542 if (name == 'mbwest') { //refresh package_tree!
543 var tree = ModuleBuilder.tree;
544 var root = tree.root;
547 while (root.hasChildren()) {
548 tree.removeNode(root.children[0], true);
550 addChildNodes(root, ajaxResponse.west.content.tree_data);
556 if(ajaxResponse[maj].action == 'deactivate') continue;
557 comp = new YAHOO.SUGAR.ClosableTab({
558 content: "<div class='bodywrapper'><script>ModuleBuilder.scriptTest=true;</script>" + ((maj == 'center') ? "<div>" + ajaxResponse[maj].crumb + "</div>" :"")
559 + ajaxResponse[maj].content + "</div>",
560 label: ajaxResponse[maj].title,
565 }, ModuleBuilder.tabPanel);
566 comp.closable = true;
567 ModuleBuilder.scriptTest = false;
568 ModuleBuilder.tabPanel.set("activeTab", comp);
569 ModuleBuilder.tabPanel.addTab(comp);
570 //Text if the browser automatically evaluated the content's script tags or not. If not, manually evaluate them.
571 if (!ModuleBuilder.scriptTest)
572 SUGAR.util.evalScript(ajaxResponse[maj].content);
574 //Store Center pane changes in browser history
575 YAHOO.util.History.navigate('mbContent', ModuleBuilder.contentURL);
576 if (name == 'mbcenter') {
577 ModuleBuilder.closeAllTabs();
578 comp = ModuleBuilder.tabPanel.getTab(0);
580 ModuleBuilder.tabPanel.set("activeTab", comp);
581 comp.set('content', "<div class='bodywrapper'><div>" + ajaxResponse[maj].crumb + "</div>" + ajaxResponse[maj].content + "</div>");
582 if (ajaxResponse[maj].title != "no_change")
583 comp.set('label', ajaxResponse[maj].title);
584 SUGAR.util.evalScript(ajaxResponse[maj].content);
587 ModuleBuilder.history.update();
590 checkForErrors: function(o){
591 if (SUGAR.util.isLoginPage(o.responseText))
593 if (o.responseText.substr(0, 1) == "<") {
594 YAHOO.SUGAR.MessageBox.show({
595 title: SUGAR.language.get('ModuleBuilder', 'ERROR_GENERIC_TITLE'),
605 submitForm: function(formname, successCall){
606 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_LOADING'));
607 if (typeof(successCall) == 'undefined') {
608 successCall = ModuleBuilder.updateContent;
611 ModuleBuilder.callLock = true;
613 Connect.setForm(document.getElementById(formname) || document.forms[formname]);
614 Connect.asyncRequest(
617 {success: successCall, failure: ModuleBuilder.failed}
620 setMode: function(reqMode){
621 ModuleBuilder.mode = reqMode;
623 main: function(type){
624 document.location.href = 'index.php?module=ModuleBuilder&action=index&type=' + type;
627 if(!ModuleBuilder.state.hideFailedMesage){
628 ajaxStatus.flashStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_FAILED_DATA'), 2000);
632 buttonDown: function(button, name, list){
633 if (typeof(name) != 'undefined') {
634 for (i in ModuleBuilder.buttons[list]) {
635 ModuleBuilder.buttons[list][i].className = 'wizardButton';
637 ModuleBuilder.buttonSelect(name, list);
639 button.className = 'wizardButtonDown';
642 buttonOver: function(button){
643 button.className = 'button';
645 buttonOut: function(button, name, list){
646 if (typeof(name) != 'undefined') {
647 if (ModuleBuilder.buttonGetSelected(list) != name) {
648 button.className = 'wizardButton'
652 button.className = 'wizardButton'
656 buttonAdd: function(id, name, list){
657 if (typeof(ModuleBuilder.buttons[list]) == 'undefined') {
658 ModuleBuilder.buttons[list] = {};
661 ModuleBuilder.buttons[list][name] = document.getElementById(id);
664 buttonGetSelected: function(list){
665 if (typeof(ModuleBuilder.selected[list]) == 'undefined') {
668 return ModuleBuilder.selected[list];
670 buttonSelect: function(name, list){
671 ModuleBuilder.selected[list] = name;
673 buttonToForm: function(form, field, list){
674 var theField = eval('document.' + form + '.' + field);
675 theField.value = ModuleBuilder.buttonGetSelected(list);
678 getTitle: function(title, breadCrumb){
679 return "<h2>" + title + "</h2><br>" + breadCrumb;
681 closeAllTabs: function() {
682 var tabs = ModuleBuilder.tabPanel.get('tabs');
683 for (var i = tabs.length - 1; i > -1; i--) {
691 helpRegister: function(name){
692 var formname = 'document.' + name;
693 var form = eval(formname);
695 for (i = 0; i < form.elements.length; i++) {
696 if (typeof(form.elements[i].type) != 'undefined' && typeof(form.elements[i].name) != 'undefined' && form.elements[i].type != 'hidden') {
697 form.elements[i].onmouseover = function(){
698 ModuleBuilder.helpToggle(this.name)
700 form.elements[i].onmouseout = function(){
701 ModuleBuilder.helpToggle('default')
707 helpUnregisterByID: function (id){
708 var elm = document.getElementById(id);
710 elm.onmouseover = function() {};
711 elm.onmouseout = function() {};
715 helpRegisterByID: function(name, tag){
716 var parent = document.getElementById(name);
717 var children = parent.getElementsByTagName(tag);
718 for (var i = 0; i < children.length; i++) {
719 if (children[i].id != 'undefined') {
720 children[i].onmouseover = function(){
721 ModuleBuilder.helpToggle(this.id)
723 //children[i].onmouseover = function(){alert(this.id)};
724 children[i].onmouseout = function(){
725 ModuleBuilder.helpToggle('default')
730 helpSetup: function(group, def, panel){
731 if (!ModuleBuilder.panelHelp) ModuleBuilder.panelHelp = [];
733 // setup the linkage between this tab/panel and the relevant help
734 var id = ModuleBuilder.tabPanel.get("activeTab").get("id") ;
735 ModuleBuilder.panelHelp [ id ] = { lang: group , def: def } ;
737 // get the help text if required
738 if ( ! ModuleBuilder.AllHelpLang ) ModuleBuilder.AllHelpLang = SUGAR.language.get('ModuleBuilder', 'help');
741 ModuleBuilder.helpLang = ModuleBuilder.AllHelpLang[group];
742 ModuleBuilder.helpDefault = def;
745 ModuleBuilder.helpToggle('default');
747 helpLoad: function(panelId){
748 if (!ModuleBuilder.panelHelp) return;
750 if ( ! ModuleBuilder.AllHelpLang ) ModuleBuilder.AllHelpLang = SUGAR.language.get('ModuleBuilder', 'help');
752 if ( ModuleBuilder.panelHelp [ panelId ] )
754 ModuleBuilder.helpLang = ModuleBuilder.AllHelpLang[ ModuleBuilder.panelHelp [ panelId ].lang ];
755 ModuleBuilder.helpDefault = ModuleBuilder.panelHelp [ panelId ].def ;
756 ModuleBuilder.helpToggle('default');
759 helpToggle: function(name){
760 if (name == 'default')
761 name = ModuleBuilder.helpDefault;
762 if (ModuleBuilder.helpLang != null && typeof(ModuleBuilder.helpLang[name]) != 'undefined') {
763 document.getElementById('mbhelp').innerHTML = ModuleBuilder.helpLang[name];
766 handleSave: function(form, callBack){
767 if (check_form(form)) {
768 ModuleBuilder.state.isDirty=false;
769 ModuleBuilder.submitForm(form, callBack);
773 handleTreeClick: function(o) {
775 ModuleBuilder.getContent(node.data.action);
778 treeSubscribe:function(tree){
779 tree.subscribe("labelClick", ModuleBuilder.treeLabelClick);
781 treeRefresh:function(type){
782 ModuleBuilder.getContent('module=ModuleBuilder&action=ViewTree&tree=' + type);
785 addModule: function(MBpackage){
786 ModuleBuilder.getContent('module=ModuleBuilder&action=module&view_package=' + MBpackage);
788 viewModule: function(MBpackage, module){
789 ModuleBuilder.getContent('module=ModuleBuilder&action=module&view_package=' + MBpackage + '&view_module=' + module);
791 packageDelete: function(MBpackage){
792 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DELETING'));
793 if (confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_REMOVE_PACKAGE'))) {
794 ModuleBuilder.getContent('module=ModuleBuilder&action=DeletePackage&package=' + MBpackage);
795 var node = ModuleBuilder.tree.getNodeByProperty('id', 'package_tree/' + MBpackage);
796 if (node) ModuleBuilder.tree.removeNode(node, true);
799 packagePublish: function(form){
800 if (check_form(form)) {
801 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_BUILDPROGRESS'));
802 ModuleBuilder.submitForm(form, ModuleBuilder.packageBuild);
805 packageBuild: function(o){
806 //make sure no user changes were made
807 document.CreatePackage.action.value = 'BuildPackage';
808 document.CreatePackage.submit();
809 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
810 ModuleBuilder.callLock = false;
812 packageDeploy: function(form, deployed){
813 var confirmed = true;
815 confirmed = confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_DEPLOY_PACKAGE'));
817 if (confirmed && check_form(form)) {
818 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DEPLOYPROGRESS'));
819 ModuleBuilder.submitForm(form, ModuleBuilder.packageInstall);
822 packageInstall: function(o){
823 //make sure no user changes were made
824 document.CreatePackage.action.value = 'displaydeploy';
825 ModuleBuilder.callLock = false;
826 ModuleBuilder.submitForm('CreatePackage', ModuleBuilder.packageInstallCleanup);
828 packageInstallCleanup: function(o){
829 //make sure no user changes were made
830 document.CreatePackage.action.value = 'displaydeploy';
831 ModuleBuilder.callLock = false;
832 ModuleBuilder.submitForm('CreatePackage');
834 beginDeploy: function(p){
835 ModuleBuilder.asyncRequest('module=ModuleBuilder&action=DeployPackage&package=' + p, ModuleBuilder.deployComplete);
837 deployComplete: function(o){
838 var resp = o.responseText;
840 //check if the deploy completed
841 if (!resp.match(/^\s*(\s*(Table already exists : [\w_]*)(<br>)*\s*)*complete$/m))
843 //Unknown error occured, warn the user
844 alert(SUGAR.language.get("ModuleBuilder", "LBL_DEPLOY_FAILED"));
846 //Cleanup in the background
847 ModuleBuilder.asyncRequest(
848 'module=Administration&action=RebuildRelationship&silent=true',
851 ModuleBuilder.asyncRequest(
852 'module=Administration&action=RebuildDashlets&silent=true',
856 ModuleBuilder.failed = function(){};
857 ModuleBuilder.state.hideFailedMesage = true;
859 window.setTimeout("window.location.assign(window.location.href.split('#')[0])", 2000);
863 packageExport: function(form){
864 if (check_form(form)) {
865 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_BUILDPROGRESS'));
866 ModuleBuilder.submitForm(form, ModuleBuilder.packageExportProject);
869 packageExportProject: function(o){
870 //make sure no user changes were made
871 document.CreatePackage.action.value = 'ExportPackage';
872 document.CreatePackage.submit();
873 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'LBL_REQUEST_PROCESSED'), 2000);
874 ModuleBuilder.callLock = false;
876 moduleDelete: function(MBpackage, module){
877 ajaxStatus.showStatus(SUGAR.language.get('ModuleBuilder', 'LBL_AJAX_DELETING'));
878 if (confirm(SUGAR.language.get('ModuleBuilder', 'LBL_JS_REMOVE_MODULE'))) {
879 ModuleBuilder.getContent('module=ModuleBuilder&action=DeleteModule&package=' + MBpackage + '&view_module=' + module);
880 var node = ModuleBuilder.tree.getNodeByProperty('id', 'package_tree/' + MBpackage + '/' + module);
881 if (node) ModuleBuilder.tree.removeNode(node, true);
884 moduleViewFields: function(o){
886 ModuleBuilder.callLock = false;
888 ModuleBuilder.getContent('module=ModuleBuilder&action=modulefields&view_package=' + ModuleBuilder.MBpackage +
889 '&view_module=' + ModuleBuilder.module);
891 moduleLoadField: function(name, type){
892 if (typeof(type) == 'undefined')
894 if (typeof(formsWithFieldLogic) != 'undefined')
895 formsWithFieldLogic = 'undefined';
896 ModuleBuilder.getContent('module=ModuleBuilder&action=modulefield&view_package=' + ModuleBuilder.MBpackage +
897 '&view_module=' + ModuleBuilder.module + '&field=' + name + '&type=' + type);
899 moduleLoadLabels: function(type){
900 if (typeof(type) == 'undefined')
903 if (type == "studio") {
904 ModuleBuilder.getContent('module=ModuleBuilder&action=editLabels&view_module=' + ModuleBuilder.module);
908 ModuleBuilder.getContent('module=ModuleBuilder&action=modulelabels&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module + '&type=' + type);
911 moduleViewRelationships: function(o){
912 ModuleBuilder.callLock = false;
913 ModuleBuilder.getContent('module=ModuleBuilder&action=relationships&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module);
915 moduleLoadRelationship2: function(name, resetLabel, checkLanguage) {
916 if (resetLabel && Dom.get('rhs_label')) {
917 Dom.get('rhs_label').value = "";
919 var panel = ModuleBuilder.findTabById('relEditor');
921 panel = new YAHOO.SUGAR.ClosableTab({
922 label: SUGAR.language.get("ModuleBuilder", "LBL_RELATIONSHIP_EDIT"),
927 }, ModuleBuilder.tabPanel);
928 ModuleBuilder.tabPanel.addTab(panel);
930 ModuleBuilder.tabPanel.set("activeTab", panel);
932 var rtField = Dom.get('relationship_type_field');
933 var relType = rtField ? rtField.options[rtField.selectedIndex].value: "";
935 name = Dom.get('rel_name_id') ? Dom.get('rel_name_id').value : "";
938 module: 'ModuleBuilder',
939 action: 'relationship',
940 view_package: ModuleBuilder.MBpackage,
941 view_module: ModuleBuilder.module,
942 relationship_name: name,
943 relationship_type: relType,
944 lhs_module: Dom.get('lhs_mod_field') ? Dom.get('lhs_mod_field').value : document.forms.relform ? document.forms.relform.lhs_module.value : "",
945 rhs_module: Dom.get('rhs_mod_field') ? Dom.get('rhs_mod_field').value : "",
946 lhs_label: Dom.get('lhs_label') ? Dom.get('lhs_label').value : "",
947 rhs_label: Dom.get('rhs_label') ? Dom.get('rhs_label').value : "",
952 params['relationship_lang'] = Dom.get('relationship_lang').value;
953 params['ajaxLoad'] = '1';
955 ModuleBuilder.asyncRequest(params, function(o) {
956 ajaxStatus.hideStatus();
957 var tab = ModuleBuilder.findTabById('relEditor');
958 tab.set("content", o.responseText);
959 SUGAR.util.evalScript(o.responseText);
962 moduleDropDown: function(name, field){
963 ModuleBuilder.getContent('module=ModuleBuilder&action=dropdown&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module + '&dropdown_name=' + name + '&field=' + field);
965 moduleViewLayouts: function(o){
966 ModuleBuilder.callLock = false;
967 ModuleBuilder.getContent('module=ModuleBuilder&MB=1&action=wizard&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module);
969 findTabById : function(id) {
970 var tabs = ModuleBuilder.tabPanel.get("tabs");
971 for (var i = 0; i < tabs.length; i++) {
972 if (tabs[i].get("id") == id)
977 autoSetLayout: function(){
978 var mp = ModuleBuilder.mainPanel;
979 var c = Dom.get("mblayout");
980 mp.set("height", Dom.getViewportHeight() - Dom.getY(c) - 30);
981 mp.set("width", Dom.getViewportWidth() - 40);
983 var tabEl = ModuleBuilder.tabPanel.get("element");
984 Dom.setStyle(tabEl.firstChild.nextSibling, "overflow-y", "auto");
985 Dom.setStyle(tabEl.firstChild.nextSibling, "height", tabEl.offsetHeight - ModuleBuilder.tabPanel.get("element").firstChild.offsetHeight - 5 + "px");
986 //Resize editor layouts
987 if (document.getElementById('toolbox')) Studio2.resizeDivs();
988 if (document.getElementById('edittabs')) resizeDDLists();
990 paramsToUrl : function (params) {
993 url += i + "=" + params[i] + "&";
997 asyncRequest : function(params, callback) {
999 if (typeof params == "object") {
1000 url = ModuleBuilder.paramsToUrl(params);
1004 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE'));
1005 Connect.asyncRequest(
1007 Connect.url + '&' + url,
1008 {success: callback, failure: ModuleBuilder.failed}
1011 refreshGlobalDropDown: function(o){
1012 // just clear the callLock; the convention is that this is done in a handler rather than in updateContent
1013 ModuleBuilder.callLock = false;
1014 ModuleBuilder.updateContent(o);
1016 refreshDropDown: function(){
1017 ModuleBuilder.callLock = false;
1018 document.popup_form.action.value = 'RefreshField';
1019 document.popup_form.new_dropdown.value = ModuleBuilder.refreshDD_name;
1020 SimpleList.refreshDD_name = '';
1021 ModuleBuilder.submitForm("popup_form");
1023 dropdownChanged: function(value){
1024 var select = document.getElementById('default[]').options;
1025 while(select.length > 0) {
1028 ModuleBuilder.asyncRequest(
1029 'module=ModuleBuilder&action=get_app_list_string&key=' + value +
1030 '&view_package=' + ModuleBuilder.MBpackage + '&view_module=' + ModuleBuilder.module,
1031 ModuleBuilder.dropdownChangedCallback
1034 dropdownChangedCallback : function(o) {
1035 var ajaxResponse = YAHOO.lang.JSON.parse(o.responseText);
1036 var select = document.getElementById('default[]').options;
1038 for (var key in ajaxResponse) {
1039 select[count] = new Option(ajaxResponse[key], key);
1043 setSelectedOption : function (sel, option)
1045 var sel = Dom.get(sel);
1046 for (var i = 0; i < sel.options.length; i++)
1048 if(sel.options[i].value == option) {
1049 sel.selectedIndex = i;
1056 ModuleBuilder.buttons = {};
1057 ModuleBuilder.selected = {};
1058 ModuleBuilder.callLock = false;