Select to view content in your preferred language

Need help with modification of print plus widget

608
0
03-26-2018 11:01 AM
QiranLiang
Regular Contributor

Hi,

I'm trying to use our own print service in the print plus widget. But later I found out that it doesn't execute the "Get Layout Templates Info" GP services like the WAB print widget did.  I need some help with adding the "Get Layout Templates Info" in there. 

I tried to add the code 

LayerInfos, in the functions 

and then 

LayerInfos.getInstance(this.map, this.map.itemInfo)
  .then(lang.hitch(this, function(layerInfosObj) {
    this.layerInfosObj = layerInfosObj;
    return all([this._getPrintTaskInfo(), this._getLayerTemplatesInfo()])
      .then(lang.hitch(this, function(results) {
        var taksInfo = results[0],
          templatesInfo = results[1];
        if (templatesInfo && !templatesInfo.error) {
          var parameters = templatesInfo && templatesInfo.results;
          if (parameters && parameters.length > 0) {
            array.some(parameters, lang.hitch(this, function(p) {
              return p && p.paramName === 'Output_JSON' ?
                this.templateInfos = p.value : false;
            }));
            if (this.templateInfos && this.templateInfos.length > 0) {
              this.templateNames = array.map(this.templateInfos, function(ti) {
                return ti.layoutTemplate;
              });
            }
          }
        } else {
          console.warn('Get Layout Templates Info Error',
            templatesInfo && templatesInfo.error);
        }
        if (!esriLang.isDefined(taksInfo) || (taksInfo && taksInfo.error)) {
          this._handleError(taksInfo.error);
        } else {
          this._handlePrintInfo(taksInfo);
        }
      }));
  })).always(lang.hitch(this, function() {
    this.shelter.hide();
  }));

and
_getLayerTemplatesInfo: function() {
  var def = new Deferred();
  var parts = this.printTaskURL.split('/');
  var pos = parts.indexOf('GPServer');
  if (pos > -1) {
    var url = null;
    if (/Utilities\/PrintingTools\/GPServer/.test(this.printTaskURL)) {
      url = parts.slice(0, pos + 1).join('/') + '/' +
        encodeURIComponent('Get Layout Templates Info Task') + '/execute';
    } else {
      url = parts.slice(0, pos + 1).join('/') + '/' +
        encodeURIComponent('Get Layout Templates Info') + '/execute';
    }
    esriRequest({
      url: url,
      content: {
        f: "json"
      },
      callbackParamName: "callback",
      handleAs: "json",
      timeout: 60000
    }).then(lang.hitch(this, function(info) {
      def.resolve(info);
    }), lang.hitch(this, function(err) {
      def.resolve({
        error: err
      });
    }));
  } else {
    def.resolve(null);
  }

  return def;
},

to the printplus.js 

then the widget fail loading in WAB.

0 Kudos
0 Replies