Replace angular.fromJson with JSON.parse (#7952)
This commit is contained in:
+2
-2
@@ -39,7 +39,7 @@ angular.module("umbraco.directives")
|
||||
|
||||
function stringToJson(text) {
|
||||
try {
|
||||
return angular.fromJson(text);
|
||||
return JSON.parse(text);
|
||||
} catch (err) {
|
||||
setInvalid();
|
||||
return text;
|
||||
@@ -55,7 +55,7 @@ angular.module("umbraco.directives")
|
||||
function isValidJson(model) {
|
||||
var flag = true;
|
||||
try {
|
||||
angular.fromJson(model);
|
||||
JSON.parse(model)
|
||||
} catch (err) {
|
||||
flag = false;
|
||||
}
|
||||
|
||||
@@ -1,113 +1,113 @@
|
||||
angular.module('umbraco.mocks').
|
||||
factory('dataTypeMocks', ['$httpBackend', 'mocksUtils', function ($httpBackend, mocksUtils) {
|
||||
'use strict';
|
||||
|
||||
function returnById(status, data, headers) {
|
||||
factory('dataTypeMocks', ['$httpBackend', 'mocksUtils', function ($httpBackend, mocksUtils) {
|
||||
'use strict';
|
||||
|
||||
if (!mocksUtils.checkAuth()) {
|
||||
return [401, null, null];
|
||||
}
|
||||
function returnById(status, data, headers) {
|
||||
|
||||
var id = mocksUtils.getParameterByName(data, "id") || 1234;
|
||||
if (!mocksUtils.checkAuth()) {
|
||||
return [401, null, null];
|
||||
}
|
||||
|
||||
var selectedId = String.CreateGuid();
|
||||
var id = mocksUtils.getParameterByName(data, "id") || 1234;
|
||||
|
||||
var dataType = mocksUtils.getMockDataType(id, selectedId);
|
||||
|
||||
return [200, dataType, null];
|
||||
}
|
||||
|
||||
function returnEmpty(status, data, headers) {
|
||||
var selectedId = String.CreateGuid();
|
||||
|
||||
if (!mocksUtils.checkAuth()) {
|
||||
return [401, null, null];
|
||||
}
|
||||
var dataType = mocksUtils.getMockDataType(id, selectedId);
|
||||
|
||||
var response = returnById(200, "", null);
|
||||
var node = response[1];
|
||||
return [200, dataType, null];
|
||||
}
|
||||
|
||||
node.name = "";
|
||||
node.selectedEditor = "";
|
||||
node.id = 0;
|
||||
node.preValues = [];
|
||||
function returnEmpty(status, data, headers) {
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
function returnPreValues(status, data, headers) {
|
||||
if (!mocksUtils.checkAuth()) {
|
||||
return [401, null, null];
|
||||
}
|
||||
|
||||
if (!mocksUtils.checkAuth()) {
|
||||
return [401, null, null];
|
||||
}
|
||||
var response = returnById(200, "", null);
|
||||
var node = response[1];
|
||||
|
||||
var editorId = mocksUtils.getParameterByName(data, "editorId") || "83E9AD36-51A7-4440-8C07-8A5623AC6979";
|
||||
node.name = "";
|
||||
node.selectedEditor = "";
|
||||
node.id = 0;
|
||||
node.preValues = [];
|
||||
|
||||
var preValues = [
|
||||
{
|
||||
label: "Custom pre value 1 for editor " + editorId,
|
||||
description: "Enter a value for this pre-value",
|
||||
key: "myPreVal",
|
||||
view: "requiredfield",
|
||||
validation: [
|
||||
{
|
||||
type: "Required"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: "Custom pre value 2 for editor " + editorId,
|
||||
description: "Enter a value for this pre-value",
|
||||
key: "myPreVal",
|
||||
view: "requiredfield",
|
||||
validation: [
|
||||
{
|
||||
type: "Required"
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
return [200, preValues, null];
|
||||
}
|
||||
|
||||
function returnSave(status, data, headers) {
|
||||
if (!mocksUtils.checkAuth()) {
|
||||
return [401, null, null];
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
var postedData = angular.fromJson(headers);
|
||||
function returnPreValues(status, data, headers) {
|
||||
|
||||
var dataType = mocksUtils.getMockDataType(postedData.id, postedData.selectedEditor);
|
||||
dataType.notifications = [{
|
||||
header: "Saved",
|
||||
message: "Data type saved",
|
||||
type: 0
|
||||
}];
|
||||
if (!mocksUtils.checkAuth()) {
|
||||
return [401, null, null];
|
||||
}
|
||||
|
||||
return [200, dataType, null];
|
||||
}
|
||||
var editorId = mocksUtils.getParameterByName(data, "editorId") || "83E9AD36-51A7-4440-8C07-8A5623AC6979";
|
||||
|
||||
return {
|
||||
register: function() {
|
||||
|
||||
$httpBackend
|
||||
.whenPOST(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/PostSave'))
|
||||
.respond(returnSave);
|
||||
|
||||
$httpBackend
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetById'))
|
||||
.respond(returnById);
|
||||
|
||||
$httpBackend
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetEmpty'))
|
||||
.respond(returnEmpty);
|
||||
|
||||
$httpBackend
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetPreValues'))
|
||||
.respond(returnPreValues);
|
||||
},
|
||||
expectGetById: function() {
|
||||
$httpBackend
|
||||
.expectGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetById'));
|
||||
}
|
||||
};
|
||||
}]);
|
||||
var preValues = [
|
||||
{
|
||||
label: "Custom pre value 1 for editor " + editorId,
|
||||
description: "Enter a value for this pre-value",
|
||||
key: "myPreVal",
|
||||
view: "requiredfield",
|
||||
validation: [
|
||||
{
|
||||
type: "Required"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: "Custom pre value 2 for editor " + editorId,
|
||||
description: "Enter a value for this pre-value",
|
||||
key: "myPreVal",
|
||||
view: "requiredfield",
|
||||
validation: [
|
||||
{
|
||||
type: "Required"
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
return [200, preValues, null];
|
||||
}
|
||||
|
||||
function returnSave(status, data, headers) {
|
||||
if (!mocksUtils.checkAuth()) {
|
||||
return [401, null, null];
|
||||
}
|
||||
|
||||
var postedData = JSON.parse(headers);
|
||||
|
||||
var dataType = mocksUtils.getMockDataType(postedData.id, postedData.selectedEditor);
|
||||
dataType.notifications = [{
|
||||
header: "Saved",
|
||||
message: "Data type saved",
|
||||
type: 0
|
||||
}];
|
||||
|
||||
return [200, dataType, null];
|
||||
}
|
||||
|
||||
return {
|
||||
register: function () {
|
||||
|
||||
$httpBackend
|
||||
.whenPOST(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/PostSave'))
|
||||
.respond(returnSave);
|
||||
|
||||
$httpBackend
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetById'))
|
||||
.respond(returnById);
|
||||
|
||||
$httpBackend
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetEmpty'))
|
||||
.respond(returnEmpty);
|
||||
|
||||
$httpBackend
|
||||
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetPreValues'))
|
||||
.respond(returnPreValues);
|
||||
},
|
||||
expectGetById: function () {
|
||||
$httpBackend
|
||||
.expectGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetById'));
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
||||
@@ -206,7 +206,7 @@ function umbSessionStorage($window) {
|
||||
return {
|
||||
|
||||
get: function (key) {
|
||||
return angular.fromJson(storage["umb_" + key]);
|
||||
return JSON.parse(storage["umb_" + key]);
|
||||
},
|
||||
|
||||
set: function (key, value) {
|
||||
|
||||
+8
-8
@@ -8,9 +8,9 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi
|
||||
$scope.noMacroParams = false;
|
||||
|
||||
function onInit() {
|
||||
if(!$scope.model.title) {
|
||||
localizationService.localize("defaultdialogs_selectMacro").then(function(value){
|
||||
$scope.model.title = value;
|
||||
if (!$scope.model.title) {
|
||||
localizationService.localize("defaultdialogs_selectMacro").then(function (value) {
|
||||
$scope.model.title = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,8 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi
|
||||
}
|
||||
};
|
||||
|
||||
$scope.close = function() {
|
||||
if($scope.model.close) {
|
||||
$scope.close = function () {
|
||||
if ($scope.model.close) {
|
||||
$scope.model.close();
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
$scope.wizardStep = "paramSelect";
|
||||
$scope.model.macroParams = data;
|
||||
|
||||
@@ -71,7 +71,7 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi
|
||||
if (val.detectIsJson()) {
|
||||
try {
|
||||
//Parse it to json
|
||||
prop.value = angular.fromJson(val);
|
||||
prop.value = JSON.parse(val);
|
||||
}
|
||||
catch (e) {
|
||||
// not json
|
||||
@@ -110,7 +110,7 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi
|
||||
|
||||
//if 'allowedMacros' is specified, we need to filter
|
||||
if (Utilities.isArray($scope.model.dialogData.allowedMacros) && $scope.model.dialogData.allowedMacros.length > 0) {
|
||||
$scope.macros = _.filter(data, function(d) {
|
||||
$scope.macros = _.filter(data, function (d) {
|
||||
return _.contains($scope.model.dialogData.allowedMacros, d.alias);
|
||||
});
|
||||
}
|
||||
|
||||
+14
-14
@@ -76,7 +76,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
/**
|
||||
* Performs the initialization of this component
|
||||
*/
|
||||
function onInit () {
|
||||
function onInit() {
|
||||
|
||||
if (vm.showLanguageSelector) {
|
||||
// load languages
|
||||
@@ -96,7 +96,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
if (vm.treeAlias === "content") {
|
||||
vm.entityType = "Document";
|
||||
if (!$scope.model.title) {
|
||||
localizationService.localize("defaultdialogs_selectContent").then(function(value){
|
||||
localizationService.localize("defaultdialogs_selectContent").then(function (value) {
|
||||
$scope.model.title = value;
|
||||
});
|
||||
}
|
||||
@@ -104,7 +104,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
else if (vm.treeAlias === "documentTypes") {
|
||||
vm.entityType = "DocumentType";
|
||||
if (!$scope.model.title) {
|
||||
localizationService.localize("defaultdialogs_selectContentType").then(function(value){
|
||||
localizationService.localize("defaultdialogs_selectContentType").then(function (value) {
|
||||
$scope.model.title = value;
|
||||
});
|
||||
}
|
||||
@@ -112,7 +112,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
else if (vm.treeAlias === "member" || vm.section === "member") {
|
||||
vm.entityType = "Member";
|
||||
if (!$scope.model.title) {
|
||||
localizationService.localize("defaultdialogs_selectMember").then(function(value) {
|
||||
localizationService.localize("defaultdialogs_selectMember").then(function (value) {
|
||||
$scope.model.title = value;
|
||||
});
|
||||
}
|
||||
@@ -120,7 +120,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
else if (vm.treeAlias === "memberTypes") {
|
||||
vm.entityType = "MemberType";
|
||||
if (!$scope.model.title) {
|
||||
localizationService.localize("defaultdialogs_selectMemberType").then(function(value){
|
||||
localizationService.localize("defaultdialogs_selectMemberType").then(function (value) {
|
||||
$scope.model.title = value;
|
||||
});
|
||||
}
|
||||
@@ -128,7 +128,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
else if (vm.treeAlias === "media" || vm.section === "media") {
|
||||
vm.entityType = "Media";
|
||||
if (!$scope.model.title) {
|
||||
localizationService.localize("defaultdialogs_selectMedia").then(function(value){
|
||||
localizationService.localize("defaultdialogs_selectMedia").then(function (value) {
|
||||
$scope.model.title = value;
|
||||
});
|
||||
}
|
||||
@@ -136,7 +136,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
else if (vm.treeAlias === "mediaTypes") {
|
||||
vm.entityType = "MediaType";
|
||||
if (!$scope.model.title) {
|
||||
localizationService.localize("defaultdialogs_selectMediaType").then(function(value){
|
||||
localizationService.localize("defaultdialogs_selectMediaType").then(function (value) {
|
||||
$scope.model.title = value;
|
||||
});
|
||||
}
|
||||
@@ -189,7 +189,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
if ($scope.model.filter.startsWith("{")) {
|
||||
$scope.model.filterAdvanced = true;
|
||||
//convert to object
|
||||
$scope.model.filter = angular.fromJson($scope.model.filter);
|
||||
$scope.model.filter = JSON.parse($scope.model.filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,7 +218,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
}
|
||||
|
||||
var queryString = $.param(queryParams); //create the query string from the params object
|
||||
|
||||
|
||||
if (!queryString) {
|
||||
vm.customTreeParams = $scope.model.customTreeParams;
|
||||
}
|
||||
@@ -243,7 +243,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
$timeout(function () {
|
||||
//reload the tree with it's updated querystring args
|
||||
vm.dialogTreeApi.load(vm.section).then(function () {
|
||||
|
||||
|
||||
//create the list of promises
|
||||
var promises = [];
|
||||
for (var i = 0; i < expandedPaths.length; i++) {
|
||||
@@ -258,7 +258,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
function toggleLanguageSelector() {
|
||||
vm.languageSelectorIsOpen = !vm.languageSelectorIsOpen;
|
||||
};
|
||||
|
||||
|
||||
function nodeExpandedHandler(args) {
|
||||
|
||||
//store the reference to the expanded node path
|
||||
@@ -673,17 +673,17 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
|
||||
}
|
||||
|
||||
function submit(model) {
|
||||
if($scope.model.submit) {
|
||||
if ($scope.model.submit) {
|
||||
$scope.model.submit(model);
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
if($scope.model.close) {
|
||||
if ($scope.model.close) {
|
||||
$scope.model.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//initialize
|
||||
onInit();
|
||||
|
||||
|
||||
@@ -1572,7 +1572,7 @@ angular.module('ngMockE2E', ['ng']).config(function ($provide) {
|
||||
*
|
||||
* // adds a new phone to the phones array
|
||||
* $httpBackend.whenPOST('/phones').respond(function(method, url, data) {
|
||||
* phones.push(angular.fromJSON(data));
|
||||
* phones.push(JSON.parse(data));
|
||||
* });
|
||||
* $httpBackend.whenGET(/^\/templates\//).passThrough();
|
||||
* //...
|
||||
|
||||
Reference in New Issue
Block a user