CampaignCalldown 页面调试

先跑的CF_gridGetObjectMeta

View Code
function CF_gridGetObjectMeta(obj, success_cb, failure_cb) {
    CF_beginProgress('Loading Metadata');
    
    CampaignCallDown.getObjectMeta(obj, function(result, event) {
        if (event.status == true) {
            // success - check picklists
            
            if (obj == 'CampaignMember') {
                eval('var rsCM = ' + result['CampaignMember']);
                eval('var rsCT = ' + result['Contact']);
                eval('var rsAC = ' + result['Account']);
                eval('result  = ' + result[obj]);
                
                result.fields = [];
                result.children = [];

                for (var i = 0; i < rsCM.fields.length; i++) {
                    rsCM.fields[i].Name = rsCM.fields[i].Name;
                    result.fields.push(rsCM.fields[i]);
                }
                for (var i = 0; i < rsCT.fields.length; i++) {
                 rsCT.fields[i].HackObject = 'Contact';
                    rsCT.fields[i].HackField = rsCT.fields[i].Name;
                    
                    rsCT.fields[i].Name = 'Contact.' + rsCT.fields[i].Name;
                    rsCT.fields[i].Label = 'Contact: ' + rsCT.fields[i].Label;

                    rsCT.fields[i].HackExtra = true;
                    
                    if (rsCT.fields[i].Controller != null && rsCT.fields[i].Controller != '') {
                        rsCT.fields[i].Controller = 'Contact.' + rsCT.fields[i].Controller;
                    }
                    
                    rsCT.fields[i].IsUpdateable = false;
                    rsCT.fields[i].IsCreateable = false;
                                    
                    result.fields.push(rsCT.fields[i]);
                }
                for (var i = 0; i < rsAC.fields.length; i++) {
                 rsAC.fields[i].HackObject = 'Account';
                    rsAC.fields[i].HackField = rsAC.fields[i].Name;
                    
                    rsAC.fields[i].Name = 'Contact.Account.' + rsAC.fields[i].Name;
                    rsAC.fields[i].Label = 'Account: ' + rsAC.fields[i].Label;

                    rsAC.fields[i].HackExtra = true;
                    if (rsAC.fields[i].Controller != null && rsAC.fields[i].Controller != '') {
                        rsAC.fields[i].Controller = 'Contact.Account.' + rsAC.fields[i].Controller;
                    }
                    
                    rsAC.fields[i].IsUpdateable = false;
                    rsAC.fields[i].IsCreateable = false;
                    
                    result.fields.push(rsAC.fields[i]);
                }
                
                $.merge(result.children,$.merge(rsAC.children,rsCT.children));
            

            } else {
                eval('result = ' + result[obj]);
            }
            
            var picklistsToLoad = [];
            var resByName = {};
            for (var i = 0; i < result.fields.length; i++) {
                if (result.fields[i].DisplayType == 'MULTIPICKLIST' || result.fields[i].DisplayType == 'PICKLIST') {
                    if (result.fields[i].PicklistVals) {
                        // already loaded
                    } else {
                        // need to load these - possibly over the governance limit
                        picklistsToLoad.push(result.fields[i].Name);
                        resByName[result.fields[i].Name] = result.fields[i];
                    }
                }
            }

            var endFunc = function() {
                // go through all the picklists and set the defaults now
                for (var i = 0; i < result.fields.length; i++) {
                    if (result.fields[i].PicklistVals) {
                        var defaultVal = null;
                        for (var j = 0; j < result.fields[i].PicklistVals.length; j++) {
                            if (result.fields[i].PicklistVals[j].isDefault) {
                                defaultVal = result.fields[i].PicklistVals[j].value;
                                break;
                            }
                        }
                        if (defaultVal) { 
                            result.fields[i].DefaultValue = defaultVal;
                        }
                    }
                }
                success_cb(result);
                CF_endProgress();
            }
            if (picklistsToLoad.length > 0) {
                // call the API to load the next batch - hopefully there aren't more than 200 picklists
                Configero_GridApp.getObjectPicklistMeta(obj, picklistsToLoad, function(pl_result, pl_event) {
                    if (pl_event.status == true) {
                        eval('pl_result = ' + pl_result);
                        for (var x in pl_result) {
                            resByName[x].PicklistVals = pl_result[x];
                        }
                        endFunc();
                    } else {
                        alert(pl_event.message);
                        if (failure_cb) failure_cb();
                        CF_endProgress();
                    }
                }, {escape: false});
            } else {
                endFunc();
            }
        } else {
            // failure
            alert(event.message);
            if (failure_cb) failure_cb();
            CF_endProgress();
        }
    }, {escape: false});
   
}

next:handleObjectMetaResults

View Code
function handleObjectMetaResults(result) {
    var objType = result.objectAPIName;
    preprocessMetaResults(result);
    handleObjectMetaResultsCommon(result, objType,templateName);
    postProcessMetaResults(allFieldsByAPIName[objType], objType);
}

next: handleObjectMetaResultsCommon

View Code
function handleObjectMetaResultsCommon(result, objType, templateGroup) {
    if (!templateGroup) templateGroup = objType;
    allFields[objType] = result.fields;
    allChildRelationships[objType] = result.children;
    allObjectProps[objType] = {feedEnabled: result.feedEnabled, hasRecordTypes: result.hasRecordTypes, keyPrefix: result.keyPrefix, isCreateable: result.isCreateable, isDeletable: result.isDeletable, isUpdateable: result.isUpdateable};
    
    allFieldsByAPIName[objType] = {};
    for (var i = 0; i < allFields[objType].length; i++) {
        allFieldsByAPIName[objType][allFields[objType][i].Name] = allFields[objType][i];
    }
    allTemplates[objType] = result.templates;
    for (var i = 0; i < allTemplates[objType].length; i++) {
        allTemplates[objType][i][CF_NAMESPACE_PREFIX + 'BulkEditTemplateFields__r'] = allTemplates[objType][i][CF_NAMESPACE_PREFIX + 'BulkEditTemplateFields__r']['records'];
    }

    var def = buildDefaultTemplate(allObjectProps[objType], allFieldsByAPIName[objType]);
    var xar = {};
    xar['Id'] = '';
    xar['Name'] = 'System Default';
    xar[CF_NAMESPACE_PREFIX + 'JustMyRecords__c'] = true;
    xar['OwnerId'] = '';
    xar[CF_NAMESPACE_PREFIX + 'Private__c'] = true;
    xar[CF_NAMESPACE_PREFIX + 'BulkEditTemplateFields__r'] = def;
    allTemplates[objType].unshift(xar);

    // determine which template should be selected
    selectedTemplate[templateGroup] = determineDefaultTemplateFromList(allTemplates[objType], templateGroup);
}

next:postMetaResults

View Code
// called once the meta data is loaded - go ahead and prepare the grid and load the results based on the template that we have loaded
function postMetaResults() {
    // add the parent field to the default template
    if (PM_getGridParam('mygrid', 'parentField')) {
     var xar = {};
     xar[CF_NAMESPACE_PREFIX + 'Width__c'] = DEFAULT_COLUMN_WIDTH;
     xar['Name'] = PM_getGridParam('mygrid', 'parentField');
        allTemplates[OBJECT_TYPE][0][CF_NAMESPACE_PREFIX + 'BulkEditTemplateFields__r'].push(xar);
    }
    beginNewSearch('mygrid', OBJECT_TYPE);
}

next:beginNewSearch

View Code
function beginNewSearch(gridName, objType) {if (window[gridName]) window[gridName].CF_clearSearchHistory();ndDataSequence[gridName] = [];beginTemplateSearch(objType);}

 next:beginTemplateSearch

View Code
function beginTemplateSearch(objType) {
  // get field info for this template
  var template = getTemplateById(objType, selectedTemplate[templateName]);
  beginBulkSearch(objType, template[CF_NAMESPACE_PREFIX + 'BulkEditTemplateFields__r']);
}

next:beginBulkSearch

View Code
function beginBulkSearch(objName, templateFields) {
  fieldsLoaded[objName] = [];
  var prevFilters = false;
  if (loadPreviousResults['mygrid'] && mygrid) {
    prevFilters = mygrid.CF_getFilters();
  }
  rebuildGrid(templateFieldsToFieldDef(fieldsLoaded[objName], templateFields, allFieldsByAPIName[objName], objName));
  if (loadPreviousResults['mygrid']) {
      delete loadPreviousResults['mygrid'];
      if (!ndDataSequence['mygrid']) ndDataSequence['mygrid'] = [];
      mygrid.CF_dataSequence = ndDataSequence['mygrid'].slice(0);
      if (prevFilters) {
          mygrid.attachEvent('CF_onLoadComplete', function() {
            mygrid.CF_applyFilters(prevFilters);
          });
      }
      ndDataSequence['mygrid'] = [];
      mygrid.CF_dataById = {};
  }
  mygrid.CF_beginSearch();
}

next:templateFieldsToFieldDef

