From c14e84827676fadfdd5e31de61c86f1582098027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C5=BEe=20Pe=C4=8Dar?= Date: Tue, 7 Oct 2014 13:39:38 +0200 Subject: [PATCH] CORE-220 for LHN resizing #resolve --- .../controllers/quick_search_controller.js | 89 ++++++++----------- .../javascripts/models/display_prefs.js | 16 ---- 2 files changed, 35 insertions(+), 70 deletions(-) diff --git a/src/ggrc/assets/javascripts/controllers/quick_search_controller.js b/src/ggrc/assets/javascripts/controllers/quick_search_controller.js index dc95f068abc1..77ee05d9e965 100644 --- a/src/ggrc/assets/javascripts/controllers/quick_search_controller.js +++ b/src/ggrc/assets/javascripts/controllers/quick_search_controller.js @@ -291,10 +291,8 @@ can.Control("CMS.Controllers.LHN", { initial_scroll(); } }); - self.size = prefs[0].getLHNavSize(null, "lhs") || self.min_lhn_size; - self.objnav_size = prefs[0].getObjNavSize(null, "object-area") || 200; + self.size = prefs[0].getLHNavSize(null, "lhs"); self.resize_lhn(self.size); - self.resize_objnav(self.lhn_width() + self.objnav_size); // Collapse the LHN if they did it on a previous page self.collapsed = prefs[0].getCollapsed(null, "lhs"); self.collapsed && self.toggle_lhs(); @@ -322,7 +320,7 @@ can.Control("CMS.Controllers.LHN", { , $lhsHolder = $(".lhs-holder") , $area = $(".area") , $bar = $("#lhn > .bar-v") - , $obj_bar = $(".objnav.bar-v") + , $search = $('.widgetsearch') ; if($lhs.hasClass("lhs-closed")) { $lhs.removeClass("lhs-closed"); @@ -338,35 +336,34 @@ can.Control("CMS.Controllers.LHN", { $bar.css("left", "40px"); } + $search.width($lhs.width() - 49); window.resize_areas(); - $(window).trigger('resize'); - $obj_bar.css("left", (this.objnav_size + this.lhn_width()) + "px"); - this.resize_lhn(this.size); CMS.Models.DisplayPrefs.findAll().done(function(prefs) { prefs[0].setCollapsed(null, "lhs", $lhs.hasClass("lhs-closed")); - }) + }); } - , min_lhn_size : 226 - , min_objnav_size : 44 , mousedown : false , dragged : false - , resize_lhn : function(resize){ - var $lhs = $("#lhs") - , $lhsHolder = $(".lhs-holder") - , $area = $(".area") - , $bar = $("#lhn>.bar-v") - , $obj_bar = $(".objnav.bar-v") - , $search = $('.widgetsearch') - , $lhs_label_right = $(".lhs-search .my-work-right") - , $lhs_label = $(".lhs-search .my-work-label") - , lhn_second_row = 201 - ; - //if(resize < this.min_lhn_size/2 && !$lhs.hasClass("lhs-closed")) this.toggle_lhs(); THIS IS RE-CODED BELOW THIS LINE. Instead of min_lhn_size I've added size of 40px - if(resize < 40 && !$lhs.hasClass("lhs-closed")) this.toggle_lhs(); - //if(resize < this.min_lhn_size) return; THIS IS RE-CODED BELOW THIS LINE. Instead of min_lhn_size I've added size of 40px - if(resize < 40) return; - if($lhs.hasClass("lhs-closed")) this.toggle_lhs(); + , resize_lhn : function(resize, no_trigger){ + var $lhs = $("#lhs"), + $lhsHolder = $(".lhs-holder"), + $area = $(".area"), + $bar = $("#lhn>.bar-v"), + $search = $('.widgetsearch'), + $lhs_label_right = $(".lhs-search .my-work-right"), + $lhs_label = $(".lhs-search .my-work-label"), + lhn_second_row = 201, + max_width = window.innerWidth - 30; + + if(resize < 40 && !$lhs.hasClass("lhs-closed")) { + this.toggle_lhs(no_trigger); + } + if(resize < 40) { + return; + } + resize = Math.min(resize, max_width); + if($lhs.hasClass("lhs-closed")) this.toggle_lhs(no_trigger); $lhsHolder.width(resize); // LHN search radio buttons oneline fix @@ -386,28 +383,14 @@ can.Control("CMS.Controllers.LHN", { $search.width(resize - 49); window.resize_areas(); - $(window).trigger('resize'); - $obj_bar.css("left", (this.objnav_size + this.lhn_width()) + "px"); - } - , resize_objnav : function(resize){ - - var $object_area = $(".object-area") - , $object_nav = $(".inner-nav") - , $object_bar = $('.objnav.bar-v') - , collapsed = false - , size = resize - this.lhn_width(); - ; - if(size < this.min_objnav_size) return; - $object_nav.width(size); - $object_bar.css('left', resize); - window.resize_areas(); - $(window).trigger('resize'); + if (!no_trigger) { + $(window).trigger('resize'); + } } , "{window} mousedown" : function(el, ev) { var $target = $(ev.target); if(!$target.hasClass('bar-v')) return; - this.objnav = $target.hasClass('objnav'); this.mousedown = true; this.dragged = false; } @@ -418,32 +401,30 @@ can.Control("CMS.Controllers.LHN", { ev.preventDefault(); this.dragged = true; - if(!this.objnav){ this.size = ev.pageX; this.resize_lhn(this.size, el); - } - else{ - this.objnav_size = ev.pageX - this.lhn_width(); - this.resize_objnav(ev.pageX); - } } , "{window} mouseup" : function(el, ev){ var self = this; if(!this.mousedown) return; this.mousedown = false; - if(!this.dragged && !this.objnav){ + if(!this.dragged){ this.toggle_lhs(); return; } - self.size = Math.max(self.size, this.min_lhn_size); - self.objnav_size = Math.max(self.objnav_size, self.min_objnav_size); + self.size = self.size; + CMS.Models.DisplayPrefs.findAll().done(function(prefs) { - prefs[0].setObjNavSize(null, "object-area", self.objnav_size); prefs[0].setLHNavSize(null, "lhs", self.size); }); } - + , "{window} resize" : function(el, ev) { + var $lhs = this.element.find("#lhs"); + if ($lhs) { + this.resize_lhn($lhs.width(), true); + } + } , "#lhs click": function(el, ev) { this.resize_search(); } diff --git a/src/ggrc/assets/javascripts/models/display_prefs.js b/src/ggrc/assets/javascripts/models/display_prefs.js index 291dfff441d8..3d5669906430 100644 --- a/src/ggrc/assets/javascripts/models/display_prefs.js +++ b/src/ggrc/assets/javascripts/models/display_prefs.js @@ -126,22 +126,6 @@ can.Model.LocalStorage("CMS.Models.DisplayPrefs", { return widget_id ? size.attr(widget_id) : size; } - - , setObjNavSize : function(page_id, widget_id, size) { - this.makeObject(page_id === null ? page_id : path, OBJ_SIZE).attr(widget_id, size); - this.autoupdate && this.save(); - return this; - } - - , getObjNavSize : function(page_id, widget_id) { - var size = this.getObject(page_id === null ? page_id : path, OBJ_SIZE); - if(!size) { - size = this.makeObject(page_id === null ? page_id : path, OBJ_SIZE).attr(this.makeObject(OBJ_SIZE, page_id).serialize()); - } - - return widget_id ? size.attr(widget_id) : size; - } - , setGlobal : function(widget_id, attrs) { var global = this.getObject(null, GLOBAL) && this.getObject(null, GLOBAL).attr(widget_id); if (!global) {