Loading...
 
Skip to main content

History: API Tracker Update Demo

Source of version: 5

Copy to clipboard
            {PARAM(name="itemId")}
{LIST(cache="n")}
{list 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}
Try this [{{page}}?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: {
                            productsStock: stock
                        },
                        itemId: itemId,
                        trackerId: 18
                    },
                    success: function (data) {
                        if (!data) {
                            alert("Oops, something went wrong, sorry");
                        } else {
                            $stockAdmin.text(stock);
                        }
                        $(".stockAdmin.number").tikiModal();
                    }
                }
            );
            return false;
        }){JQ}

{CODE(colors="javascript")}$(".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 product id 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: {
                            productsStock: stock
                        },
                        itemId: itemId,
                        trackerId: 1
                    },
                    success: function (data) {
                        if (!data) {
                            alert("Oops, something went wrong, sorry");
                        } else {
                            $stockAdmin.text(stock);
                        }
                        $(".stockAdmin.number").tikiModal();
                    }
                }
            );
            return false;
        })
{CODE}

        

History

Advanced
Information Version
Jonny Bradley 9
Jonny Bradley 8
Jonny Bradley 7
Jonny Bradley 6
Jonny Bradley 5
Jonny Bradley 4
Jonny Bradley 3
Jonny Bradley 2
Jonny Bradley Not finished yet... 1