Browse Source

publish muk_web_utils - 12.0

pull/48/head
MuK IT GmbH 6 years ago
parent
commit
30301116c6
  1. 2
      muk_web_utils/__manifest__.py
  2. 5
      muk_web_utils/doc/changelog.rst
  3. 113
      muk_web_utils/static/src/js/fields/path.js
  4. 1
      muk_web_utils/template/assets.xml

2
muk_web_utils/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Web Utils", "name": "MuK Web Utils",
"summary": """Utility Features""", "summary": """Utility Features""",
"version": "12.0.2.7.0",
"version": "12.0.2.8.0",
"category": "Extra Tools", "category": "Extra Tools",
"license": "AGPL-3", "license": "AGPL-3",
"author": "MuK IT", "author": "MuK IT",

5
muk_web_utils/doc/changelog.rst

@ -1,3 +1,8 @@
`2.8.0`
-------
- Added path field widgets
`2.7.0` `2.7.0`
------- -------

113
muk_web_utils/static/src/js/fields/path.js

@ -0,0 +1,113 @@
/**********************************************************************************
*
* Copyright (C) 2017 MuK IT GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**********************************************************************************/
odoo.define('muk_web_utils.path', function (require) {
"use strict";
var core = require('web.core');
var fields = require('web.basic_fields');
var registry = require('web.field_registry');
var colorpicker = require('web.colorpicker');
var AbstractField = require('web.AbstractField');
var _t = core._t;
var QWeb = core.qweb;
var FieldPathNames = fields.FieldChar.extend({
init: function(parent, name, record) {
this._super.apply(this, arguments);
this.max_width = this.nodeOptions.width || 500;
},
_renderReadonly: function() {
var show_value = this._formatValue(this.value);
var text_witdh = $.fn.textWidth(show_value);
if(text_witdh >= this.max_width) {
var ratio_start = (1 - (this.max_width / text_witdh)) * show_value.length;
show_value = ".." + show_value.substring(ratio_start, show_value.length);
}
this.$el.text(show_value);
},
});
var FieldPathJson = fields.FieldText.extend({
events: _.extend({}, fields.FieldText.prototype.events, {
'click a' : '_onNodeClicked',
}),
init: function(parent, name, record) {
this._super.apply(this, arguments);
this.max_width = this.nodeOptions.width || 500;
this.seperator = this.nodeOptions.seperator || "/";
this.prefix = this.nodeOptions.prefix || false;
this.suffix = this.nodeOptions.suffix || false;
},
_renderReadonly: function() {
this.$el.empty();
this._renderPath();
},
_renderPath: function() {
var text_width_measure = "";
var path = JSON.parse(this.value || "[]");
$.each(_.clone(path).reverse(), function(index, element) {
text_width_measure += element.name + "/";
if($.fn.textWidth(text_width_measure) >= this.max_width) {
this.$el.prepend($('<span/>').text(".."));
} else {
if (index == 0) {
if(this.suffix) {
this.$el.prepend($('<span/>').text(this.seperator));
}
this.$el.prepend($('<span/>').text(element.name));
this.$el.prepend($('<span/>').text(this.seperator));
} else {
this.$el.prepend($('<a/>', {
'class': 'oe_form_uri',
'data-model': element.model,
'data-id': element.id,
'href': "javascript:void(0);",
'text': element.name,
}));
if (index != path.length - 1) {
this.$el.prepend($('<span/>').text(this.seperator));
} else if (this.prefix) {
this.$el.prepend($('<span/>').text(this.seperator));
}
}
}
return ($.fn.textWidth(text_width_measure) < this.max_width);
}.bind(this));
},
_onNodeClicked : function(event) {
this.do_action({
type: 'ir.actions.act_window',
res_model: $(event.currentTarget).data('model'),
res_id: $(event.currentTarget).data('id'),
views: [[false, 'form']],
target: 'current',
context: {},
});
}
});
registry.add('path_names', FieldPathNames);
registry.add('path_json', FieldPathJson);
return FieldColor;
});

1
muk_web_utils/template/assets.xml

@ -43,6 +43,7 @@
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/image.js" /> <script type="text/javascript" src="/muk_web_utils/static/src/js/fields/image.js" />
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/copy.js" /> <script type="text/javascript" src="/muk_web_utils/static/src/js/fields/copy.js" />
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/share.js" /> <script type="text/javascript" src="/muk_web_utils/static/src/js/fields/share.js" />
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/path.js" />
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/module.js" /> <script type="text/javascript" src="/muk_web_utils/static/src/js/fields/module.js" />
<script type="text/javascript" src="/muk_web_utils/static/src/js/views/form/renderer.js" /> <script type="text/javascript" src="/muk_web_utils/static/src/js/views/form/renderer.js" />
</xpath> </xpath>

Loading…
Cancel
Save