View Code
function templateFieldsToFieldDef(fieldsLoaded, templateFields, allFieldsByAPIName, obj) {
  // for bulk editing
  var fieldDef = [
      {'name':'','sort':'str','width':'0','align':'center','type':'ch','field':'__selectall','value_func':function(rec){return 0},'filter':'#master_rah_checkbox','skip_export':true,'bulk_edit_override':'','skip_track_changes':true,'selalltype':'master',allowResize:'false'},
      {'name':'<div class="error_icon" />','sort':'str','width':'0','align':'center','field':'__error','type':'err','value_func':function(rec){return '';},'filter':'','skip_export':true,'skip_track_changes':true,allowResize:'false'}
  ];

  // build fieldDef from list of fields for this template
  for (var i = 0; i < templateFields.length; i++) {
      var f = templateFields[i];
      var n = f.Name;
      var a = allFieldsByAPIName[n];
      if (!a) continue;  // maybe the field is no longer valid yet exists in the template?
      fieldsLoaded.push(n);

      var fd = {'name': a.Label, 'soapType': a.SoapType, 'dynamicFieldIndex': i, 'sort':'str','defaultvalue':a.DefaultValue,'width':f[CF_NAMESPACE_PREFIX + 'Width__c'], 'summary':f[CF_NAMESPACE_PREFIX + 'SummaryType__c'], 'align':'left', 'field': a.Name, 'filter':'#textregex_filter', 'createable': a.IsCreateable, 'updateable': a.IsUpdateable, 'controller': a.Controller, 'object': obj};

      if (f[CF_NAMESPACE_PREFIX + 'SplitAt__c']) fd.split = true;

      var readOnly = (!a.IsUpdateable && !a.IsCreateable) || a.Name == 'RecordTypeId';
      if (a.SoapType == 'BOOLEAN') {
          // checkbox
          fd['align'] = 'center';
          fd['type'] = readOnly ? 'chro' : (getDependencyChain(allFieldsByAPIName, a.Name).length > 0 ? 'chvf' : 'ch');
          fd['value_func'] = function(rec, fld) { return rec[fld['field']] ? '1' : '0' };
          fd['filter'] = '#yesno_filter';
      } else if (a.SoapType == 'DATE' || a.SoapType == 'DATETIME') {
          fd['sort'] = 'date';
          fd['align'] = 'center';
          fd['type'] = readOnly ? 'rotxt' : 'dhxCalendarA';
      } else if (a.SoapType == 'DOUBLE' || a.SoapType == 'INTEGER') {
          fd['sort'] = 'int';
          fd['align'] = 'right';
          fd['type'] = readOnly ? 'ron' : 'edn';
          fd['filter'] = '#numeric_filter';
          var s = '';
          for (var j = 0; j < a.Scale; j++) s += '0';
          if (s != '') s = '.' + s;
          fd['numberFormat'] = (a.DisplayType == 'CURRENCY' ? '$' : '') + '0,000' + s;
      } else if (a.DisplayType == 'PICKLIST') {
          fd['type'] = readOnly ? 'corotxt' : 'plvf';
          fd['PicklistVals'] = a['PicklistVals'];
          //fd['filter'] = '#plist_filter'; // get rid of for now - need to show only displayed values?  What about filtering on blank vs showing all?
          fd['sort'] = 'pl';
      } else if (a.DisplayType == 'MULTIPICKLIST' ) {
          fd['type'] = readOnly ? 'rotxt' : 'vf';
          fd['PicklistVals'] = a['PicklistVals'];
      } else if (a.IsHtmlFormatted) {
          if(a.DisplayType == 'TEXTAREA') {
            fd['type'] = readOnly ? 'ro' : 'edtxtvf';
          } else {
            fd['type'] = readOnly ? 'ro' : 'ed';
          }
      } else if (a.DisplayType == 'TEXTAREA') {
          fd['type'] = readOnly ? 'rotxt' : 'edtxtvf';
      } else {
          fd['type'] = readOnly ? 'rotxt' : 'edtxt';
      }
      // if is NOT updateable, then disable bulk edit
      if (readOnly) {
          fd['skip_track_changes'] = true;
      }
      // if is a reference field, add bulk edit info
      if (a.ReferenceTo) {
          fd['related'] = a.ReferenceTo;
          fd['related_field'] = a.Relationship;
      }
      fd['defaultvalue'] = a.DefaultValue;
      if (a.HackExtra) fd['hackextra'] = a.HackExtra;
      if (a.HackObject && a.HackObject != '') fd['hackobject'] = a.HackObject;
      if (a.HackField && a.HackField != '') fd['hackfield'] = a.HackField;
      fieldDef.push(fd);
  }
  return fieldDef;
}

