Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pve-manager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
pve-manager
Commits
36be2857
Commit
36be2857
authored
Jan 08, 2015
by
Dietmar Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup json object reader
Try to make it a generic usable class.
parent
019434e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
24 deletions
+58
-24
PendingObjectStore.js
www/manager/data/PendingObjectStore.js
+1
-1
JsonObject.js
www/manager/data/reader/JsonObject.js
+57
-23
No files found.
www/manager/data/PendingObjectStore.js
View file @
36be2857
...
...
@@ -19,7 +19,7 @@ Ext.define('PVE.data.PendingObjectStore', {
reader
:
{
type
:
'
jsonobject
'
,
rows
:
config
.
rows
,
pending
:
1
readArray
:
true
}
}
});
...
...
www/manager/data/reader/JsonObject.js
View file @
36be2857
/* A reader to store a single JSON Object (hash) into a storage.
* Also accepts an array containing a single hash.
*
* So it can read:
*
* example1: { data: "xyz" }
* example2: [ { data: "xyz" } ]
* example1: {data1: "xyz", data2: "abc"}
* returns [{key: "data1", value: "xyz"}, {key: "data2", value: "abc"}]
*
* example2: [ {data1: "xyz", data2: "abc"} ]
* returns [{key: "data1", value: "xyz"}, {key: "data2", value: "abc"}]
*
* If you set 'readArray', the reader expexts the object as array:
*
* example3: [ { key: "data1", value: "xyz", p2: "cde" }, { key: "data2", value: "abc", p2: "efg" }]
* returns [{key: "data1", value: "xyz", p2: "cde}, {key: "data2", value: "abc", p2: "efg"}]
*
* Note: The records can contain additional properties (like 'p2' above) when you use 'readArray'
*
* Additional feature: specify allowed properties with default values with 'rows' object
*
* var rows = {
* memory: {
* required: true,
* defaultValue: 512
* }
* }
*
*/
Ext
.
define
(
'
PVE.data.reader.JsonObject
'
,
{
...
...
@@ -11,7 +32,11 @@ Ext.define('PVE.data.reader.JsonObject', {
alias
:
'
reader.jsonobject
'
,
root
:
'
data
'
,
readArray
:
false
,
rows
:
undefined
,
constructor
:
function
(
config
)
{
var
me
=
this
;
...
...
@@ -27,39 +52,49 @@ Ext.define('PVE.data.reader.JsonObject', {
try
{
var
result
=
Ext
.
decode
(
response
.
responseText
);
var
root
=
me
.
getRoot
(
result
);
var
org_root
=
root
;
if
(
Ext
.
isArray
(
org_root
))
{
if
(
org_root
.
length
==
1
)
{
root
=
org_root
[
0
];
}
else
{
root
=
{};
}
}
if
(
me
.
readArray
)
{
if
(
me
.
pending
)
{
var
rec_hash
=
{};
Ext
.
Array
.
each
(
root
,
function
(
rec
)
{
if
(
Ext
.
isDefined
(
rec
.
key
))
{
rec_hash
[
rec
.
key
]
=
rec
;
}
});
if
(
me
.
rows
)
{
Ext
.
Object
.
each
(
me
.
rows
,
function
(
key
,
rowdef
)
{
if
(
Ext
.
isDefined
(
root
[
key
]))
{
if
(
Ext
.
isDefined
(
root
[
key
][
"
value
"
])){
data
.
push
({
key
:
key
,
value
:
root
[
key
][
"
value
"
],
pending
:
root
[
key
][
"
pending
"
],
delete
:
root
[
key
][
"
delete
"
]});
}
else
if
(
Ext
.
isDefined
(
rowdef
.
defaultValue
)){
data
.
push
({
key
:
key
,
value
:
rowdef
.
defaultValue
,
pending
:
root
[
key
][
"
pending
"
],
delete
:
root
[
key
][
"
delete
"
]});
var
rec
=
rec_hash
[
key
];
if
(
Ext
.
isDefined
(
rec
))
{
if
(
!
Ext
.
isDefined
(
rec
.
value
))
{
rec
.
value
=
rowdef
.
defaultValue
;
}
data
.
push
(
rec
);
}
else
if
(
Ext
.
isDefined
(
rowdef
.
defaultValue
))
{
data
.
push
({
key
:
key
,
value
:
rowdef
.
defaultValue
,
pending
:
undefined
,
delete
:
undefined
}
);
data
.
push
({
key
:
key
,
value
:
rowdef
.
defaultValue
}
);
}
else
if
(
rowdef
.
required
)
{
data
.
push
({
key
:
key
,
value
:
undefined
,
pending
:
undefined
,
delete
:
undefined
});
data
.
push
({
key
:
key
,
value
:
undefined
});
}
});
}
else
{
Ext
.
Object
.
each
(
root
,
function
(
key
,
value
)
{
data
.
push
({
key
:
key
,
value
:
root
[
key
][
"
value
"
],
pending
:
root
[
key
][
"
pending
"
],
delete
:
root
[
key
][
"
delete
"
]});
Ext
.
Array
.
each
(
root
,
function
(
rec
)
{
if
(
Ext
.
isDefined
(
rec
.
key
))
{
data
.
push
(
rec
);
}
});
}
}
else
{
var
org_root
=
root
;
}
else
{
if
(
Ext
.
isArray
(
org_root
))
{
if
(
root
.
length
==
1
)
{
root
=
org_root
[
0
];
}
else
{
root
=
{};
}
}
if
(
me
.
rows
)
{
Ext
.
Object
.
each
(
me
.
rows
,
function
(
key
,
rowdef
)
{
...
...
@@ -77,7 +112,6 @@ Ext.define('PVE.data.reader.JsonObject', {
});
}
}
}
catch
(
ex
)
{
Ext
.
Error
.
raise
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment