| author | ymh <ymh.work@gmail.com> |
| Sat, 07 Sep 2013 14:41:20 +0200 | |
| changeset 47 | b07f8d11f2b8 |
| parent 44 | 65912194e047 |
| child 49 | fcfa68f39f6b |
| permissions | -rw-r--r-- |
| 26 | 1 |
|
2 |
// initialize the app |
|
3 |
||
| 47 | 4 |
var app = angular.module("recordApp", ['ngResource', 'ngRoute', 'pascalprecht.translate']) |
| 26 | 5 |
|
|
33
945b144d68c1
put context variables in a single object
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
6 |
app.service("Api", function($resource, context) { |
| 47 | 7 |
this.record = $resource(context.urls.record_api, |
8 |
{}, |
|
9 |
{ |
|
10 |
get: { |
|
11 |
method: "GET", |
|
12 |
isArray: false |
|
13 |
}, |
|
14 |
save:{ |
|
15 |
method:"PUT", |
|
16 |
isArray:false, |
|
17 |
headers:{'X-CSRFToken':context.csrf_token} |
|
18 |
} |
|
19 |
}); |
|
| 26 | 20 |
}); |
21 |
||
|
33
945b144d68c1
put context variables in a single object
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
22 |
app.controller("RecordCtrl", function($scope, Api, context){ |
|
945b144d68c1
put context variables in a single object
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
23 |
$scope.record = Api.record.get({recordId: context.record_id}); |
| 34 | 24 |
$scope.uriLabels = context.uri_labels; |
| 35 | 25 |
|
26 |
$scope.addSubject = function() { |
|
27 |
$scope.record.subjects.push($scope.addSubjectText); |
|
28 |
$scope.addSubjectText = ''; |
|
29 |
}; |
|
30 |
|
|
| 38 | 31 |
$scope.updateUriLabelDict = function(k,v) { |
32 |
$scope.uriLabels[k] = v; |
|
33 |
}; |
|
| 47 | 34 |
|
35 |
$scope.submitRecord = function() { |
|
36 |
$scope.record.$save({recordId: context.record_id}); |
|
37 |
} |
|
| 38 | 38 |
|
| 44 | 39 |
$scope.removeSubject = function(uri) { |
40 |
i = $scope.record.subjects.indexOf(uri); |
|
41 |
if(i>=0){ |
|
42 |
$scope.record.subjects.splice(i, 1); |
|
43 |
} |
|
44 |
}; |
|
| 26 | 45 |
}); |
46 |
||
47 |
app.config(['$routeProvider', function($routeProvider) { |
|
48 |
// $routeProvider.when('/', {controller: 'RecordCtrl', templateUrl: 'partials/record.html'}); |
|
49 |
// $routeProvider.otherwise({redirectTo: '/'}); |
|
50 |
}]); |
|
|
28
f26426e9360b
update view simplification. Baby step towards complete form.
ymh <ymh.work@gmail.com>
parents:
26
diff
changeset
|
51 |