web mailing list archives

web@odoo-community.org

Avatar

Re: [OCA/web] [ADD] web_widget_switchcase (#1064)

by Simone Orsi <notifications@github.com> - 10/10/2018 17:44:26

@simahawk commented on this pull request.


In web_widget_char_switchcase/static/src/js/web_widget_char_switchcase.js:

> @@ -0,0 +1,95 @@
+odoo.define('web_widget_char_switchcase', function (require) {
+    "use strict";
+
+    var core = require('web.core');
+    var formats = require('web.formats');
+    var form_widgets = require('web.form_widgets');
+
+    form_widgets.FieldChar.include({
+        transformations: ['upper', 'lower', 'title', 'sentence', 'camel', 'pascal', 'snake'],
+        init: function (field_manager, node) {
+            this._super(field_manager, node);
+            this.options = _.defaults(this.options, {
+                transform: this.transformations[0]
+            });
+            this.current_transformation = this.options['transform'];
this.current_handler = this._get_handler()
[...]
/* return the function that will be used to handle current transformation */
_get_handler: function () {
    switch (this.current_transformation) {
        case 'upper':
            // HELLO WORLD!
            return function (val) { return val.toUpperCase() }
        case 'lower':
            // hello world!
            return function (val) { return val.toLowerCase() }
        [...]
}
[...]
this.$input.keyup(function(){
    var old_val = self.$input.val();
    if (!old_val) return old_val;
    self.$input.val(self.current_handler(old_val));
})

transform is actually replaced by _get_handler but you can for instance rename current_handler to transform...


You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.