5 angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
7 .directive("egContextMenuItem", function () {
11 template: '<li ng-click="setContent(item.value,item.action)">{{label}}</li>',
13 controller: ['$scope','$element',
14 function ($scope , $element) {
15 if (!$scope.item.label) $scope.item.label = $scope.item.value;
16 if ($scope.item.divider) {
17 $element.style.borderTop = 'solid 1px';
20 $scope.setContent = function (v, a) {
21 if (a) { v = a($scope,v); }
22 $scope.$apply("item.value=v");
23 $( $($scope.element).parent() ).parent().empty().remove();
24 $scope.$parent.$destroy();
31 .directive("egMarcEditEditable", ['$document', function ($document) {
32 function showContext(event) {
33 event.preventDefault();
34 var con = event.data.scope.contextitems;
36 if (angular.isArray(con)) { // we have a list of values or transforms
38 '<div class="dropdown" dropdown is-open="true">'+
39 '<ul class="dropdown-menu" role="menu">'+
40 '<eg-context-menu-item ng-repeat="item in contextitems" item="item"/>'+
44 var el = $compile(tmpl)(event.data);
58 template: '<input style="font-family: \'Lucida Console\', Monaco, monospace;" ng-model="content" size="{{content.length * 1.1}}" maxlength="{{max}}" class="" type="text"/>',
66 // controller : ['$scope',
67 // function ( $scope ) {
68 // $scope.minsize = $scope.max || $scope.content.length;
69 // if (!$scope.contextitems) $scope.contextitems = {};
72 link: function (scope, element, attrs) {
74 element.bind('change', {}, function (e) { element.size = scope.max || scope.content.length * 1.1});
76 if (scope.contextitems && angular.isArray(scope.contextitems)) {
77 element.bind('context', { scope : scope, element : element }, showContext);
83 .directive("egMarcEditSubfield", function () {
87 '<span><eg-marc-edit-editable type="sfc" class="marcsfcode" content="subfield[0]" max="1"/></span>'+
88 '<span><eg-marc-edit-editable type="sfv" class="marcsfvalue" content="subfield[1]"/></span>'+
90 scope: { field: "=", subfield: "=" },
95 .directive("egMarcEditInd", function () {
98 template: '<span><eg-marc-edit-editable type="ind" content="ind" max="1"/></span>',
104 .directive("egMarcEditTag", function () {
107 template: '<span><eg-marc-edit-editable type="tag" content="tag" max="3"/></span>',
108 scope: { tag : '=' },
113 .directive("egMarcEditDatafield", function () {
117 '<span><eg-marc-edit-tag class="marctag" tag="field.tag"/></span>'+
118 '<span><eg-marc-edit-ind class="marcind" ind="field.ind1"/></span>'+
119 '<span><eg-marc-edit-ind class="marcind" ind="field.ind2"/></span>'+
120 '<span><eg-marc-edit-subfield ng-repeat="subfield in field.subfields" subfield="subfield" field="field"/></span>'+
122 scope: { field: "=" }
126 .directive("egMarcEditControlfield", function () {
130 '<span><eg-marc-edit-tag class="marctag" tag="field.tag"/></span>'+
131 '<span><eg-marc-edit-editable type="cfld" class="marcdata" content="field.data"/></span>'+
133 scope: { field: "=" }
137 .directive("egMarcEditLeader", function () {
141 '<span><eg-marc-edit-editable class="marctag" content="tag"/></span>'+
142 '<span><eg-marc-edit-editable class="marcdata" max="{{record.leader.length}}" content="record.leader"/></span>'+
144 controller : ['$scope',
145 function ( $scope ) {
149 scope: { record: "=" }
153 /// TODO: fixed field editor and such
154 .directive("egMarcEditRecord", function () {
156 template: '<form ng-submit="saveRecord()">'+
157 '<div class="marcrecord">'+
158 '<div><eg-marc-edit-leader record="record"/></div>'+
159 '<div><eg-marc-edit-controlfield ng-repeat="field in controlfields" field="field"/></div>'+
160 '<div><eg-marc-edit-datafield ng-repeat="field in datafields" field="field"/></div>'+
162 '<button class="btn btn-default" type="submit">Save</button>'+
164 '<button class="btn btn-default" ng-click="seeBreaker()">Breaker</button>',
167 scope: { recordId : '=' },
168 controller : ['$scope','egCore',
169 function ( $scope , egCore ) {
171 function loadRecord() {
172 return egCore.pcrud.retrieve(
173 'bre', $scope.recordId
174 ).then(function(rec) {
176 $scope.record = new MARC.Record();
177 $scope.record.fromXmlString( $scope.bre.marc() );
178 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
179 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
183 $scope.saveRecord = function () {
184 $scope.bre.marc($scope.record.toXmlString());
185 return egCore.pcrud.update(
190 $scope.seeBreaker = function () {
191 alert($scope.record.toBreaker());
194 $scope.$watch('recordId',
195 function(newVal, oldVal) {
196 if (newVal && newVal !== oldVal) {
203 $scope.controlfields = [];
204 $scope.datafields = [];