Skip to content

Commit

Permalink
Merge pull request #1869 from reciprocity/feature/lhn-fixes
Browse files Browse the repository at this point in the history
CORE-220 for LHN resizing #resolve
  • Loading branch information
laran committed Oct 8, 2014
2 parents bae3071 + c14e848 commit 6222da6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 70 deletions.
89 changes: 35 additions & 54 deletions src/ggrc/assets/javascripts/controllers/quick_search_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand All @@ -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;
}
Expand All @@ -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();
}
Expand Down
16 changes: 0 additions & 16 deletions src/ggrc/assets/javascripts/models/display_prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6222da6

Please # to comment.