3 Replies Latest reply on Mar 12, 2014 9:10 PM by Ryan Rutan

    How to use API functions within HTML widget?

    richardliu

      Hi everyone:

       

      I found two useful functions in v3 Javascript API,

        https://developers.jivesoftware.com/api/v3/js/documents.html

        https://developers.jivesoftware.com/api/v3/js/Document.html

       

      I tried to add those functions to my HTML widget,  but IE reminded me the “osapi” was undefined while I debuging.

       

      What I want to ask is:

       

      Can I use those functions within HTML widget? If yes, how can I make it?

      If no, is there anyother solution to let me create and save docuemt (create and save in content of one group) within HTML widget? For example, click the button and call the backgroud function to finish the create and save behaviours.

       

      Thank you~~

       

      Richard

        • Re: How to use API functions within HTML widget?

          I gave an interesting example snippet here:

          Can you create fly-out menus in an HTML widget?

           

          Should get you started at least =)

          1 person found this helpful
            • Re: How to use API functions within HTML widget?
              richardliu

              Hi Ryan:

               

              I read the thread carefully, and saw you post the codes below at the end. And come across several questions.

               

              1)  You said we can use the Core REST API. Did you means that we can use that API in HTML widget thorugh these codes?

              2) What are the parameters "section" and "data"? I want to test the and see what would come out, but I don't know where the parameters come from.

              3) There is a "GET" function in the sample code, is there a similar "CREATE" function?

               

              Thank you very much

               

              Richard

               

              var navLinks = {};

              navLinks.load = function(section) {

              var documentID=1234;

                $.ajax({

                      type: "GET",

                      url: "/api/core/v3/contents?filter=entityDescriptor(102,documentID)

                      dataType: "text"

                  }).success(function(data) {

                      //NOTE:  substring needed to parse exception headers out for easy JSON parsing

                      navLinks.show(JSON.parse(data.substring(data.indexOf("{"))),section);

                  });

              }; // end function

               

              navLinks.show = function (data,section) {

                //*** THIS jQUERY SELECTOR ASSUMES YOU ARE USING A <ul id="sectioncode"> WITH CHILDREN <LI> tags containing <A> ***

                //**** YOU CAN STORE LINKS ANY WAY YOU CAN IN THE DOCUMENT

                $(data.list[0].content.text).find("#"+section+" li a").each(function() {

                    // DO WHATEVER WITH EACH LINK TO RENDER IN NAV

                    alert(this.html());

                });

              }; // end function