首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >结合Javascript if语句进行剪纸

结合Javascript if语句进行剪纸
EN

Stack Overflow用户
提问于 2018-10-03 20:26:30
回答 5查看 433关注 0票数 5

我的任务是在Js中为剪纸脚本组合两个if语句。它是一款打印管理软件。我有我需要的一切,我相信下面的脚本。问题是把这两个if合并成一个语句,我相信。我不熟悉Javascript,也不熟悉python。我希望在重新安排这个脚本做如下所述的一些帮助。

PaperCut print script API reference

目标:

只有在打印作业10+页时才会弹出成本中心,否则会自动将作业计入公司的非计费帐户。如果作业是50+ pages,请将其从HP重定向到较大的复印机。在这种情况下,从test_printer3到复印机-颜色。

代码语言:javascript
复制
/*
* 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 + "'.");
  }

}
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2018-10-11 01:54:05

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

代码语言:javascript
复制
/*
* 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
}
票数 3
EN

Stack Overflow用户

发布于 2018-10-09 03:53:56

我认为您在这里遇到的问题必须处理您提到的if语句块中的多个return语句。

这个街区就是你所拥有的..。

代码语言:javascript
复制
if (!inputs.job.isAnalysisComplete) {
    return;
    actions.job.chargeToPersonalAccount();
    return;

    if (inputs.job.totalPages < 10) {
        actions.job.chargeToSharedAccount(ADM-3900);
    } 
} 

我认为如果它是这样的话这个区块会更准确...

代码语言:javascript
复制
/*No details of print analysis?  Return the the function immediately!*/
if (!inputs.job.isAnalysisComplete) {
    return;
} 

/*Job less than ten pages?  Charge shared account.  Otherwise charge personal account.*/
if (inputs.job.totalPages < 10) {

    /*Also, my bet is that the ADM-3900 needs to be in quotes for a string unless other wise stated in the manual.*/

    actions.job.chargeToSharedAccount("ADM-3900");
} else {
    actions.job.chargeToPersonalAccount();
}

注意,这是我最好的猜测,因为我不熟悉剪纸软件。

如果这还不起作用,那么总会有technical support

票数 0
EN

Stack Overflow用户

发布于 2018-10-11 02:51:24

根据我对GOAL的理解,我将对您的代码进行下一步更改:

代码语言:javascript
复制
/*
* 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.
*/

// Setup limit for charge the job to ADM-3900.

var ADM_3900_CHARGE_LIMIT = 10;

// Setup of redirection for larger jobs.

var REDIRECT_PAGE_LIMIT = 50;
var REDIRECT_PRINTER  = "Copier - Color";

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.
    */

    // Check if job analysis is completed (return if not)

    if (!inputs.job.isAnalysisComplete)
    {
        // No job details yet so return.
        // XXX: We should return some value that the client can
        // identify and know he have to call the method again on a
        // few seconds (when job analysis is complete). the client could
        // also check this condition before calling us.
        return false;
    }

    // If pages to print is less than ADM_3900_CHARGE_LIMIT,
    // just charge the job to the firm non-billable (ADM-3900) account.

    if (inputs.job.totalPages < ADM_3900_CHARGE_LIMIT)
    {
        // Charge to the firm non-bill account.
        actions.job.chargeToSharedAccount(ADM-3900);

        // Return with success.
        return true;
    }

    // At this point, we have to charge to personal account.

    actions.job.chargeToPersonalAccount();

    // Finally, check if we have to redirect to a more efficient or
    // faster high volume printer.

    if (inputs.job.totalPages > REDIRECT_PAGE_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(REDIRECT_PRINTER, {allowHoldAtTarget: true});

        // Notify the user that the job was automatically redirected.

        actions.client.sendMessage(
            "The print job was over " + REDIRECT_PAGE_LIMIT + " pages and" +
            " was sent to printer: " + REDIRECT_PRINTER + "."
        );

        // Record that the job was redirected in the application log.

        actions.log.info(
            "Large job redirected from printer '" + inputs.job.printerName +
            "' to printer '" + REDIRECT_PRINTER + "'."
        );
    }

    // Return with success.
    return true;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52627020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档