3 function ObjectsPerspective(options){
5 var old_callback = options.callback;
7 options.callback = function(){
10 self.$tag_name = $('#objects-editor #tag-name');
11 self.$objects_list = $('#objects-editor #objects-list');
18 if (!CurrentDocument.readonly) {
19 self.ias = $('#objects-editor img.area-selectable').imgAreaSelect({ handles: true, onSelectEnd: self._fillCoords(self), instance: true });
20 $('#objects-editor #add').click(self._addObject(self));
22 $('.delete', self.$objects_list).live('click', function() {
23 $(this).prev().trigger('click');
24 if (window.confirm("Czy na pewno chcesz usunąć ten obiekt?")) {
25 $(this).prev().remove();
28 self._resetSelection();
33 $('.image-object', self.$objects_list).live('click', function(){
34 $('.active', self.$objects_list).removeClass('active');
35 $(this).addClass('active');
36 var coords = $(this).data('coords');
38 self.ias.setSelection.apply(self.ias, coords);
39 self.ias.setOptions({ show: true });
42 self._resetSelection();
46 old_callback.call(this);
49 $.wiki.Perspective.call(this, options);
52 ObjectsPerspective.prototype = new $.wiki.Perspective();
54 ObjectsPerspective.prototype.freezeState = function(){
58 ObjectsPerspective.prototype._resetSelection = function() {
60 self.x1 = self.x2 = self.y1 = self.y2 = null;
61 self.ias.setOptions({ hide: true });
65 ObjectsPerspective.prototype._push = function(name, x1, y1, x2, y2) {
66 var $e = $('<span class="image-object"></span>')
69 $e.data('coords', [x1, y1, x2, y2]);
70 this.$objects_list.append($e);
71 this.$objects_list.append('<span class="delete">(x)</span>');
75 ObjectsPerspective.prototype._addObject = function(self) {
78 chunks = self.$tag_name.val().split(',');
80 item = chunks[i].trim();
83 outputs.push(item.trim());
85 output = outputs.join(', ');
87 self._push(output, self.x1, self.y1, self.x2, self.y2);
88 self._resetSelection();
92 ObjectsPerspective.prototype._fillCoords = function(self) {
93 return function(img, selection) {
94 $('.active', self.$objects_list).removeClass('active');
95 if (selection.x1 != selection.x2 && selection.y1 != selection.y2) {
96 self.x1 = selection.x1;
97 self.x2 = selection.x2;
98 self.y1 = selection.y1;
99 self.y2 = selection.y2;
102 self.x1 = self.x2 = self.y1 = self.y2 = null;
107 ObjectsPerspective.prototype.onEnter = function(success, failure){
109 this.$objects_list.children().remove();
111 $.each(this.doc.getImageItems('obiekt'), function(i, e) {
112 self._push.apply(self, e);
115 if (this.x1 !== null)
116 this.ias.setOptions({enable: true, show: true});
118 this.ias.setOptions({enable: true});
120 $.wiki.Perspective.prototype.onEnter.call(this);
124 ObjectsPerspective.prototype.onExit = function(success, failure){
127 this.$objects_list.children(".image-object").each(function(i, e) {
128 var args = $(e).data('coords');
130 args = [null, null, null, null];
131 args.unshift($(e).text());
134 self.doc.setImageItems('obiekt', objects);
136 this.ias.setOptions({disable: true, hide: true});
140 $.wiki.ObjectsPerspective = ObjectsPerspective;