return self.on_processed_onchange(response, processed);
} catch(e) {
- console.error(e);
+ instance.webclient.crashmanager.on_javascript_exception(e);
return $.Deferred().reject();
}
});
var tip_delay = 200;
var tip_duration = 3000;
var anyoneLoosesFocus = function() {
+ var used = false;
if (self.floating) {
if (self.last_search.length > 0) {
if (self.last_search[0][0] != self.get("value")) {
self.display_value["" + self.last_search[0][0]] = self.last_search[0][1];
self.set({value: self.last_search[0][0]});
} else {
+ used = true;
self.render_value();
}
} else {
+ used = true;
self.set({value: false});
+ self.render_value();
}
+ self.floating = false;
}
- if (! self.get("value")) {
+ if (used) {
tip_def.reject();
untip_def.reject();
tip_def = $.Deferred();
e.preventDefault();
},
html: true,
- close: anyoneLoosesFocus,
+ // disabled to solve a bug, but may cause others
+ //close: anyoneLoosesFocus,
minLength: 0,
delay: 0
});
},
start: function() {
this._super.apply(this, arguments);
+ this.$element.addClass('oe_form_field_one2many');
var self = this;
var views = [];
_.each(modes, function(mode) {
if (! _.include(["list", "tree", "graph", "kanban"], mode)) {
- instance.webclient.notification.warn(
- _.str.sprintf("View type '%s' is not supported in One2Many.", mode));
- return;
+ try {
+ throw new Error(_.str.sprintf("View type '%s' is not supported in One2Many.", mode));
+ } catch(e) {
+ instance.webclient.crashmanager.on_javascript_exception(e)
+ }
}
var view = {
view_id: false,
this.views = views;
this.viewmanager = new instance.web.form.One2ManyViewManager(this, this.dataset, views, {});
+ this.viewmanager.$element.addClass("oe_view_manager_one2many");
this.viewmanager.o2m = self;
var once = $.Deferred().then(function() {
self.init_form_last_update.resolve();
},
start: function() {
this._super.apply(this, arguments);
+ this.$element.addClass('oe_form_field_many2many');
var self = this;
this.dataset.on_unlink.add_last(function(ids) {
self.dataset_changed();
});
-
+
this.is_setted.then(function() {
self.load_view();
});
});
});
});
- })
+ });
},
set_value: function(value_) {
value_ = value_ || [];
instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
init: function(field_manager, node) {
+ var self = this;
this._super(field_manager, node);
- this.iframe = this.element_id + '_iframe';
this.binary_value = false;
+ this.fileupload_id = _.uniqueId('oe_fileupload');
+ $(window).on(this.fileupload_id, function() {
+ var args = [].slice.call(arguments).slice(1);
+ self.on_file_uploaded.apply(self, args);
+ });
+ },
+ stop: function() {
+ $(window).off(this.fileupload_id);
+ this._super.apply(this, arguments);
},
initialize_content: function() {
this.$element.find('input.oe-binary-file').change(this.on_file_change);
- this.$element.find('button.oe-binary-file-save').click(this.on_save_as);
+ this.$element.find('button.oe_binary_file_save').click(this.on_save_as);
this.$element.find('.oe-binary-file-clear').click(this.on_clear);
},
human_filesize : function(size) {
// TODO: on modern browsers, we could directly read the file locally on client ready to be used on image cropper
// http://www.html5rocks.com/tutorials/file/dndfiles/
// http://deepliquid.com/projects/Jcrop/demos.php?demo=handler
- window[this.iframe] = this.on_file_uploaded;
- if ($(e.target).val() != '') {
+
+ if ($(e.target).val() !== '') {
this.$element.find('form.oe-binary-form input[name=session_id]').val(this.session.session_id);
this.$element.find('form.oe-binary-form').submit();
this.$element.find('.oe-binary-progress').show();
}
},
on_file_uploaded: function(size, name, content_type, file_base64) {
- delete(window[this.iframe]);
if (size === false) {
this.do_warn("File Upload", "There was a problem while uploading your file");
// TODO: use openerp web crashmanager
console.warn("Error while uploading file : ", name);
} else {
+ this.filename = name;
this.on_file_uploaded_and_valid.apply(this, arguments);
}
this.$element.find('.oe-binary-progress').hide();
},
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
},
- on_save_as: function() {
- $.blockUI();
- this.session.get_file({
- url: '/web/binary/saveas_ajax',
- data: {data: JSON.stringify({
- model: this.view.dataset.model,
- id: (this.view.datarecord.id || ''),
- field: this.name,
- filename_field: (this.node.attrs.filename || ''),
- context: this.view.dataset.get_context()
- })},
- complete: $.unblockUI,
- error: instance.webclient.crashmanager.on_rpc_error
- });
+ on_save_as: function(ev) {
+ var value = this.get('value');
+ if (!value) {
+ this.do_warn(_t("Save As..."), _t("The field is empty, there's nothing to save !"));
+ ev.stopPropagation();
+ } else if (this._dirty_flag) {
+ var link = this.$('.oe_binary_file_save_data')[0];
+ link.download = this.filename || "download.bin"; // Works on only on Google Chrome
+ //link.target = '_blank';
+ link.href = "data:application/octet-stream;base64," + value;
+ } else {
+ $.blockUI();
+ this.session.get_file({
+ url: '/web/binary/saveas_ajax',
+ data: {data: JSON.stringify({
+ model: this.view.dataset.model,
+ id: (this.view.datarecord.id || ''),
+ field: this.name,
+ filename_field: (this.node.attrs.filename || ''),
+ context: this.view.dataset.get_context()
+ })},
+ complete: $.unblockUI,
+ error: instance.webclient.crashmanager.on_rpc_error
+ });
+ ev.stopPropagation();
+ return false;
+ }
},
on_clear: function() {
if (this.get('value') !== false) {
instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
template: 'FieldBinaryImage',
- initialize_content: function() {
- this._super();
- if (!this.get("effective_readonly")) {
- this.$element.find('.oe_form_field_image_controls').show();
- } else {
- this.$element.find('.oe_form_field_image_controls').hide();
- }
- },
set_value: function(value_) {
this._super.apply(this, arguments);
this.render_value();