5 angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
7 .directive("egContextMenuItem", ['$timeout',function ($timeout) {
11 template: '<li><a ng-click="setContent(item.value,item.action)">{{item.label}}</a></li>',
12 scope: { item: '=', content: '=' },
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) {
22 if (a) replace_with = a($scope,$element,$scope.item.value,$scope.$parent.$parent.content);
24 $scope.$parent.$parent.$apply(function(){
25 $scope.$parent.$parent.content = replace_with
28 console.log('well, replaced it');
29 $($element).parent().css({display: 'none'});
36 .directive("egMarcEditEditable", ['$timeout', '$compile', '$document', function ($timeout, $compile, $document) {
41 template: '<input style="font-family: \'Lucida Console\', Monaco, monospace;" ng-model="content" size="{{content.length * 1.1}}" maxlength="{{max}}" class="" type="text"/>',
46 contextItemContainer: '@',
50 controller : ['$scope',
53 /* XXX Example, for testing. We'll get this from the tag-table services for realz
55 if (!$scope.contextItemContainer) {
56 $scope.contextItemContainer = "default_context";
57 $scope[$scope.contextItemContainer] = [
67 if ($scope.contextItemContainer)
68 $scope.item_container = $scope[$scope.contextItemContainer];
70 $scope.showContext = function (event) {
71 if ($scope.context_menu_element) {
72 console.log('Reshowing context menu...');
73 $($scope.context_menu_element).css({ display: 'block', top: event.pageY, left: event.pageX });
77 if (angular.isArray($scope.item_container)) { // we have a list of values or transforms
78 console.log('Showing context menu...');
81 '<ul class="dropdown-menu" role="menu">'+
82 '<eg-context-menu-item ng-repeat="item in item_container" item="item" content="content"/>'+
85 var tnode = angular.element(tmpl);
86 console.log('... got element ...');
88 $document.find('body').append(tnode);
89 console.log('... attached to DOM ...');
96 console.log('... displayed ...');
98 $scope.context_menu_element = tnode;
99 console.log('... captured for later ...');
101 $timeout(function() {
102 var e = $compile(tnode)($scope);
103 console.log('... compiled: ' + e);
114 link: function (scope, element, attrs) {
116 element.bind('change', function (e) { element.size = scope.max || parseInt(scope.content.length * 1.1) });
117 if (scope.contextItemContainer && angular.isArray(scope[scope.contextItemContainer]))
118 element.bind('contextmenu', scope.showContext);
123 .directive("egMarcEditSubfield", function () {
127 '<span><eg-marc-edit-editable type="sfc" class="marcsfcode" field="field" subfield="subfield" content="subfield[0]" max="1"/></span>'+
128 '<span><eg-marc-edit-editable type="sfv" class="marcsfvalue" field="field" subfield="subfield" content="subfield[1]"/></span>'+
130 scope: { field: "=", subfield: "=" },
135 .directive("egMarcEditInd", function () {
138 template: '<span><eg-marc-edit-editable type="ind" field="field" content="ind" max="1"/></span>',
139 scope: { ind : '=', field: '=' },
144 .directive("egMarcEditTag", function () {
147 template: '<span><eg-marc-edit-editable type="tag" field="field" content="tag" max="3"/></span>',
148 scope: { tag : '=', field: '=' },
153 .directive("egMarcEditDatafield", function () {
157 '<span><eg-marc-edit-tag class="marctag" field="field" tag="field.tag"/></span>'+
158 '<span><eg-marc-edit-ind class="marcind" field="field" ind="field.ind1"/></span>'+
159 '<span><eg-marc-edit-ind class="marcind" field="field" ind="field.ind2"/></span>'+
160 '<span><eg-marc-edit-subfield ng-repeat="subfield in field.subfields" subfield="subfield" field="field"/></span>'+
162 scope: { field: "=" }
166 .directive("egMarcEditControlfield", function () {
170 '<span><eg-marc-edit-tag class="marctag" field="field" tag="field.tag"/></span>'+
171 '<span><eg-marc-edit-editable type="cfld" field="field" class="marcdata" content="field.data"/></span>'+
173 scope: { field: "=" }
177 .directive("egMarcEditLeader", function () {
181 '<span><eg-marc-edit-editable class="marctag" content="tag"/></span>'+
182 '<span><eg-marc-edit-editable class="marcdata" type="ldr" max="{{record.leader.length}}" content="record.leader"/></span>'+
184 controller : ['$scope',
185 function ( $scope ) {
189 scope: { record: "=" }
193 /// TODO: fixed field editor and such
194 .directive("egMarcEditRecord", function () {
196 template: '<form ng-submit="saveRecord()">'+
197 '<div class="marcrecord">'+
198 '<div><eg-marc-edit-leader record="record"/></div>'+
199 '<div><eg-marc-edit-controlfield ng-repeat="field in controlfields" field="field"/></div>'+
200 '<div><eg-marc-edit-datafield ng-repeat="field in datafields" field="field"/></div>'+
202 '<button class="btn btn-default" type="submit">Save</button>'+
204 '<button class="btn btn-default" ng-click="seeBreaker()">Breaker</button>',
207 scope: { recordId : '=' },
208 controller : ['$scope','egCore',
209 function ( $scope , egCore ) {
211 function loadRecord() {
212 return egCore.pcrud.retrieve(
213 'bre', $scope.recordId
214 ).then(function(rec) {
216 $scope.record = new MARC.Record();
217 $scope.record.fromXmlString( $scope.bre.marc() );
218 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
219 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
223 $scope.saveRecord = function () {
224 $scope.bre.marc($scope.record.toXmlString());
225 return egCore.pcrud.update(
230 $scope.seeBreaker = function () {
231 alert($scope.record.toBreaker());
234 $scope.$watch('recordId',
235 function(newVal, oldVal) {
236 if (newVal && newVal !== oldVal) {
243 $scope.controlfields = [];
244 $scope.datafields = [];