javascript - 结合 Javascript if 语句进行 Papercut

标签 javascript

我的任务是将 Js 中的两个 if 语句组合成 Papercut 脚本。它是一个打印管理软件。我拥有我需要的一切我相信下面的脚本。我相信问题是将这两个 if 组合成一个语句。我不熟悉 Javascript,也不熟悉 python。我希望在重新安排此脚本以按如下所述执行操作时获得一些帮助。

PaperCut print script API reference

目标:

仅当他们打印 10 页以上的作业时才会弹出成本中心,否则只会自动将作业计入公司的非计费 (ADM-3900) 帐户。 如果作业超过 50 页,将其从 HP 重定向到更大的复印机。在这种情况下,从 test_printer3 到 Copier – Color。

/*
* Redirect large jobs without confirmation
* 
* Users printing jobs larger than the defined number of pages have their jobs 
* automatically redirected to another printer or virtual queue.
* This can be used to redirect large jobs from slower or high cost printers 
* to more efficient or faster high volume printers.
*/

function printJobHook(inputs, actions) {

  /*
  * This print hook will need access to all job details
  * so return if full job analysis is not yet complete.
  * The only job details that are available before analysis
  * are metadata such as username, printer name, and date.
  *
  * See reference documentation for full explanation.
  */

  /*
  * NOTE: The high-volume printer must be compatible with the source printer.
  *       i.e. use the same printer language like PCL or Postscript.
  *       If this is a virtual queue, all printers in the queue must use
  *       the same printer language.
  */

  if (!inputs.job.isAnalysisComplete) {
    // No job details yet so return.

    return;
    actions.job.chargeToPersonalAccount();

    return;


    if (inputs.job.totalPages < 10) {

      // Charge to the firm non-bill account

      actions.job.chargeToSharedAccount(ADM-3900);

    } 
    // Account Selection will still show

  } 

  var LIMIT             = 5; // Redirect jobs over 5 pages.


  var HIGH_VOL_PRINTER  = "Copier - Color";

  if (inputs.job.totalPages > LIMIT) {
    /*
    * Specify actions.job.bypassReleaseQueue() if you wish to bypass the release queue
    * on the original printer the job was sent to.  (Otherwise if held at the target,
    * the job will need to be released from two different queues before it will print.)
    */
    actions.job.bypassReleaseQueue();

    /*
    * Job is larger than our page limit, so redirect to high-volume printer,
    * and send a message to the user.
    * Specify "allowHoldAtTarget":true to allow the job to be held at the hold/release
    * queue for the high-volume printer, if one is defined.
    */

    actions.job.redirect(HIGH_VOL_PRINTER, {allowHoldAtTarget: true});

    // Notify the user that the job was automatically redirected.
    actions.client.sendMessage(
      "The print job was over " + LIMIT + " pages and was sent to " 
      + " printer: " + HIGH_VOL_PRINTER + ".");

    // Record that the job was redirected in the application log.
    actions.log.info("Large job redirected from printer '" + inputs.job.printerName 
                     + "' to printer '" + HIGH_VOL_PRINTER + "'.");
  }

}

最佳答案

我相信这就是您要找的东西,但还不完全清楚。在不知道所有逻辑分支的情况下很难合并条件。

/*
* Redirect large jobs without confirmation
* 
* Users printing jobs larger than the defined number of pages have their jobs 
* automatically redirected to another printer or virtual queue.
* This can be used to redirect large jobs from slower or high cost printers 
* to more efficient or faster high volume printers.
*/

 function printJobHook(inputs, actions) {

 /*
 * This print hook will need access to all job details
 * so return if full job analysis is not yet complete.
 * The only job details that are available before analysis
 * are metadata such as username, printer name, and date.
 *
 * See reference documentation for full explanation.
 */

 /*
 * NOTE: The high-volume printer must be compatible with the source printer.
 *       i.e. use the same printer language like PCL or Postscript.
 *       If this is a virtual queue, all printers in the queue must use
 *       the same printer language.
 */


 var LIMIT             = 5; // Redirect jobs over 5 pages.
 var HIGH_VOL_PRINTER  = "Copier - Color";  

if (!inputs.job.isAnalysisComplete) { 
 return;// No job details yet so return. 
} 


//Charge jobs with less than 10 pages to non-bill account
if (inputs.job.totalPages < 10) {
  // Charge to the firm non-bill account
  actions.job.chargeToSharedAccount(ADM-3900);
} 
else //Charge jobs with more than 10 pages to the personal account
{   
    actions.job.chargeToPersonalAccount();

      if (inputs.job.totalPages > LIMIT) {
        /*
        * Specify actions.job.bypassReleaseQueue() if you wish to bypass the release queue
        * on the original printer the job was sent to.  (Otherwise if held at the target,
        * the job will need to be released from two different queues before it will print.)
        */
        actions.job.bypassReleaseQueue();

        /*
        * Job is larger than our page limit, so redirect to high-volume printer,
        * and send a message to the user.
        * Specify "allowHoldAtTarget":true to allow the job to be held at the hold/release
        * queue for the high-volume printer, if one is defined.
        */

        actions.job.redirect(HIGH_VOL_PRINTER, {allowHoldAtTarget: true});

        // Notify the user that the job was automatically redirected.
        actions.client.sendMessage(
          "The print job was over " + LIMIT + " pages and was sent to " 
          + " printer: " + HIGH_VOL_PRINTER + ".");

        // Record that the job was redirected in the application log.
        actions.log.info("Large job redirected from printer '" + inputs.job.printerName 
                         + "' to printer '" + HIGH_VOL_PRINTER + "'.");
      }
}
   return
}

关于javascript - 结合 Javascript if 语句进行 Papercut ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52627020/

相关文章:

JavaScript 模块模式(function(){})(); vs block 语句

javascript - 是否可以将 Angular 模板编译为最终的 html 字符串?

javascript - 通过单击具有数字和字符串值的列的表标题对 React 表进行排序

javascript - Meteor js 显示方法结果

javascript - 在node.js REPL 中使用SetInterval?