Du er her: Hjem > Sharepoint > Javascript til Content Editor Webparts > Visitkort i en enkel fil

Visitkort i en enkel fil

Et enkelt lille visitkort samlet i en fil, der kan sættes ind i, eller linkes fra, en Content Editor Webpart. Koden er baseret på CSOM og jquery, og kan enkelt rettes til efter behov.

Har man behov for en oversigt over hvilke bruger attributter der er tigængelige, kan man udkommentere afsnittet på linje 124-129.

Hvis brugeren ikke har uploadet et billede af sig selv, vises et standard billede, som vist herunder:

 SPBusinessCard

Filen kan downloades her.

Kode:

<!--
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Vidar Jon Bauge <vidarjb@gresshoppen.dk>
-->
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.userprofiles.js"></script>
 
<table class="SPBCContactDetails">
<tr>
<td class="SPBCImageDiv"><img id="SPBCPersonImage" src="" alt="" class="SPBCPersonImage"></td>
 
<td>
<table>
<tr class="SPBCShowAttribute">
<td class="SPBCShowKeyName">Name:</td>
<td id="SPBCNameCell" class="SPBCShowDetails"></td>
</tr>
<tr class="SPBCShowAttribute">
<td class="SPBCShowKeyName">Adress:</td>
<td id="SPBCAdressCell" class="SPBCShowDetails"></td>
</tr>
<tr class="SPBCShowAttribute">
<td class="SPBCShowKeyName">Position:</td>
<td id="SPBCPositionCell" class="SPBCShowDetails"></td>
</tr>
<tr class="SPBCShowAttribute">
<td class="SPBCShowKeyName">Email:</td>
<td id="SPBCEmailCell" class="SPBCShowDetails"></td>
</tr>
<tr class="SPBCShowAttribute">
<td class="SPBCShowKeyName">Department:</td>
<td id="SPBCDepartmentCell" class="SPBCShowDetails"></td>
</tr>
</table></td>
</tr>
</table>
<div id="userDetails"></div>
 
<!-- CSS -->
<style type="text/css">
.SPBCPersonImage{
height:auto;
width:auto;
border:solid;
border-color:#696969;
}
 
.SPBCContactDetails{
border-style:solid;
border-width:1px;
}
 
.SPBCShowAttribute{
text-align:left;
}
 
.SPBCShowKeyName{
padding-right:5px;
font-weight:bold;
}
 
.SPBCShowDetails{
padding-left:5px;
}
 
.SPBCImageDiv{
padding:2px2px2px2px;
}
</style>
 
<script type="text/javascript">
Type.registerNamespace('VJBSCode')
 VJBSCode.SpUserBusinessCard = VJBSCode.SpUserBusinessCard || {};
 
VJBSCode.SpUserBusinessCard.CurrentUser = "";
VJBSCode.SpUserBusinessCard.MyProperties = "";
VJBSCode.SpUserBusinessCard.DefaultPersonImage = "_layouts/images/O14_person_placeHolder_96.png";
 
VJBSCode.SpUserBusinessCard.LoadUser = function() {
 console.log("Requesting user details");
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
VJBSCode.SpUserBusinessCard.CurrentUser = web.get_currentUser();
 
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
VJBSCode.SpUserBusinessCard.MyProperties = peopleManager.getMyProperties();
 
clientContext.load(VJBSCode.SpUserBusinessCard.MyProperties);
clientContext.load(VJBSCode.SpUserBusinessCard.CurrentUser);
clientContext.executeQueryAsync(Function.createDelegate(this, this.VJBSCode.SpUserBusinessCard.OnQuerySucceeded), Function.createDelegate(this, this.VJBSCode.SpUserBusinessCard.OnQueryFailed));
};
 
