Loading...
 
Skip to main content

History: API Tracker Update Demo

Source of version: 9 (current)

Copy to clipboard
            {PARAM(name="itemId")}
  {PERM(perms="tiki_p_modify_tracker_items" type="trackeritem" object={{itemId}})}
    {LIST(cache="n")}
      {pagination max="1"}
      {filter field="tracker_id" content="18"}
      {filter field="object_id" content="{{itemId}}"}
      {OUTPUT()}Item admin: {DIV(class="click-modal" type="span")}[tiki-tracker-update_item?trackerId=18&itemId={display name=object_id}|{display name=title}]{DIV} (example number: {button href="#" _icon_name="arrow-down" _class="stockAdmin minus" _type="danger"} {DIV(type="span" class="stockAdmin number")}{display name="tracker_field_exampleNumber" default="0"}{DIV} {button href="#" _icon_name="arrow-up" _class="stockAdmin plus" _type="success"}){OUTPUT}
      {ALTERNATE()}^Hmm, not found?^{ALTERNATE}
    {LIST}
  {ELSE}
^You'll need to [login|log in] to be able to edit this tracker item.^
  {PERM}
{ELSE}
Try this [API-Tracker-Update-Demo?itemId=2745]
{PARAM}

{JQ()}$(".stockAdmin.minus, .stockAdmin.plus")
    .css("cursor", "pointer")
    .on(
        "click",
        function () {
            let itemId = location.href.match(/itemId=(\d+)/);
            if (itemId) {
                itemId = itemId[1];
            } else {
                alert("No example number found");
                return;
            }
            const $stockAdmin = $(".stockAdmin.number");
            $stockAdmin.tikiModal(" ");
            let stock = $stockAdmin.text();
            if ($(this).hasClass("minus")) {
                stock--;
            } else {
                stock++;
            }
            $.ajax(
                $.service("tracker", "update_item"),
                {
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        fields: {
                            exampleNumber: stock
                        },
                        itemId: itemId,
                        trackerId: 18
                    },
                    success: function (data) {
                        if (! data) {
                            alert("Oops, something went wrong, sorry");
                        } else {
                            $stockAdmin.text(stock);
                        }
                        $(".stockAdmin.number").tikiModal();
                    }
                }
            ).fail(function(jqXHR, textStatus, errorThrown) {
                alert( "error: " + textStatus);
                debugger;
                $(".stockAdmin.number").tikiModal();
            });
            return false;
        }){JQ}

Page source is [tiki-pagehistory.php?page=API+Tracker+Update+Demo&source=0|here]