Name

sn_smd.SMBaseAction

Description

Abstract base action. Any sub action should implement function -doAction (..)

Script

var SMBaseAction = Class.create();
SMBaseAction.prototype = {
  
  // We actually need this to do reflection for some reason
  initialize: function() {},
  
  /* eslint-disable no-unused-vars */  
  /**
  * Abstract action method. Params should be JSON with {paramName: value, ...} 
  */
  doAction : function(params) {		
  	throw 'Need to implement the doAction method';
  },
  /* eslint-enable no-unused-vars */ 

  // Why do we need these JSON methods...? We're not using them anywhere. 
  
  /**
  * encode object to JSON string.
  */
  encodeJSON : function(val) {
  	return new global.JSON().encode(val);
  },
  
  /**
  * convert JSON string to JSON object.
  */
  decodeJSON : function(val) {
  	return new global.JSON().decode(val);
  },

  /**
   * Checks the params object for the keys in the expectedParams array. If any are missing, it throws a missing parameter
   * error. Also checks for "undefined" and "null" which are NOT falsy but we want them to be here.
   *
   * @param {Object} params - the value that is passed to 'doAction'
   * @param {String|Array<String>} expectedParams - parameters that are expected in params
   */
  validateParameters: function(params, expectedParams) {

      if (typeof expectedParams == 'string')
          expectedParams = [expectedParams];

      var missingParams = [];
      expectedParams.forEach(function(expectedParam) {
          var param = params[expectedParam];
          if (!param || param === 'undefined' || param === 'null')
              missingParams.push(expectedParam);
      });

      if (missingParams.length)
          throw SMErrorHelper.createMissingParameterError(this.type + '.doAction()', missingParams, true);
  },

  type: 'SMBaseAction'
};

Sys ID

2429da529313310054005d3f867ffb55

Offical Documentation

Official Docs: