Creating an Api Key setting for Web Search in Media Library

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros 2013-06-03 16:20:10 -07:00
parent aa1d0ec590
commit 86385c8e1d
10 changed files with 122 additions and 30 deletions

View File

@ -83,7 +83,7 @@ Pixels EMs Percent Points
24px 1.846em 184.6% 18pt
*/
html, body { height:100%; box-sizing: border-box; }
html, body { height:100%; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
html {
color:#333;

View File

@ -0,0 +1,25 @@
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Localization;
using Orchard.MediaLibrary.Models;
namespace Orchard.MediaLibrary.Handlers {
[UsedImplicitly]
public class WebSearchSettingsPartHandler : ContentHandler {
public WebSearchSettingsPartHandler() {
T = NullLocalizer.Instance;
Filters.Add(new ActivatingFilter<WebSearchSettingsPart>("Site"));
Filters.Add(new TemplateFilterForPart<WebSearchSettingsPart>("WebSearchSettings", "Parts/WebSearch.WebSearchSettings", "media"));
}
public Localizer T { get; set; }
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
if (context.ContentItem.ContentType != "Site")
return;
base.GetItemMetadata(context);
context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Media")));
}
}
}

View File

@ -0,0 +1,12 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
namespace Orchard.MediaLibrary.Models {
public class WebSearchSettingsPart : ContentPart {
public string ApiKey {
get { return this.As<InfosetPart>().Get<WebSearchSettingsPart>("ApiKey"); }
set { this.As<InfosetPart>().Set<WebSearchSettingsPart>("ApiKey", value); }
}
}
}

View File

@ -134,8 +134,10 @@
<Compile Include="Handlers\MediaLibraryPickerFieldHandler.cs" />
<Compile Include="Handlers\MediaPartHandler.cs" />
<Compile Include="Drivers\MediaPartDriver.cs" />
<Compile Include="Handlers\WebSearchSettingsPartHandler.cs" />
<Compile Include="Migrations.cs" />
<Compile Include="Models\AudioPart.cs" />
<Compile Include="Models\WebSearchSettingsPart.cs" />
<Compile Include="Models\ImagePart.cs" />
<Compile Include="Models\DocumentPart.cs" />
<Compile Include="Models\VideoPart.cs" />
@ -301,6 +303,9 @@
<ItemGroup>
<Content Include="Views\Media-OEmbed.Thumbnail.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\EditorTemplates\Parts\WebSearch.WebSearchSettings.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@ -1,9 +1,10 @@
 .zone-content, #content, #main, #layout-content , #layout-main {
.zone-content, #content, #main, #layout-content, #layout-main {
height: 100%;
display: block;
min-height: 400px;
margin-bottom: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
@ -35,6 +36,8 @@
border: 1px solid #e0e0e0;
border-width: 0 1px 1px 1px;
background-color: white;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
@ -86,12 +89,12 @@
font-size:14px;
}
.media-library-folder-title {
box-sizing: border-box;
-moz-box-sizing: border-box;
border: 2px solid transparent;
width: 100%;
}
.media-library-folder-title {
-moz-box-sizing: border-box;
box-sizing: border-box;
border: 2px solid transparent;
width: 100%;
}
.media-library-folder-title.dropping {
border-color: #444;
@ -268,6 +271,8 @@
-webkit-background-size: cover;
background-size: cover;
background-image: none;
-moz-box-sizing: inherit;
-webkit-box-sizing: inherit;
box-sizing: inherit;
}
@ -284,6 +289,8 @@
background-repeat: no-repeat;
background-position: center;
border: 1px solid #e0e0e0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
@ -292,6 +299,8 @@
background-repeat: no-repeat;
background-position: center;
border: 1px solid #e0e0e0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

View File

@ -22,11 +22,13 @@
margin-right: 40px;
}
#query input {
width: 100%;
box-sizing: border-box;
height: 28px;
}
#query input {
width: 100%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
height: 28px;
}
#icon {
float: right;

View File

@ -162,11 +162,13 @@
margin-right: 40px;
}
#query input {
width: 100%;
box-sizing: border-box;
height: 28px;
}
#query input {
width: 100%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
height: 28px;
}
#icon {
float: right;
@ -188,4 +190,14 @@
.actions {
margin-top: 5px;
}
#message-api {
background: #fdf5bc; /* yellow */
border: 1px solid #ffea9b;
margin: 5px;
padding: 5px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

View File

@ -0,0 +1,14 @@
@model Orchard.MediaLibrary.Models.WebSearchSettingsPart
<fieldset>
<legend>@T("Web Search")</legend>
<div>
@Html.TextBoxFor(m => m.ApiKey, new { @class = "textMedium"})
<span class="hint">@T("Your private key.")</span>
</div>
@T("Get a free API Key on {0}", "<a href=\"http://datamarket.azure.com/dataset/bing/search\">http://datamarket.azure.com/dataset/bing/search</a>")
</fieldset>

View File

@ -1,4 +1,7 @@
@using System.Text
@using Orchard.ContentManagement
@using Orchard.MediaLibrary.Models
@using Orchard.UI.Notify
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
@ -16,12 +19,20 @@
@Display.HeadScripts()
@Display.HeadLinks()
@Display.StyleSheetLinks()
@{
var apiKey = WorkContext.CurrentSite.As<WebSearchSettingsPart>().ApiKey;
}
</head>
<body >
<div id="websearch-main">
<!-- Register for an API account on https://datamarket.azure.com/dataset/5BA839F1-12CE-4CCE-BF57-A49D98D29A44 -->
@if (String.IsNullOrWhiteSpace(apiKey)) {
<div id="message-api">
@T("You need to define an API Key in the Media settings before being able to use this feature.")
</div>
}
<form data-bind="submit: doSearch">
<div class="query-container">
<div id="icon">
@ -118,11 +129,11 @@
self.doSearch = function () {
var query = $('#query > input').val();
var url = 'https://api.datamarket.azure.com/Bing/Search/Image?$format=json&Query=%27' + encodeURIComponent(query) + '%27';
$.ajax({
type: "POST",
url: url,
headers: { "Authorization": "Basic @Convert.ToBase64String(Encoding.ASCII.GetBytes(":" + "FqMaK2bg6vxvFBOFFNF2uS8hHFWo3t1PM3YNxVswx7o="))" }
headers: { "Authorization": "Basic @Convert.ToBase64String(Encoding.ASCII.GetBytes(":" + @apiKey))" }
}).done(function (msg) {
var results = msg.d.results;
self.clearSelection();

View File

@ -109,14 +109,16 @@ ul.tagit li.tagit-choice a.tagit-close:hover {
color: #535353;
}
ul.tagit input[type="text"] {
-moz-box-sizing: border-box;
border: none !important;
margin: 0 !important;
padding: 0 !important;
width: inherit !important;
outline: none;
}
ul.tagit input[type="text"] {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border: none !important;
margin: 0 !important;
padding: 0 !important;
width: inherit !important;
outline: none;
}
.tagit-hiddenSelect {
display:none;