Initial checkin of the rte embed option

This commit is contained in:
Tim Geyssens
2013-09-13 13:46:19 +02:00
parent da05196023
commit bc7bbea650
6 changed files with 163 additions and 2 deletions

View File

@@ -376,6 +376,19 @@ angular.module('umbraco.services')
return openDialog(options);
},
/**
* @ngdoc method
* @name umbraco.services.dialogService#ysodDialog
* @methodOf umbraco.services.dialogService
*
* @description
* Opens a dialog to an embed dialog
*/
embedDialog: function (options) {
options.template = 'views/common/dialogs/embed.html';
options.show = true;
return openDialog(options);
},
/**
* @ngdoc method
* @name umbraco.services.dialogService#ysodDialog

View File

@@ -0,0 +1,23 @@
angular.module("umbraco").controller("Umbraco.Dialogs.EmbedController", function ($scope, $http) {
$scope.url = "";
$scope.width = 500;
$scope.height = 300;
$scope.constrain = true;
$scope.preview = "";
$scope.showPreview = function () {
$http({ method: 'POST', url: '/umbraco/UmbracoApi/Embed/Embed', params: { url: $scope.url, width: $scope.width, height: $scope.height } })
.success(function (data) {
$scope.preview = data.Markup;
})
.error(function () {
});
};
$scope.insert = function () {
$scope.submit($scope.preview);
};
});

View File

@@ -0,0 +1,35 @@
<div class="umb-panel" ng-controller="Umbraco.Dialogs.EmbedController">
<div class="umb-panel-header">
<div class="umb-el-wrap umb-panel-buttons">
<div class="btn-toolbar umb-btn-toolbar">
<input type="button" ng-click="insert()" class="btn btn-primary" value="Insert" />
</div>
</div>
</div>
<div class="umb-panel-body umb-scrollable" auto-scale="1">
<div class="umb-panel">
<div class="umb-control-group">
<label for="url">Url</label>
<input id="url" type="text" ng-model="url" ng-change="showPreview()"/>
<label>Size:</label>
<input type="text" ng-model="width"/> x <input type="text" ng-model="height" />
<label for="constrain">Constrain:</label>
<input id="constrain" type="checkbox" ng-model="constrain"/>
<div ng-bind-html-unsafe="preview">
</div>
</div>
</div>
</div>
</div>

View File

@@ -11,7 +11,7 @@ angular.module("umbraco")
menubar : false,
statusbar: false,
height: 340,
toolbar: "bold italic | styleselect | alignleft aligncenter alignright | bullist numlist | outdent indent | link image mediapicker iconpicker",
toolbar: "bold italic | styleselect | alignleft aligncenter alignright | bullist numlist | outdent indent | link image mediapicker iconpicker embeddialog",
setup : function(editor) {
@@ -69,7 +69,20 @@ angular.module("umbraco")
editor.insertContent(i);
}});
}
});
});
editor.addButton('embeddialog', {
icon: 'media',
tooltip: 'Embed',
onclick: function () {
dialogService.embedDialog({
scope: $scope, callback: function (data) {
editor.insertContent(data);
}
});
}
});
}
});

View File

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using Umbraco.Core.Configuration;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi.Filters;
using Constants = Umbraco.Core.Constants;
using Umbraco.Core.Media;
using System.IO;
namespace Umbraco.Web.Editors
{
[PluginController("UmbracoApi")]
public class EmbedController : UmbracoAuthorizedJsonController
{
public Result Embed(string url, int width, int height)
{
var result = new Result();
//todo cache embed doc
var xmlConfig = new XmlDocument();
xmlConfig.Load(GlobalSettings.FullpathToRoot + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "EmbeddedMedia.config");
foreach (XmlNode node in xmlConfig.SelectNodes("//provider"))
{
var regexPattern = new Regex(node.SelectSingleNode("./urlShemeRegex").InnerText, RegexOptions.IgnoreCase);
if (regexPattern.IsMatch(url))
{
var prov = (IEmbedProvider)Activator.CreateInstance(Type.GetType(node.Attributes["type"].Value));
if (node.Attributes["supportsDimensions"] != null)
result.SupportsDimensions = node.Attributes["supportsDimensions"].Value == "True";
else
result.SupportsDimensions = prov.SupportsDimensions;
var settings = node.ChildNodes.Cast<XmlNode>().ToDictionary(settingNode => settingNode.Name);
foreach (var prop in prov.GetType().GetProperties().Where(prop => prop.IsDefined(typeof(ProviderSetting), true)))
{
if (settings.Any(s => s.Key.ToLower() == prop.Name.ToLower()))
{
var setting = settings.FirstOrDefault(s => s.Key.ToLower() == prop.Name.ToLower()).Value;
var settingType = typeof(Media.EmbedProviders.Settings.String);
if (setting.Attributes["type"] != null)
settingType = Type.GetType(setting.Attributes["type"].Value);
var settingProv = (IEmbedSettingProvider)Activator.CreateInstance(settingType);
prop.SetValue(prov, settingProv.GetSetting(settings.FirstOrDefault(s => s.Key.ToLower() == prop.Name.ToLower()).Value), null);
}
}
try
{
result.Markup = prov.GetMarkup(url, width, height);
result.Status = Status.Success;
}
catch
{
result.Status = Status.Error;
}
return result;
}
}
result.Status = Status.NotSupported;
return result;
}
}
}

View File

@@ -304,6 +304,7 @@
<Compile Include="Editors\DashboardController.cs" />
<Compile Include="Editors\DataTypeController.cs" />
<Compile Include="Editors\DataTypeValidateAttribute.cs" />
<Compile Include="Editors\EmbedController.cs" />
<Compile Include="Editors\EntityController.cs" />
<Compile Include="Editors\MediaPostValidateAttribute.cs" />
<Compile Include="Editors\UserController.cs" />