all files / src/ sputils.list.items.js

100% Statements 16/16
83.33% Branches 5/6
100% Functions 5/5
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                                                
(function () {
  /** @namespace sputils.list.items */
  var checkFile = function (dir, fileUrl) {
    var cctxPromise = sputils.helpers.clientContext(fileUrl);
    return cctxPromise.then(function (cctx) {
      var web = cctx.get_web();
      var page = web.getFileByServerRelativeUrl(
        sputils.helpers.abs2rel(fileUrl));
 
      if (dir === 'in') {
        page.checkIn();
      } else Eif (dir === 'out') {
        page.checkOut();
      }
 
      return new Cctx(cctx).executeQuery();
    });
  };
 
  var checkIn = function (url) {
    return checkFile('in', url);
  };
 
  var checkOut = function (url) {
    return checkFile('out', url);
  };
 
  // public API for this submodule.
  sputils.list = fjs.assign(sputils.list || {}, {
    items: {
      /**
       * Initiates a checkIn operation on the file located at the supplied URL.
       * @function sputils.list.items.checkIn
       * @param {string} url - the URL of the file
       * @returns {Promise} the promise of fulfilling the operation
       * @example
       *
       * sputils.list.items.checkIn('/pages/default.aspx')
       *   .then(function () { console.log('page was checked in') });
       */
      checkIn: checkIn,
      /**
       * Initiates a checkOut operation on the file located at the supplied URL.
       * @function sputils.list.items.checkOut
       * @param {string} url - the URL of the file
       * @returns {Promise} the promise of fulfilling the operation
       * @example
       *
       * sputils.list.items.checkOut('/pages/default.aspx')
       *   .then(function () { console.log('page was checked out') });
       */
      checkOut: checkOut
    }
  });
})();