-
-
Save eirikb/0a35dd446801e5a3bfe2 to your computer and use it in GitHub Desktop.
execThen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-controller="UserCtrl"> | |
<p>Hello {{user.get_title()}}</p> | |
</div> | |
<div ng-controller="ListsCtrl"> | |
<p>All lists:</p> | |
<ul> | |
<li ng-repeat="list in lists"> | |
{{list.get_title()}} | |
</li> | |
</ul> | |
</div> | |
<div ng-controller="SiteUsersCtrl"> | |
<p>All users:</p> | |
<ul> | |
<li ng-repeat="user in users"> | |
{{user.get_title()}} | |
</li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('ctx', function ($q) { | |
var ctx = new SP.ClientContext("/"); | |
ctx.execThen = (function () { | |
var q; | |
return function () { | |
if (!q) { | |
q = $q.when().then(function () { | |
return $q(function (resolve, reject) { | |
ctx.executeQueryAsync(resolve, reject); | |
}).then(function () { | |
q = null; | |
}); | |
}); | |
} | |
return q; | |
}; | |
})(); | |
return ctx; | |
}); | |
app.controller('UserCtrl', function ($scope, ctx) { | |
var user = ctx.get_web().get_currentUser(); | |
ctx.load(user); | |
ctx.execThen().then(function () { | |
$scope.user = user; | |
}); | |
}); | |
app.controller('ListsCtrl', function ($scope, ctx) { | |
var lists = ctx.get_web().get_lists(); | |
ctx.load(lists); | |
ctx.execThen().then(function () { | |
$scope.lists = []; | |
var e = lists.getEnumerator(); | |
while (e.moveNext()) $scope.lists.push(e.get_current()); | |
}); | |
}); | |
app.controller('SiteUsersCtrl', function ($scope, ctx) { | |
var users = ctx.get_web().get_siteUsers(); | |
ctx.load(users); | |
ctx.execThen().then(function () { | |
$scope.users = []; | |
var e = users.getEnumerator(); | |
while (e.moveNext()) $scope.users.push(e.get_current()); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment