var Qs_WeldingStamp_Mark = qs.createObject(); Qs_WeldingStamp_Mark.prototype = { id: null, _stamp: null, _delete_message: 'Are you sure you want to delete this weld?', initialize: function(options, stamp) { this._stamp = stamp; if (options.id) { this.id = options.id; this.onLoad(); } else { this.create(options.positionX, options.positionY); } }, create: function(positionX, positionY) { var self = this; $.ajax({ type: 'GET', url: self._stamp.options.callbackUrl, data: {id: self._stamp.options.id, action: 'addMark'}, dataType: 'json', success: function(response) { self.onCreateSuccess(response, positionX, positionY); } }); }, onCreateSuccess: function(response, positionX, positionY) { this.id = response.id; this._stamp.getContainer().append(response.html); $('#mark-container-' + this.id).css('left', positionX + 'px').css('top', positionY + 'px'); this.onLoad(); this.savePosition(); }, onLoad: function() { var self = this; $('#mark-container-' + self.id).draggable({ containment: 'parent', stack: '.mark', stop: function() { self.savePosition(); } }); $('#mark-options-' + self.id + ' a.edit').fancybox({ onComplete: function() { Qs_Form.init('stamp-mark-form', {onSuccessCallback: {refreshMark: [self.id]}}); var colorPicker = new Qs_colorPicker({id: 'color', pickerOptions: []}); }, modal: true }); $('#mark-options-' + self.id + ' a.delete').click(function(){ if (confirm(self._delete_message)) { $.ajax({ type: 'GET', url: self._stamp.options.callbackUrl, data: {id: self._stamp.options.id, markId: self.id, action: 'deleteMark'}, dataType: 'json', success: function() { $('#mark-container-' + self.id).remove(); } }); } return false; }); // force popup to open if (String(this.id).length > 16) { $('#mark-options-' + self.id + ' a.edit').trigger('click'); } }, refresh: function() { var self = this; $.ajax({ type: 'GET', url: self._stamp.options.callbackUrl, dataType: 'json', data: {id: self._stamp.options.id, markId: self.id, action: 'getMark'}, success: function(data, textStatus){ $('#mark-container-' + self.id).replaceWith(data.html); self.onLoad(); } }); $.fancybox.close(); }, savePosition: function() { var self = this; $.ajax({ type: 'GET', url: self._stamp.options.builderUrl, data: {id: self._stamp.options.id, markId: self.id, mark: {position: this.getPosition()}, action: 'updateMark'}, dataType: 'json' }); }, getPosition: function () { var position = $('#mark-container-' + this.id).position(); return { top: position.top, left: position.left, zIndex: $('#mark-container-' + this.id).css('z-index') }; } }; function refreshMark(id){ var mark = weldingStamp.getMarkById(id); mark.refresh(); }