VJBSCode.SpUserBusinessCard.OnQuerySucceeded = function() {
 console.log("Request succeeded");
 
var picUrl = VJBSCode.SpUserBusinessCard.MyProperties.get_userProfileProperties()["PictureURL"];
var actUrl = (picUrl === "") ? VJBSCode.SpUserBusinessCard.DefaultPersonImage : VJBSCode.SpUserBusinessCard.DefaultPersonImage;
 
$("#SPBCPersonImage").attr("src", actUrl);
 
$("#SPBCNameCell").html(VJBSCode.SpUserBusinessCard.MyProperties.get_userProfileProperties()["FirstName"] + " "+ VJBSCode.SpUserBusinessCard.MyProperties.get_userProfileProperties()["LastName"]);
$("#SPBCAdressCell").html(VJBSCode.SpUserBusinessCard.MyProperties.get_userProfileProperties()["Office"]);
$("#SPBCPositionCell").html(VJBSCode.SpUserBusinessCard.MyProperties.get_userProfileProperties()["Title"]);
$("#SPBCEmailCell").html(VJBSCode.SpUserBusinessCard.MyProperties.get_userProfileProperties()["WorkEmail"]);
$("#SPBCDepartmentCell").html(VJBSCode.SpUserBusinessCard.MyProperties.get_userProfileProperties()["Department"]);
 
var myUserProperties = VJBSCode.SpUserBusinessCard.MyProperties.get_userProfileProperties();
 
//Uncomment this block to dump all the users properties
/*
 $("#userDetails").append("<table>");
 $("#userDetails").append("<th style='text-align: left;'>Key</th><th style='text-align: left;'>Value</th>");
 $.each(myUserProperties, function(key, value) {
 $("#userDetails").append("<tr><td>" + key + "</td><td>" + value + "</td></tr>");
 });
 $("#userDetails").append("</table>");
 */
};
 
VJBSCode.SpUserBusinessCard.OnQueryFailed = function(sender, args) {
 console.log('Request failed.'+ args.get_message());
};
 
//VJBSCode.SpUserBusinessCard.ToggleShowDetails = function(){
 
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {
 console.log("Initiating SP.ClientContext");
});
SP.SOD.executeOrDelayUntilScriptLoaded(VJBSCode.SpUserBusinessCard.LoadUser, "sp.js"); 
</script>
 
<!--
 
Available properties:
 
PersonalSpace
PictureURL
PreferredName
PublicSiteRedirect
PulseMRUPeople
QuickLinks
SID
SPS-AdjustHijriDays
SPS-AltCalendarType
SPS-Birthday
SPS-CalendarType
SPS-ClaimID
SPS-ClaimProviderID
SPS-ClaimProviderType
SPS-ContentLanguages
SPS-DataSource
SPS-Department
SPS-DisplayOrder
SPS-DistinguishedName
SPS-DontSuggestList
SPS-Dotted-line
SPS-EmailOptin
SPS-FeedIdentifier
SPS-FirstDayOfWeek
SPS-FirstWeekOfYear
SPS-HashTags
SPS-HideFromAddressLists
SPS-HireDate
SPS-Interests
SPS-JobTitle
SPS-LastColleagueAdded
SPS-LastKeywordAdded
SPS-Locale
SPS-Location
SPS-MUILanguages
SPS-MasterAccountName
SPS-MemberOf
SPS-MySiteUpgrade
SPS-O15FirstRunExperience
SPS-OWAUrl
SPS-ObjectExists
SPS-PastProjects
SPS-Peers
SPS-PersonalSiteCapabilities
SPS-PersonalSiteFirstCreationError
SPS-PersonalSiteFirstCreationTime
SPS-PersonalSiteInstantiationState
SPS-PersonalSiteLastCreationTime
SPS-PersonalSiteNumberOfRetries
SPS-PhoneticDisplayName
SPS-PhoneticFirstName
SPS-PhoneticLastName
SPS-PictureExchangeSyncState
SPS-PicturePlaceholderState
SPS-PictureTimestamp
SPS-PointPublishingUrl
SPS-PrivacyActivity
SPS-PrivacyPeople
SPS-ProxyAddresses
SPS-RecipientTypeDetails
SPS-RegionalSettings-FollowWeb
SPS-RegionalSettings-Initialized
SPS-ResourceAccountName
SPS-ResourceSID
SPS-Responsibility
SPS-SavedAccountName
SPS-SavedSID
SPS-School
SPS-SharePointHomeExperienceState
SPS-ShowWeeks
SPS-SipAddress
SPS-Skills
SPS-SourceObjectDN
SPS-StatusNotes
SPS-TenantInstanceId
SPS-Time24
SPS-TimeZone
SPS-UserPrincipalName
SPS-UserType
SPS-WorkDayEndHour
SPS-WorkDayStartHour
SPS-WorkDays
Title
UserName
UserProfile_GUID
WebSite
WorkEmail
WorkPhone
MsOnline-ObjectId
 
-->