This commit is contained in:
Per Ploug Krogslund
2013-08-26 10:02:35 +02:00
40 changed files with 598 additions and 290 deletions

View File

@@ -24,13 +24,13 @@ angular.module('umbraco.mocks').
{
label: "Custom pre value 1 for editor " + selectedId,
description: "Enter a value for this pre-value",
key: "myPreVal",
key: "myPreVal1",
view: "requiredfield"
},
{
label: "Custom pre value 2 for editor " + selectedId,
description: "Enter a value for this pre-value",
key: "myPreVal",
key: "myPreVal2",
view: "requiredfield"
}
]

View File

@@ -1,12 +1,12 @@
angular.module("umbraco")
.controller("My.MarkdownEditorController",
//inject umbracos assetsServce and dialog service
function ($scope,assetsService, dialogService) {
function ($scope, assetsService, dialogService, $log, imageHelper) {
//tell the assets service to load the markdown.editor libs from the markdown editors
//plugin folder
if($scope.model.value === null || $scope.model.value === ""){
if ($scope.model.value === null || $scope.model.value === "") {
$scope.model.value = $scope.model.config.defaultValue;
}
@@ -17,32 +17,27 @@ function ($scope,assetsService, dialogService) {
"/app_plugins/markdowneditor/lib/markdown.editor.js"
])
.then(function () {
//this function will execute when all dependencies have loaded
var converter2 = new Markdown.Converter();
var editor2 = new Markdown.Editor(converter2, "-" + $scope.model.alias);
editor2.run();
//subscribe to the image dialog clicks
editor2.hooks.set("insertImageDialog", function (callback) {
dialogService.mediaPicker({callback: function(data){
$(data.selection).each(function(i, item){
alert(item);
});
}});
//this function will execute when all dependencies have loaded
var converter2 = new Markdown.Converter();
var editor2 = new Markdown.Editor(converter2, "-" + $scope.model.alias);
editor2.run();
/*
setTimeout(function () {
var prompt = "We have detected that you like cats. Do you want to insert an image of a cat?";
if (confirm(prompt))
callback("http://icanhascheezburger.files.wordpress.com/2007/06/schrodingers-lolcat1.jpg")
else
callback(null);
}, 2000);
*/
//subscribe to the image dialog clicks
editor2.hooks.set("insertImageDialog", function (callback) {
dialogService.mediaPicker({ callback: function (data) {
$(data.selection).each(function (i, item) {
var imagePropVal = imageHelper.getImagePropertyVaue({ imageModel: item, scope: $scope });
callback(imagePropVal);
});
}
});
return true; // tell the editor that we'll take care of getting the image url
});
return true; // tell the editor that we'll take care of getting the image url
});
});
//load the seperat css for the editor to avoid it blocking our js loading TEMP HACK

View File

@@ -1,3 +1 @@
<input type="checkbox" ng-model="model.value" id="{{model.alias}" ng-true-value="True" ng-false-value="False" />
{{model | json}}
<input name="boolean" type="checkbox" ng-model="model.value" ng-true-value="1" ng-false-value="0" />

View File

@@ -0,0 +1 @@
<input name="hidden" type="hidden" ng-model="model.value" name="{{model.alias}" />

View File

@@ -1,9 +1,9 @@
<div>
<input name="requiredField" type="text" id="{{model.alias}}" class="umb-textstring span7 textstring"
<input name="requiredfield" type="text" class="umb-textstring span7 textstring"
ng-model="model.value"
required
val-server="value" />
<span class="help-inline" val-msg-for="requiredField" val-toggle-msg="required">Required</span>
<span class="help-inline" val-msg-for="requiredField" val-toggle-msg="valServer">{{propertyForm.requiredField.errorMsg}}</span>
<span class="help-inline" val-msg-for="requiredfield" val-toggle-msg="required">Required</span>
<span class="help-inline" val-msg-for="requiredfield" val-toggle-msg="valServer">{{propertyForm.requiredField.errorMsg}}</span>
</div>

View File

@@ -1 +1 @@
<textarea ng-model="model.value" rows="4" id="{{model.alias}}" class="span8"></textarea>
<textarea name="textarea" ng-model="model.value" rows="4" class="span8"></textarea>

View File

@@ -4,9 +4,7 @@ angular.module("umbraco").controller("Umbraco.Editors.DropdownController",
//setup the default config
var config = {
items: [],
multiple: false,
keyName: "alias",
valueName: "name"
multiple: false
};
//map the user config
@@ -14,25 +12,16 @@ angular.module("umbraco").controller("Umbraco.Editors.DropdownController",
//map back to the model
$scope.model.config = config;
$scope.selectExpression = "e." + config.keyName + " as e." + config.valueName + " for e in model.config.items";
//now we need to format the items in the array because we always want to have a dictionary
for (var i = 0; i < $scope.model.config.items.length; i++) {
if (angular.isString($scope.model.config.items[i])) {
//convert to key/value
var keyVal = {};
keyVal[$scope.model.config.keyName] = $scope.model.config.items[i];
keyVal[$scope.model.config.valueName] = $scope.model.config.items[i];
$scope.model.config.items[i] = keyVal;
}
else if (angular.isObject($scope.model.config.items[i])) {
if ($scope.model.config.items[i][$scope.model.config.keyName] === undefined || $scope.model.config.items[i][$scope.model.config.valueName] === undefined) {
throw "All objects in the items array must have a key with a name " + $scope.model.config.keyName + " and a value with a name " + $scope.model.config.valueName;
}
}
else {
throw "The items array must contain either a key value pair or a string";
if (angular.isArray($scope.model.config.items)) {
//now we need to format the items in the array because we always want to have a dictionary
var newItems = {};
for (var i = 0; i < $scope.model.config.items.length; i++) {
newItems[$scope.model.config.items[i]] = $scope.model.config.items[i];
}
$scope.model.config.items = newItems;
}
else if (!angular.isObject($scope.model.config.items)) {
throw "The items property must be either an array or a dictionary";
}
//now we need to check if the value is null/undefined, if it is we need to set it to "" so that any value that is set

View File

@@ -1,6 +1,19 @@
<div ng-controller="Umbraco.Editors.DropdownController">
<div ng-controller="Umbraco.Editors.DropdownController" ng-switch="model.config.multiple">
<select name="dropDownList"
ng-model="model.value"
ng-options="{{selectExpression}}"></select>
ng-switch-default
ng-model="model.value"
ng-options="key as val for (key, val) in model.config.items">
</select>
<!--NOTE: This ng-switch is required because ng-multiple doesn't actually support dynamic bindings with multi-select lists -->
<select name="dropDownList"
ng-switch-when="1"
multiple
ng-model="model.value"
ng-options="key as val for (key, val) in model.config.items">
</select>
</div>
{{model.value | json}}

View File

@@ -3,14 +3,31 @@ angular.module("umbraco").controller("Umbraco.Editors.DropdownPreValueController
$scope.newItem = "";
$scope.hasError = false;
if (!angular.isArray($scope.model.value)) {
//make an array from the dictionary
var items = [];
for (var i in $scope.model.value) {
items.push($scope.model.value[i]);
}
//now make the editor model the array
$scope.model.value = items;
}
$scope.remove = function(item, evt) {
evt.preventDefault();
$scope.model.value = _.reject($scope.model.value, function(i) {
$scope.model.value = _.reject($scope.model.value, function (i) {
return i === item;
});
//setup the dictionary from array
$scope.model.value = {};
for (var i = 0; i < $scope.model.value.length; i++) {
//just make the key the iteration
$scope.model.value[i] = $scope.model.value[i];
}
};
$scope.add = function (evt) {

View File

@@ -63,7 +63,7 @@ module.exports = function(karma) {
// level of logging
// possible values: karma.LOG_DISABLE || karma.LOG_ERROR || karma.LOG_WARN || karma.LOG_INFO || karma.LOG_DEBUG
// CLI --log-level debug
logLevel: karma.LOG_DEBUG,
logLevel: karma.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
// CLI --auto-watch --no-auto-watch

View File

@@ -22,8 +22,6 @@ describe('Drop down controller tests', function () {
expect(scope.model.config).toBeDefined();
expect(scope.model.config.items).toBeDefined();
expect(scope.model.config.multiple).toBeDefined();
expect(scope.model.config.keyName).toBeDefined();
expect(scope.model.config.valueName).toBeDefined();
});
it("should convert simple array to dictionary", function () {
@@ -39,14 +37,9 @@ describe('Drop down controller tests', function () {
$routeParams: routeParams
});
expect(scope.model.config.items.length).toBe(3);
for (var i = 0; i < scope.model.config.items.length; i++) {
expect(scope.model.config.items[i].alias).toBeDefined();
expect(scope.model.config.items[i].name).toBeDefined();
//name and alias will be the same in this case
expect(scope.model.config.items[i].alias).toBe("value" + i);
expect(scope.model.config.items[i].name).toBe("value" + i);
}
expect(scope.model.config.items["value0"]).toBe("value0");
expect(scope.model.config.items["value1"]).toBe("value1");
expect(scope.model.config.items["value2"]).toBe("value2");
});
@@ -54,11 +47,11 @@ describe('Drop down controller tests', function () {
scope.model = {
config: {
items: [
{ alias: "value0", name: "Value 0" },
{ alias: "value1", name: "Value 1" },
{ alias: "value2", name: "Value 2" }
]
items: {
"value0" : "Value 0",
"value1" : "Value 1",
"value2" : "Value 2"
}
}
};
@@ -73,15 +66,11 @@ describe('Drop down controller tests', function () {
});
it("should not allow an existing invalid dictionary", function () {
it("should not allow a non-array or non-dictionary", function () {
scope.model = {
config: {
items: [
{ blah: "value0", name: "Value 0" },
{ blah: "value1", name: "Value 1" },
{ blah: "value2", name: "Value 2" }
]
items: true
}
};