Skip to content

Commit

Permalink
[tags] Remove taggle (#4631)
Browse files Browse the repository at this point in the history
  • Loading branch information
pratu16x7 authored and netchampfaris committed Dec 15, 2017
1 parent db687a2 commit 5763766
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 232 deletions.
6 changes: 3 additions & 3 deletions frappe/public/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
"public/css/form.css",
"public/css/mobile.css",
"public/css/kanban.css",
"public/css/controls.css"
"public/css/controls.css",
"public/css/tags.css"
],
"css/frappe-rtl.css": [
"public/css/bootstrap-rtl.css",
Expand All @@ -132,7 +133,6 @@
"js/libs.min.js": [
"public/js/lib/awesomplete/awesomplete.min.js",
"public/js/lib/Sortable.min.js",
"public/js/lib/taggle/taggle.min.js",
"public/js/lib/jquery/jquery.hotkeys.js",
"public/js/lib/summernote/summernote.js",
"public/js/lib/bootstrap.min.js",
Expand Down Expand Up @@ -292,7 +292,6 @@
"public/js/frappe/form/quick_entry.js"
],
"css/list.min.css": [
"public/js/lib/taggle/taggle.min.css",
"public/css/list.css",
"public/css/calendar.css",
"public/css/role_editor.css",
Expand All @@ -307,6 +306,7 @@
"public/js/frappe/ui/filters/filters.js",
"public/js/frappe/ui/filters/edit_filter.html",
"public/js/frappe/ui/tags.js",
"public/js/frappe/ui/tag_editor.js",
"public/js/frappe/ui/like.js",
"public/js/frappe/ui/liked_by.html",
"public/html/print_template.html",
Expand Down
19 changes: 19 additions & 0 deletions frappe/public/css/tags.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.tags-list {
float: left;
width: 100%;
padding-left: 3px;
}
.tags-input {
width: 100px;
font-size: 11px;
border: none;
outline: none;
}
.tags-list-item {
display: inline-block;
margin: 0px 3px;
}
.tags-placeholder {
display: inline-block;
font-size: 11px;
}
129 changes: 129 additions & 0 deletions frappe/public/js/frappe/ui/tag_editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
frappe.ui.TagEditor = Class.extend({
init: function(opts) {
/* docs:
Arguments
- parent
- user_tags
- doctype
- docname
*/
$.extend(this, opts);

this.setup_tags();

if (!this.user_tags) {
this.user_tags = "";
}
this.initialized = true;
this.refresh(this.user_tags);
},
setup_tags: function() {
var me = this;

// hidden form, does not have parent
if (!this.parent) {
return;
}

this.wrapper = $('<div class="tag-line" style="position: relative">').appendTo(this.parent);
if(!this.wrapper.length) return;

this.tags = new frappe.ui.Tags({
parent: this.wrapper,
placeholder: "Add a tag ...",
onTagAdd: (tag) => {
if(me.initialized && !me.refreshing) {
tag = toTitle(tag);
return frappe.call({
method: 'frappe.desk.tags.add_tag',
args: me.get_args(tag),
callback: function(r) {
var user_tags = me.user_tags ? me.user_tags.split(",") : [];
user_tags.push(tag)
me.user_tags = user_tags.join(",");
me.on_change && me.on_change(me.user_tags);
}
});
}
},
onTagRemove: (tag) => {
if(!me.refreshing) {
return frappe.call({
method: 'frappe.desk.tags.remove_tag',
args: me.get_args(tag),
callback: function(r) {
var user_tags = me.user_tags.split(",");
user_tags.splice(user_tags.indexOf(tag), 1);
me.user_tags = user_tags.join(",");
me.on_change && me.on_change(me.user_tags);
}
});
}
}
});
this.setup_awesomplete();
this.setup_complete = true;
},
setup_awesomplete: function() {
var me = this;
var $input = this.wrapper.find("input.tags-input");
var input = $input.get(0);
this.awesomplete = new Awesomplete(input, {
minChars: 0,
maxItems: 99,
list: []
});
$input.on("awesomplete-open", function(e){
$input.attr('state', 'open');
});
$input.on("awesomplete-close", function(e){
$input.attr('state', 'closed');
});
$input.on("input", function(e) {
var value = e.target.value;
frappe.call({
method:"frappe.desk.tags.get_tags",
args:{
doctype: me.frm.doctype,
txt: value.toLowerCase(),
cat_tags: me.list_sidebar ?
JSON.stringify(me.list_sidebar.get_cat_tags()) : '[]'
},
callback: function(r) {
me.awesomplete.list = r.message;
}
});
});
$input.on("focus", function(e) {
if($input.attr('state') != 'open') {
$input.trigger("input");
}
});
},
get_args: function(tag) {
return {
tag: tag,
dt: this.frm.doctype,
dn: this.frm.docname,
}
},
refresh: function(user_tags) {
var me = this;
if (!this.initialized || !this.setup_complete || this.refreshing) return;

me.refreshing = true;
try {
me.tags.clearTags();
if(user_tags) {
me.tags.addTags(user_tags.split(','));
}
} catch(e) {
me.refreshing = false;
// wtf bug
setTimeout( function() { me.refresh(); }, 100);
}
me.refreshing = false;

}
})

0 comments on commit 5763766

Please sign in to comment.