-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 17, 2016
0 parents
commit 3fcf4b8
Showing
1,916 changed files
with
250,180 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
243 changes: 243 additions & 0 deletions
243
BookSourceCode/Chapter 11 - File upload/bootstrap-fileupload.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
/* =========================================================== | ||
* bootstrap-fileupload.js j2 | ||
* Code to upload files in SharePoint; derived from bootstrap file upload plugin | ||
* http://jasny.github.com/bootstrap/javascript.html#fileupload | ||
* =========================================================== | ||
* Copyright 2012 Jasny BV, Netherlands. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ========================================================== */ | ||
|
||
!function ($) { | ||
|
||
"use strict"; // jshint ;_ | ||
//alert("fileupload.js"); | ||
/* FILEUPLOAD PUBLIC CLASS DEFINITION | ||
* ================================= */ | ||
var file | ||
|
||
var Fileupload = function (element, options) { | ||
//alert("FILEUPLOAD"); | ||
this.$element = $(element) | ||
this.type = this.$element.data('uploadtype') || (this.$element.find('.thumbnail').length > 0 ? "image" : "file") | ||
|
||
this.$input = this.$element.find(':file') | ||
if (this.$input.length === 0) return | ||
|
||
this.name = this.$input.attr('name') || options.name | ||
|
||
this.$hidden = this.$element.find('input[type=hidden][name="' + this.name + '"]') | ||
if (this.$hidden.length === 0) { | ||
this.$hidden = $('<input type="hidden" />') | ||
this.$element.prepend(this.$hidden) | ||
} | ||
|
||
|
||
this.$preview = this.$element.find('.fileupload-preview') | ||
this.$path = this.$element.find('.fileupload-path') | ||
var height = this.$preview.css('height') | ||
if (this.$preview.css('display') != 'inline' && height != '0px' && height != 'none') this.$preview.css('line-height', height) | ||
|
||
this.original = { | ||
'exists': this.$element.hasClass('fileupload-exists'), | ||
'preview': this.$preview.html(), | ||
'path': this.$path.html(), | ||
'hiddenVal': this.$hidden.val() | ||
} | ||
|
||
this.$remove = this.$element.find('[data-dismiss="fileupload"]') | ||
this.$uploadnow = this.$element.find('[data-dismiss="fileuploadnow"]') | ||
this.$element.find('[data-trigger="fileupload"]').on('click.fileupload', $.proxy(this.trigger, this)) | ||
|
||
this.listen() | ||
} | ||
|
||
Fileupload.prototype = { | ||
|
||
listen: function () { | ||
//alert("listen") | ||
this.$input.on('change.fileupload', $.proxy(this.change, this)) | ||
$(this.$input[0].form).on('reset.fileupload', $.proxy(this.reset, this)) | ||
if (this.$remove) this.$remove.on('click.fileupload', $.proxy(this.clear, this)) | ||
if (this.$uploadnow) this.$uploadnow.on('click.fileupload', $.proxy(this.upload, this)) | ||
}, | ||
|
||
upload: function (e) { | ||
alert("upload invoked"); | ||
if (!file) { | ||
alert("no file to upload") | ||
this.clear() | ||
return | ||
} | ||
alert("before file reading") | ||
var bufferReader = new FileReader() | ||
|
||
|
||
bufferReader.onload = function (e) { | ||
alert("buffer reading") | ||
var buffer = e.target.result; | ||
var digest = $('#__REQUESTDIGEST').val(); | ||
alert(digest); | ||
|
||
$.ajax({ | ||
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('/sites/fileuploadtest/Documents/Communities')/Files/Add(url='" + file.name + "',overwrite=true)", | ||
method: 'POST', | ||
data: buffer,//bytes, | ||
//binaryStringRequestBody: true, | ||
headers: { | ||
//"Accept": "application/json; odata=verbose", | ||
'content-type': "application/json;odata=verbose", | ||
'X-RequestDigest': $('#__REQUESTDIGEST').val(), | ||
"content-length": buffer.length//bytes.byteLength | ||
}, | ||
processData: false,//ensure no conversion is done on the image file | ||
success: function (e) { | ||
alert('successfully done'); | ||
}, | ||
error: function (err) { alert("Error in JSON: " + JSON.stringify(err)); }, | ||
//state: "Update" | ||
}); | ||
|
||
} | ||
bufferReader.onerror = function (e) { | ||
alert("File could not be read! Code " + e.target.error.code); | ||
}; | ||
|
||
bufferReader.readAsArrayBuffer(file); | ||
alert("after add file"); | ||
e.preventDefault() | ||
}, | ||
|
||
change: function (e, invoked) { | ||
//alert("change") | ||
if (invoked === 'clear') return | ||
|
||
file = e.target.files !== undefined ? e.target.files[0] : (e.target.value ? { name: e.target.value.replace(/^.+\\/, '')} : null) | ||
|
||
if (!file) { | ||
this.clear() | ||
return | ||
} | ||
|
||
this.$hidden.val('') | ||
this.$hidden.attr('name', '') | ||
this.$input.attr('name', this.name) | ||
|
||
if (this.$preview.length > 0 && (typeof file.type !== "undefined" ? file.type.match('image.*') : file.name.match('\\.(gif|png|jpe?g)$')) && typeof FileReader !== "undefined") {//this.type === "image" && | ||
|
||
var urlReader = new FileReader() | ||
var preview = this.$preview | ||
var element = this.$element | ||
|
||
|
||
|
||
urlReader.onload = function (e) { | ||
preview.html('<img src="' + e.target.result + '" ' + (preview.css('max-height') != 'none' ? 'style="max-height: ' + preview.css('max-height') + ';"' : '') + ' />') | ||
element.addClass('fileupload-exists').removeClass('fileupload-new') | ||
} | ||
urlReader.onerror = function (e) { | ||
alert("File could not be read! Code " + e.target.error.code); | ||
}; | ||
|
||
|
||
urlReader.readAsDataURL(file) | ||
this.$path.text(file.name) | ||
|
||
} else { | ||
alert("did not read file"); | ||
//alert("file type: " + file.type + " type: " + this.type); | ||
this.$path.text(file.name) | ||
this.$element.addClass('fileupload-exists').removeClass('fileupload-new') | ||
} | ||
}, | ||
|
||
clear: function (e) { | ||
//alert("clear") | ||
this.$hidden.val('') | ||
this.$hidden.attr('name', this.name) | ||
this.$input.attr('name', '') | ||
|
||
//ie8+ doesn't support changing the value of input with type=file so clone instead | ||
if (navigator.userAgent.match(/msie/i)) { | ||
var inputClone = this.$input.clone(true); | ||
this.$input.after(inputClone); | ||
this.$input.remove(); | ||
this.$input = inputClone; | ||
} else { | ||
this.$input.val('') | ||
} | ||
|
||
this.$preview.html('') | ||
this.$path.html('') | ||
this.$element.addClass('fileupload-new').removeClass('fileupload-exists') | ||
|
||
if (e) { | ||
this.$input.trigger('change', ['clear']) | ||
e.preventDefault() | ||
} | ||
}, | ||
|
||
reset: function (e) { | ||
//alert("reset") | ||
this.clear() | ||
|
||
this.$hidden.val(this.original.hiddenVal) | ||
this.$preview.html(this.original.preview) | ||
this.$path.html(this.original.path) | ||
|
||
if (this.original.exists) this.$element.addClass('fileupload-exists').removeClass('fileupload-new') | ||
else this.$element.addClass('fileupload-new').removeClass('fileupload-exists') | ||
}, | ||
|
||
trigger: function (e) { | ||
alert("trigger") | ||
this.$input.trigger('click') | ||
e.preventDefault() | ||
} | ||
} | ||
|
||
|
||
/* FILEUPLOAD PLUGIN DEFINITION | ||
* =========================== */ | ||
|
||
$.fn.fileupload = function (options) { | ||
return this.each(function () { | ||
var $this = $(this) | ||
, data = $this.data('fileupload') | ||
if (!data) $this.data('fileupload', (data = new Fileupload(this, options))) | ||
if (typeof options == 'string') data[options]() | ||
}) | ||
} | ||
|
||
$.fn.fileupload.Constructor = Fileupload | ||
|
||
|
||
/* FILEUPLOAD DATA-API | ||
* ================== */ | ||
|
||
$(document).on('click.fileupload.data-api', '[data-provides="fileupload"]', function (e) { | ||
//alert("fileupload data-api") | ||
var $this = $(this) | ||
if ($this.data('fileupload')) return | ||
$this.fileupload($this.data()) | ||
|
||
var $target = $(e.target).closest('[data-dismiss="fileupload"],[data-trigger="fileupload"]'); | ||
//alert("target"); | ||
if ($target.length > 0) { | ||
//alert("click fileupload") | ||
$target.trigger('click.fileupload') | ||
e.preventDefault() | ||
} | ||
}) | ||
|
||
} (window.jQuery); |
10 changes: 10 additions & 0 deletions
10
BookSourceCode/Chapter 11 - File upload/fileupload_htmlsource.txt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div data-provides="fileupload" class="fileupload fileupload-new"> | ||
<input type="hidden"/> | ||
<input type="hidden"/> | ||
<div class="input-append"> | ||
<div class="uneditable-input span3"> | ||
<i class="icon-file fileupload-exists"></i> | ||
<span class="fileupload-path"></span>  </div> | ||
<span class="btn btn-file"><span class="fileupload-new">Select file</span><span class="fileupload-exists">Change</span><input type="file"/> </span><a data-dismiss="fileupload" href="#" class="btn fileupload-exists">Remove</a><a data-dismiss="fileuploadnow" href="#" class="btn fileupload-exists">Upload</a><span class="fileupload-preview"></span></div> | ||
<br/> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
BookSourceCode/Chapter 12 - Geolocation/SPGeolocationList/SPGeolocationList.sln
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SPGeolocationList", "SPGeolocationList\SPGeolocationList.csproj", "{325E13CB-6AB1-41A9-8620-3E25366C9DA6}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{325E13CB-6AB1-41A9-8620-3E25366C9DA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{325E13CB-6AB1-41A9-8620-3E25366C9DA6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{325E13CB-6AB1-41A9-8620-3E25366C9DA6}.Debug|Any CPU.Deploy.0 = Debug|Any CPU | ||
{325E13CB-6AB1-41A9-8620-3E25366C9DA6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{325E13CB-6AB1-41A9-8620-3E25366C9DA6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{325E13CB-6AB1-41A9-8620-3E25366C9DA6}.Release|Any CPU.Deploy.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file added
BIN
+36.5 KB
BookSourceCode/Chapter 12 - Geolocation/SPGeolocationList/SPGeolocationList.v11.suo
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
BookSourceCode/Chapter 12 - Geolocation/SPGeolocationList/SPGeolocationList/AppManifest.xml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest" | ||
Name="SPGeolocationList" | ||
ProductID="{1ffaf046-3cc7-46a7-b4ea-f6b7dc38880d}" | ||
Version="1.0.0.0" | ||
SharePointMinVersion="15.0.0.0" | ||
> | ||
<Properties> | ||
<Title>SPGeolocationList</Title> | ||
<StartPage>~appWebUrl/Pages/Default.aspx?{StandardTokens}</StartPage> | ||
</Properties> | ||
|
||
<AppPrincipal> | ||
<Internal /> | ||
</AppPrincipal> | ||
|
||
|
||
</App> |
1 change: 1 addition & 0 deletions
1
BookSourceCode/Chapter 12 - Geolocation/SPGeolocationList/SPGeolocationList/Content/App.css
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* Place custom styles below */ |
6 changes: 6 additions & 0 deletions
6
...rceCode/Chapter 12 - Geolocation/SPGeolocationList/SPGeolocationList/Content/Elements.xml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> | ||
<Module Name="Content"> | ||
<File Path="Content\App.css" Url="Content/App.css" /> | ||
</Module> | ||
</Elements> |
14 changes: 14 additions & 0 deletions
14
...er 12 - Geolocation/SPGeolocationList/SPGeolocationList/Content/LocationList/Elements.xml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> | ||
<!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List project item, an error will occur when the project is run. --> | ||
<ListTemplate | ||
Name="LocationList" | ||
Type="10000" | ||
BaseType="0" | ||
OnQuickLaunch="TRUE" | ||
SecurityBits="11" | ||
Sequence="410" | ||
DisplayName="LocationList" | ||
Description="My List Definition" | ||
Image="/_layouts/15/images/itgen.png"/> | ||
</Elements> |
4 changes: 4 additions & 0 deletions
4
...PGeolocationList/SPGeolocationList/Content/LocationList/LocationListInstance/Elements.xml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> | ||
<ListInstance Title="LocationList" OnQuickLaunch="TRUE" TemplateType="10000" Url="Lists/LocationList" Description="My List Instance"></ListInstance> | ||
</Elements> |
6 changes: 6 additions & 0 deletions
6
.../SPGeolocationList/Content/LocationList/LocationListInstance/SharePointProjectItem.spdata
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ProjectItem Type="Microsoft.VisualStudio.SharePoint.ListInstance" DefaultFile="Elements.xml" SupportedTrustLevels="All" SupportedDeploymentScopes="Web, Site" xmlns="http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel"> | ||
<Files> | ||
<ProjectItemFile Source="Elements.xml" Target="LocationListInstance\" Type="ElementManifest" /> | ||
</Files> | ||
</ProjectItem> |
57 changes: 57 additions & 0 deletions
57
...pter 12 - Geolocation/SPGeolocationList/SPGeolocationList/Content/LocationList/Schema.xml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<List xmlns:ows="Microsoft SharePoint" Title="LocationList" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/LocationList" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/"> | ||
<MetaData> | ||
<ContentTypes> | ||
|
||
|
||
<ContentType ID="0x0100397c5645059d4ec79b5f9fbba4d211df" Name="ListFieldsContentType"><FieldRefs><FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" /><FieldRef ID="{be075499-998a-4924-a69a-8fe11bcc612d}" Name="Location1" /></FieldRefs></ContentType><ContentTypeRef ID="0x01"> | ||
<Folder TargetName="Item" /> | ||
</ContentTypeRef><ContentTypeRef ID="0x0120" /></ContentTypes> | ||
<Fields> | ||
|
||
<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" DisplayName="$Resources:core,Title;" Required="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" MaxLength="255" /><Field Type="Geolocation" DisplayName="Location" ID="{be075499-998a-4924-a69a-8fe11bcc612d}" SourceID="{b9497bff-6e4c-4f72-89dd-80be589aebd0}" StaticName="Location1" Name="Location1" /></Fields> | ||
<Views> | ||
|
||
|
||
<View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE"> | ||
<Toolbar Type="Standard" /> | ||
<XslLink Default="TRUE">main.xsl</XslLink> | ||
<RowLimit Paged="TRUE">30</RowLimit> | ||
<ViewFields> | ||
|
||
<FieldRef Name="LinkTitleNoMenu"></FieldRef></ViewFields> | ||
<Query> | ||
<OrderBy> | ||
|
||
<FieldRef Name="Modified" Ascending="FALSE"></FieldRef></OrderBy> | ||
</Query> | ||
<ParameterBindings> | ||
<ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" /> | ||
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" /> | ||
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" /> | ||
</ParameterBindings> | ||
</View><View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/15/images/generic.png" Url="AllItems.aspx"> | ||
<Toolbar Type="Standard" /> | ||
<XslLink Default="TRUE">main.xsl</XslLink> | ||
<JSLink>clienttemplates.js</JSLink> | ||
<RowLimit Paged="TRUE">30</RowLimit> | ||
<ViewFields> | ||
|
||
<FieldRef Name="LinkTitle"></FieldRef><FieldRef Name="Location1" /></ViewFields> | ||
<Query> | ||
<OrderBy> | ||
|
||
<FieldRef Name="ID"></FieldRef></OrderBy> | ||
</Query> | ||
<ParameterBindings> | ||
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" /> | ||
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" /> | ||
</ParameterBindings> | ||
</View></Views> | ||
<Forms> | ||
<Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> | ||
<Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> | ||
<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> | ||
</Forms> | ||
</MetaData> | ||
</List> |
Oops, something went wrong.