Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Paste code macro
languagegroovy
titlematrix
def pg = api.getElement("pg")

if (pg == null || api.syntaxCheck) return


def matrix = api.newMatrix([
  "sku", "activePrice", "lastUpdateDate", "download", "action"
])

matrix.setTitle(pg.label)
matrix.setEnableClientFilter(true)
matrix.setColumnFormat("lastUpdateDate", FieldFormatType.DATETIME)
matrix.setPreferenceName("SwissChriss_UltimateResultMatrix_uuid42")
matrix.addColumnTranslation("sku", [en: "sku (click leads to Master Data)"])

api.getElement("pg_items").each { pgi ->
  def row = [:]
  row.sku = matrix.linkCell(pgi.sku, AppPages.MD_PRODUCTS_PAGE, pgi.sku)
  row.activePrice = pgi.activePrice
  row.lastUpdateDate = pgi.lastUpdateDate
  row.download = createDownloadLink(matrix, pg, pgi)
  row.action = createCalcPgiAction(matrix, pg, pgi)
  matrix.addRow(row)
}

if (api.getElement("input_activate_click")) {
  addClickEvent(matrix)
}

if (api.getElement("input_activate_select")) {
  addRowSelectionBackEndAction(matrix, pg)
}

return matrix

// helper methods (they make the above code more readable)

def createDownloadLink(def matrix, def pg, def pgi) {
  matrix.downloadButton("Download (whole PG)",
                        "/pricegridmanager.fetchpdf/" + pg.id,
                        null /*payload*/)
}

def createCalcPgiAction(def matrix, def pg, def pgi) {
  matrix.backEndAction("Recalculate (this item)",
                       "/pricegridmanager.update/" + pg.id,
                       api.toJson([data:[typedId: pgi.typedId]]),
                       "success",
                       "failure")
}

def addClickEvent(def matrix) {
  matrix
    .onRowSelection()
      .triggerEvent(api.dashboardWideEvent("myEvent"))
      .withColValueAsEventDataAttr("sku", "sku_attribute")
}

def addRowSelectionBackEndAction(def matrix, def pg) {
  matrix
    .rowSelectionBackEndAction("SKUs")
      .withLogicName("SC_UltimateMatrix_calc")
      .withColumns("sku")
      .addFormulaInput("PG_label", pg.label)
      .addFormulaInput("PG_id", pg.id)
      .withButtonLabel("Calc PGI")
      .withButtonTooltip("(Re)Calculate the selected Price Grid Items (SKUs)")
      .withSuccessMessage("Success")
      .withFailureMessage("Sorry")
}

...