Revision 34748
Added by Michele Artini over 9 years ago
modules/dnet-information-service/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/is/IsAjaxController.java | ||
---|---|---|
93 | 93 |
@RequestMapping("updateDs.do") |
94 | 94 |
public @ResponseBody |
95 | 95 |
String updateDs( |
96 |
@RequestParam(value = "id", required = false) final String id,
|
|
96 |
@RequestParam(value = "id", required = true) final String id,
|
|
97 | 97 |
@RequestParam(value = "name", required = false) final String name, |
98 | 98 |
@RequestParam(value = "description", required = false) final String description, |
99 | 99 |
@RequestParam(value = "content", required = false) final String content) throws Exception { |
modules/dnet-information-service/trunk/src/main/resources/eu/dnetlib/web/resources/html/is_templates/ds.html | ||
---|---|---|
2 | 2 |
<div class="col-xs-12" ng-hide="resource && resource.id"> |
3 | 3 |
<div class="well">Missing resource !!!</div> |
4 | 4 |
</div> |
5 |
|
|
6 |
|
|
5 |
{{modes}} |
|
7 | 6 |
<div class="col-xs-12" ng-show="resource && resource.id"> |
8 |
<p> |
|
9 |
<b>D-Net ID:</b> <i>{{resource.id}}</i><br /> |
|
10 |
<b>Code:</b> <i>{{resource.code}}</i><br /> |
|
11 |
<b>Type:</b> <i>{{resource.type}}</i><br /> |
|
12 |
<b>Creation date:</b> <i>{{resource.date | date:'yyyy-MM-dd HH:mm:ss'}}</i><br /> |
|
13 |
|
|
14 |
<b>Content Ready:</b> {{isContentReady}} |
|
15 |
</p> |
|
16 |
|
|
17 |
<form class="form-vertical" style="margin-top: 30px"> |
|
7 |
<form class="form-horizontal" style="margin-top: 30px"> |
|
18 | 8 |
<div class="form-group"> |
19 |
<label for="inputName">Name</label> |
|
20 |
<input class="form-control" id="inputName" placeholder="Name" ng-model="resource.name"> |
|
9 |
<label class="col-sm-2 control-label">D-Net ID</label> |
|
10 |
<div class="col-sm-9"> |
|
11 |
<p class="form-control-static">{{resource.id}}</p> |
|
12 |
</div> |
|
13 |
</div> |
|
14 |
<div class="form-group"> |
|
15 |
<label class="col-sm-2 control-label">Code</label> |
|
16 |
<div class="col-sm-9"> |
|
17 |
<p class="form-control-static">{{resource.code}}</p> |
|
18 |
</div> |
|
19 |
</div> |
|
20 |
<div class="form-group"> |
|
21 |
<label class="col-sm-2 control-label">Type</label> |
|
22 |
<div class="col-sm-9"> |
|
23 |
<p class="form-control-static">{{resource.type}}</p> |
|
24 |
</div> |
|
25 |
</div> |
|
26 |
<div class="form-group"> |
|
27 |
<label class="col-sm-2 control-label">Creation date</label> |
|
28 |
<div class="col-sm-9"> |
|
29 |
<p class="form-control-static">{{resource.date | date:'yyyy-MM-dd HH:mm:ss'}}</p> |
|
30 |
</div> |
|
21 | 31 |
</div> |
22 | 32 |
<div class="form-group"> |
23 |
<label for="inputDesc">Description</label> |
|
24 |
<textarea id="inputDesc" class="form-control" rows="5" placeholder="Description" ng-model="resource.description"></textarea> |
|
33 |
<label class="col-sm-2 control-label" for="inputName">Name</label> |
|
34 |
<div class="col-sm-9"> |
|
35 |
<input class="form-control" id="inputName" placeholder="Name" ng-model="resource.name"> |
|
36 |
</div> |
|
37 |
</div> |
|
38 |
<div class="form-group"> |
|
39 |
<label class="col-sm-2 control-label" for="inputDesc">Description</label> |
|
40 |
<div class="col-sm-9"> |
|
41 |
<textarea id="inputDesc" class="form-control" rows="5" placeholder="Description" ng-model="resource.description"></textarea> |
|
42 |
</div> |
|
25 | 43 |
</div> |
26 |
<button type="button" class="btn btn-sm btn-primary" ng-click="updateResource()">Save</button> |
|
27 |
<button type="button" class="btn btn-sm btn-default" data-toggle="modal" data-target="#contentModal" ng-click="setupEditContent()">Show/edit content</button> |
|
28 |
<button type="button" class="btn btn-sm btn-default" ng-click="getResource(resource.id)">Reset</button> |
|
29 |
<button type="submit" class="btn btn-sm btn-danger pull-right" ng-click="deleteResource()">Delete</button> |
|
44 |
<div class="form-group"> |
|
45 |
<div class="col-sm-offset-2 col-sm-9"> |
|
46 |
<button type="button" class="btn btn-sm btn-primary" ng-click="saveInfo()">Save</button> |
|
47 |
<button type="button" class="btn btn-sm btn-default" data-toggle="modal" data-target="#contentModal" ng-click="setupEditContent()">Show/edit content</button> |
|
48 |
<button type="button" class="btn btn-sm btn-default" ng-click="getResource(resource.id)">Reset</button> |
|
49 |
<button type="submit" class="btn btn-sm btn-danger pull-right" ng-click="deleteResource()">Delete</button> |
|
50 |
</div> |
|
51 |
</div> |
|
30 | 52 |
</form> |
31 | 53 |
</div> |
32 | 54 |
</div> |
... | ... | |
40 | 62 |
</div> |
41 | 63 |
<div ui-codemirror ui-codemirror-opts="editorOptions" ng-model="parsedContent"></div> |
42 | 64 |
<div class="modal-footer" style="margin-top: 0px"> |
43 |
<button class="btn btn-primary" data-dismiss="modal">Done</button> |
|
44 | 65 |
<button class="btn btn-default" data-dismiss="modal">Close</button> |
66 |
<button class="btn btn-primary" ng-click="saveContent()">Save</button> |
|
45 | 67 |
</div> |
46 | 68 |
</div> |
47 | 69 |
</div> |
modules/dnet-information-service/trunk/src/main/resources/eu/dnetlib/web/resources/js/is_controllers.js | ||
---|---|---|
59 | 59 |
$scope.editorOptions = { |
60 | 60 |
lineWrapping : true, |
61 | 61 |
lineNumbers: true, |
62 |
mode: 'javascript' |
|
62 |
mode: { |
|
63 |
name: "javascript", |
|
64 |
json: true |
|
65 |
} |
|
63 | 66 |
}; |
64 | 67 |
|
65 | 68 |
$scope.showSpinner(); |
66 | 69 |
$scope.getResource = function(id) { |
67 | 70 |
if (id) { |
71 |
$scope.showSpinner(); |
|
68 | 72 |
$http.get('ajax_is/getDs.do?id=' + id).success(function(data) { |
69 | 73 |
$scope.hideSpinner(); |
70 | 74 |
$scope.resource = data; |
75 |
$scope.parsedContent = ''; |
|
71 | 76 |
}).error(function() { |
72 | 77 |
$scope.showError('Error retrieving ds'); |
73 | 78 |
$scope.hideSpinner(); |
... | ... | |
77 | 82 |
|
78 | 83 |
$scope.setupEditContent = function () { |
79 | 84 |
$timeout(function() { |
80 |
if ($scope.format == 'JSON') { |
|
81 |
$scope.parsedContent = JSON.stringify(JSON.parse($scope.resource.content),null,2); |
|
82 |
} else if ($scope.format == 'XML') { |
|
83 |
|
|
84 |
} else { |
|
85 |
try { |
|
86 |
if ($scope.format == 'JSON') { |
|
87 |
$scope.editorOptions.mode = { name: "javascript", json: true }; |
|
88 |
$scope.parsedContent = JSON.stringify(JSON.parse($scope.resource.content),null,2); |
|
89 |
} else if ($scope.format == 'XML') { |
|
90 |
$scope.editorOptions.mode = 'xml'; |
|
91 |
$scope.parsedContent = $scope.resource.content; |
|
92 |
} else { |
|
93 |
$scope.editorOptions.mode = null; |
|
94 |
$scope.parsedContent = $scope.resource.content; |
|
95 |
} |
|
96 |
} catch(err) { |
|
97 |
$scope.showError('Error parsing content (' + $scope.format + ')'); |
|
85 | 98 |
$scope.parsedContent = $scope.resource.content; |
86 | 99 |
} |
87 | 100 |
}, 1000); |
... | ... | |
102 | 115 |
} |
103 | 116 |
} |
104 | 117 |
|
105 |
$scope.updateResource = function() { |
|
118 |
$scope.saveContent = function() { |
|
119 |
try { |
|
120 |
if ($scope.format == 'JSON') { |
|
121 |
$scope.saveDs({ |
|
122 |
'id' : $scope.resource.id, |
|
123 |
'content' : JSON.stringify(JSON.parse($scope.parsedContent)) |
|
124 |
}); |
|
125 |
} else { |
|
126 |
$scope.saveDs({ |
|
127 |
'id' : $scope.resource.id, |
|
128 |
'content' : $scope.parsedContent |
|
129 |
}); |
|
130 |
} |
|
131 |
} catch(err) { |
|
132 |
$scope.showError('ERROR: Invalid content (' + $scope.format + ')'); |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
$scope.saveInfo = function() { |
|
137 |
$scope.saveDs({ |
|
138 |
'id' : $scope.resource.id, |
|
139 |
'name' : $scope.resource.name, |
|
140 |
'description' : $scope.resource.description |
|
141 |
}); |
|
142 |
} |
|
143 |
|
|
144 |
$scope.saveDs = function(map) { |
|
106 | 145 |
$scope.showSpinner(); |
107 | 146 |
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"; |
108 |
$http.post('ajax_is/updateProfile.do', $.param({ |
|
109 |
'profile' : $scope.editProfile |
|
110 |
})).success(function(data) { |
|
147 |
$http.post('ajax_is/updateDs.do', $.param(map)).success(function(data) { |
|
111 | 148 |
$scope.hideSpinner(); |
112 | 149 |
$scope.showNotification('Resource updated !'); |
150 |
if (map.content) { |
|
151 |
$('#contentModal').modal('hide'); |
|
152 |
} |
|
153 |
$scope.getResource($scope.resource.id); |
|
113 | 154 |
}).error(function(err) { |
114 | 155 |
$scope.showError(err.message); |
115 | 156 |
$scope.hideSpinner(); |
Also available in: Unified diff
ds editor