next:rebuildGrid

View Code
function rebuildGrid(fieldDef) { 
    resetMainGrid();

 var dynamicBegin = fieldDef.length;
    for (var i = 0; i < fieldDef.length; i++) {
     if (fieldDef[i].dynamicFieldIndex == 0) {
      dynamicBegin = i;
      break;
     }
    }

    // don't care about view link if don't have a way to open it
    if (PM_getGridParam('mygrid', 'openUrlFunc')) {
     fieldDef.splice(dynamicBegin, 0, {'name':'','sort':'str','width':'30','align':'center','field':'__link','type':'link','value_func':function(rec){return '<img title="Open" src="/resource/1342856524000/AppIcons/actions/go-next.png" />^javascript:PM_getGridParam("mygrid","openUrlFunc")("' + rec.Id + '")'; },'filter':'','skip_export':true,'skip_track_changes':true,allowResize:'false'});
     dynamicBegin++;
    } 
    
    // assume whatever field is here will get the parent defined
    if (PM_getGridParam('mygrid', 'parentField')) {
  fieldDef[dynamicBegin]['type'] = 'tree';
 }
    buildGrid(fieldDef);
}

next:buildGrid

View Code
function buildGrid(fieldDef) {
   var hasContactId = false;
   for (var i = 0; i < fieldDef.length; i++) {
       if (fieldDef[i].field == 'ContactId') hasContactId = true;
   }
   if (!hasContactId) {
       fieldDef.push({'name':'hackContact','width':'0','skip_track_changes':true,'skip_export':true,'type':'rotxt','hack_field':'hackContactId','value_func':function(rec){return rec.ContactId}});
   }
   fieldDef.push({'name':'hackContactName','width':'0','skip_track_changes':true,'skip_export':true,'type':'rotxt','hack_field':'hackContactName','value_func':function(rec){return rec.Contact.Name; }});
   fieldDef.push({'name':'hackAccountName','width':'0','skip_track_changes':true,'skip_export':true,'type':'rotxt','hack_field':'hackAccountName','value_func':function(rec){return (rec.Contact.Account ? rec.Contact.Account.Name : ''); }});  
   
   buildGridBase(OBJECT_TYPE, fieldDef);
   buildTabBase();
   mygrid.CF_searchGetIdsFunc = doRemoterSearchGetIds;
   mygrid.CF_searchLoadDataForIdsFunc = doRemoterGetDataForIds;
   

 
}

next:buildGridBase

View Code
function buildGridBase(objType, fieldDef, toolbarFilterFuncCustom, gridDefHandlerCustom) {
   var gridDefHandler = function(grid) {
    if (gridDefHandlerCustom) grid = gridDefHandlerCustom(grid);
    return grid;
   }
   var toolbarFilterHandler = function(btns, obj) {
        btns.unshift(
        {
            type: "button",
            id: "save_btn",
            img: "Configero/save.png",
            tooltip: 'Save',
            text: 'Save',
            onClick: function(grid) {
              if (!grid.CF_hasBulkEditEnabled) return;
              grid.CF_saveChanges();
            }
        }
        );
        for (var i = 0; i < btns.length; i++) {
         if (btns[i].id == 'delete') {
          var delete_func = btns[i].onClick;
          btns[i].onClick = function(grid) {
           if (grid.CF_hasBulkEditEnabled) {
            //delete_func(grid);
            grid.CF_deleteRows();
            grid.CF_saveChanges();
           } else {
            delete_func(grid);
           }
          }
          break;
         }
        }
     if (toolbarFilterFuncCustom) btns = toolbarFilterFuncCustom(btns, obj);
     return btns;
   }
   __cf._attachGrid(gridCell, {
       'var':  'mygrid',
       'grid': gridDefHandler({
           fields: fieldDef,
           allowFilter: !PM_getGridParam('mygrid', 'suppressHeaderFilter'),
           allowBulkEdit: !PM_getGridParam('mygrid', 'parentField'),
           postInit: function(grid) {
             grid.attachEvent('onResizeEnd', function() { saveTemplate(grid, objType); });
                if (PM_getGridParam(grid.CF_var, 'parentField')) {
                 grid.attachEvent('onRowDblClicked', function(id) {
                     var editurl = PM_getGridParam(grid.CF_var, 'editUrlFunc')();
                     if(editurl) {
                         var idd =grid.getSelectedId();
                         $.doLookupEdit(editurl+'&idd='+escape(idd)+'&grid='+escape(grid.CF_var), null,null,'lookupEditDialog', PM_getGridParam(grid.CF_var, 'editTitleFunc') ? PM_getGridParam(grid.CF_var, 'editTitleFunc')(idd) : '');
                     }
                 });
                 grid.rowToDragElement=function(rid) {
                  for (var i = 0; i < grid.CF_fieldDef.length; i++) {
             if (grid.CF_fieldDef[i]['field'] == 'Name') {
                 var text = grid.cells(rid, i).getValue();
                 return text;
             }
         }
         return '';
                 }

                 grid.setFiltrationLevel(0);
                 grid.enableDragAndDrop(true);
                 
                 grid.attachEvent('onDragIn', function(dId, lId, sobj, tobj) { return sobj == tobj; });
                 grid.attachEvent('onDrag', function(sourceId, targetId, sourceGrid, targetGrid, colIndexStart, colIndexEnd) {
                     // only allow drag/drop among ourselves
                     if (sourceGrid != targetGrid) return false;
 
                     // if it's the same parent already, only do something if ctrl key is parent (ie - unset relationship)
                     var currentParent = grid.getParentId(sourceId);
                     if (currentParent == targetId) {
                         // if control key pressed, undo - otherwise do nothing
                         if (!CF_currentKeysPressed[17]) return false;
                         targetId = null;
                     }
 
                     // call the webapp to see if this is allowed
                     CF_beginProgress('Moving...');
                     grid.CF_dragRowFunc(sourceId, targetId, function(result, event) {
                        if (event.status == true) {
                            reParentRecord(sourceGrid, sourceId, targetId == null ? 0 : targetId);
                        } else {
                            alert(event.message);
                        }
                        CF_endProgress();
                     });
                     return false;
                 });
               } else {
                 // for now set them all to the same thing
                 grid.CF_saveRecsFunc = function(recsToSend, saveChangesHandler, extraParams) {
                  var afterSave = function(res, event) {
                   saveChangesHandler(res, event);
                   // if nothing is selected, reset the depend views
                   if (!grid.getSelectedId()) {
                    grid.callEvent('onRowSelect', ['', '', false]);
                   }
                  }
                  Configero_CampaignCalldownApp.saveRecs(objType, fieldsLoaded[objType], recsToSend, afterSave, extraParams);
        }
               }
           },
           'toolbar': {
               'var':'grid_toolbar',
               items: getGenericGridToolbarSet('mygrid', objType, toolbarFilterHandler)
           }
       })
   });
   mygrid.attachEvent('CF_onLoadComplete', function() {
        if (PM_getGridParam('mygrid', 'autoScrollToId') && PM_getGridParam('mygrid', 'autoScrollToId') != '') {
            // add this event so it runs after all other progress events are done
            CF_doWhenIdle(function() {
                CF_beginProgress('Finding record');
                if (mygrid.CF_hasId(PM_getGridParam('mygrid', 'autoScrollToId'))) {
                    mygrid.showRow(PM_getGridParam('mygrid', 'autoScrollToId'));
                    mygrid.selectRowById(PM_getGridParam('mygrid', 'autoScrollToId'));
                    mygrid.callEvent('onRowSelect', [PM_getGridParam('mygrid', 'autoScrollToId'), '', true]);
                }
                PM_setGridParam('mygrid', 'autoScrollToId', null);
                CF_endProgress();
            });
        }
   });
 }

next:buildTabBase

View Code
 function buildTabBase() {
   var tabs = getTabsForPage();
   hookedTabBars['propertiesCell'] = buildTabBaseAndHooks(tabs, propertiesCell);
 }

next:doRemoterSearchGetIds

View Code
function doRemoterSearchGetIds(loadPageSize,searchResultsHandler, extraParams) {
    campaignId = $("#allCampaigns").val();
    if (!campaignId) {
        CF_endProgress();
        return;
    }
    
    var selStatus ;
    var cmStatus=[];
    selStatus=$("#cmStatus option:selected").each(function(index,obj){
      var o = $(obj);
      var v = o.val();
      cmStatus.push(v);
     }) 

 CampaignCallDown.getCampaignMembers(getFieldsToLoad(),campaignId,cmStatus, loadPageSize, searchResultsHandler, extraParams);
}

next:doRemoterGetDataForIds

View Code
function doRemoterGetDataForIds(lastIdBatch, handleLoadResults, extraParams) {
 Configero_CampaignCalldownApp.getDataForIds(OBJECT_TYPE, getFieldsToLoad(), lastIdBatch, handleLoadResults, extraParams);
}
【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/EasonSun/p/2608011.html