Setting button/select options from Salesforce quicklist options - angularjs

I would like to have two menus, where the choice in the first menu sets the options in the second menu. This is to be done on a Salesforce VisualForce page that is using Angular JS and specifically the UI-Grid module for it. Similar controls are using the Angular button classes for menus, but I don't see how to dynamically set the choices using a button.
My current design is using a select control and ng-options.
In the controller.js I have declared variables to be used by the menus and a function to swap out the array values for the second menu. Note that $scope.fieldOptions is set through a query to Salesforce to pull option values from quicklist fields. This array is used in the UI-Grid filter option that accepts in a format like "[ { value: '1', label: 'male' }, { value: '2', label: 'female' }...".
$scope.editRows = 'all';
$scope.editField = 'Program';
$scope.editValue;
$scope.editOptions = {};
$scope.setEditOptions = function(editField) {
switch (editField) {
case "Program" :
$scope.editOptions = $scope.fieldOptions.Program_Enrolled__c;
break;
case "Appl. ASSET" :
$scope.editOptions = $scope.fieldOptions.Applied_for_ASSET__c;
break;
case "4 Year Degree" :
$scope.editOptions = $scope.fieldOptions.Has_Student_Completed_4_Year_Degree__c;
break;
}
}
On the VisualForce page I have the buttons defined in a button group with the select control just after.
<div class="row" style="margin-bottom:10px;">
<div class="col-md-12">
<div class="btn-group">
<div class="btn-group" dropdown="true" dropdown-append-to-body="true">
<button class="btn btn-default dropdown-toggle" dropdown-toggle="true" type="button">
{{editRows | capitalize}} Rows <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li ng-click="editRows = 'all'">All Rows</li>
<li ng-click="editRows = 'visible'">Visible Rows Only</li>
<li ng-click="editRows = 'selected'">Selected Rows Only</li>
</ul>
</div>
<div class="btn-group" dropdown="true" dropdown-append-to-body="true">
<button class="btn btn-default dropdown-toggle" ng-click="setEditOptions(editField)"
dropdown-toggle="true" type="button">
{{editField | capitalize}} <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li ng-click="editField = 'Program'">Program Enrolled</li>
<li ng-click="editField = 'Appl. ASSET'">Applied for ASSET</li>
<li ng-click="editField = '4 Year Degree'">4-year degree?</li>
</ul>
</div>
<div>
<select ng-model="editValue" ng-options="option.label for option.value in selectOptions">
</select>
</div>
</div>
<button id="split-button" type="button" class="btn btn-default" ng-click="massUpdate()">Modify</button>
</div>
</div>
Am I on the right track? If there is an easier method, or one that would use a button menu directly, please feel free to offer suggestions. Otherwise, is the issue how I am using ng-options?

Okay, easier than I thought. Two typos. First, I had the array declared with {} instead of []. And I misspelled it in the select statement ng-options section. Fixed that and it's working.
If anyone knows any tricks to get this working with a button so it would match the others though, that would be wonderful. Otherwise I'm thinking I'll go with all selects for consistency. Also, maybe bundle these options into an array with the primary menu choices as the keys so I can just reference without the case statement.
$scope.editRows = 'all';
$scope.editField = 'Program';
$scope.editValue;
$scope.editOptions = {};

Related

How to change the uib-typeahead array based on button choice?

I can't seem to change the array that the uib-typeahead uses for the autocomplete on a search field. I have a button that chooses the categories to search by name, title, education, expertise and the button is working to filter the search results. But I am having issues trying to do the same thing for the uib-typeahead autocomplete.
I have a few arrays that pull the correct information and if I put them in and publish the page it works as intended, but I can't get them to switch out dynamically when a new filter is chosen.
The arrays that I am using. The default is the searchText with every category included. I tested them all and if I switch out searchText for any other one it works fine.
$scope.searchText = []; // all text that will be searched
$scope.searchname = []; // Name text that will be searched
$scope.searchtitle = []; // Title text that will be searched
$scope.searchexpertise = []; // Expertise text that will be searched
$scope.searcheducation = []; // Education text that will be searched
$scope.searchpositionsHeld = []; // PositionsHeld text that will be searched
Here are my button and input sections.
<button type="button" class="btn btn-outline dropdown-toggle rounded-0" data-toggle="dropdown">
<span id="search_selection">Search by</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<a class="dropdown-item" ng-click="changeFilterTo('name'); changeSearchTo('$scope.searchname')" href="#name">Name</a>
<a class="dropdown-item" ng-click="changeFilterTo('title'); changeSearchTo('$scope.searchtitle')" href="#title">Title</a>
<a class="dropdown-item" ng-click="changeFilterTo('tags'); changeSearchTo('$scope.searchtags')" href="#tags">Lab Capability</a>
<a class="dropdown-item" ng-click="changeFilterTo('expertise'); changeSearchTo('$scope.searchexpertise')" href="#expertise">Expertise</a>
<a class="dropdown-item" ng-click="changeFilterTo('education'); changeSearchTo('$scope.searcheducation')" href="#education">Education</a>
<a class="dropdown-item" ng-click="changeFilterTo('positionsHeld'); changeSearchTo('$scope.searchpositionsHeld')" href="#positionsHeld">LANL Positions</a>
</ul>
</div>
<input
class="form-control"
id="search_param"
placeholder="Type something"
type="text"
ng-model="search[filter]"
uib-typeahead="item for item in searchText | filter:$viewValue | limitTo:25"
ng-change="changeHandler()"
/>
And here is what I was trying to set out the uib-typeahead attribute.
$scope.changeSearchTo = function(pr) {
$scope.searchText = [];
$scope.searchText = pr;
}
So far nothing I have tried can switch out the arrays and I have tried searching for more answers, but nothing seems to match. I appreciate the help anyone can provide. Thank you!
remove $scope in the template. Try changeSearchTo(searchname) without the comma.
Merlin was mostly correct I removed $scope and then used this code to set the attribute:
$scope.changeSearchTo = function(prs) {
$scope.searchText = [];
$scope.searchText = $scope[prs];
}

Angularjs toggle panel & sub-panel controls

there are multiple panels and sub-panels (DIVs), that i need to show its (panel) controls on click to do specific tasks. The project is cv builder with front-end editing capabilities. So in regard to show/hide panels, my approach is very basic so hoping there would be much better way to getting this done.
Here is HTML Markup
<div class="panel component-about" ng-class="{'active': aboutPanel}" ng-click="activePanelAbout()">
<h2 class="title">Some Title (input)</h2>
<div class="panel-body">
Some text (textarea)
</div>
<div class="panel-hover-controls">
<span class="fa fa-pencil"></span>
<span class="fa fa-cog"></span>
<ul class="panel-dropdown" ng-class="{'active': aboutToggle}">
<li><label class="input-switch"><input type="checkbox" ng-model="aboutTitleShow" ><span class="slider round"></span></label> Show Title</li>
</ul>
</div>
</div>
<div class="panel component-experience" ng-class="{'active': expPanel}" ng-click="activePanelExp()">
<h2 class="title">Some Title (input)</h2>
<div class="panel-body">
<ul class="panel-componenets">
<li ng-repeat>
Title
Content
</li>
</ul>
</div>
<div class="panel-hover-controls">
<span class="fa fa-pencil"></span>
<span class="fa fa-cog"></span>
<ul class="panel-dropdown" ng-class="{'active': aboutToggle}">
<li><label class="input-switch"><input type="checkbox" ng-model="aboutTitleShow" ><span class="slider round"></span></label> Show Title</li>
</ul>
</div>
</div>
<div class="panel component-skills" ng-class="{'active': skillsPanel}" ng-click="activePanelSkills()">
<h2 class="title">Some Title (input)</h2>
<div class="panel-body">
<ul class="panel-dropdown" ng-class="{'active': aboutToggle}">
<li><label class="input-switch"><input type="checkbox" ng-model="aboutTitleShow" ><span class="slider round"></span></label> Show Title</li>
</ul>
</div>
<div class="panel-hover-controls">
<span class="fa fa-pencil"></span>
<span class="fa fa-cog"></span>
<ul class="panel-dropdown" ng-class="{'active': aboutToggle}">
<li><label class="input-switch"><input type="checkbox" ng-model="aboutTitleShow" ><span class="slider round"></span></label> Show Title</li>
</ul>
</div>
</div>
Further please check markup figure in (below) screenshot.
In reference to attached screenshot, there are multiple panel sections and most of panels also have sub-panels and each panel has its own control type which need to be show on click.
Here is JS (Controller)
// for setting popups
$scope.aboutToggle = false;
$scope.expToggle = false;
$scope.skillToggle = false;
// about panel
$scope.activePanelAbout = function() {
$scope.aboutPanel = true;
$scope.expPanel = false;
$scope.skillPanel = false;
}
// experience panel
$scope.activePanelExp = function() {
$scope.aboutPanel = false;
$scope.expPanel = true;
$scope.skillPanel = false;
}
// skill panel
$scope.activePanelSkill = function() {
$scope.aboutPanel = false;
$scope.expPanel = false;
$scope.skillPanel = true;
}
Now i think the picture should be clear. The panels are toggling actually, but i require more better approach something like this that we use to do in javascript/jquery.
I hope i have covered all aspects of my question, if not please do guide me so i can clarify myself. I'm looking forward for your guidance.
Thanks in advance.
this in AngularJS ends up a bit different than plain old JS. Since a controller contains its own $scope in relation to the DOM of which the controller is instantiated, this doesn't always refer to the object that calls a function, etc. So I can think of two options:
First maybe simplify how you're changing the active class for each panel and it's children. So maybe just:
$scope.activePanel = "";
$scope.ChangeActivePanel = function(newPanel) {
$scope.activePanel = newPanel;
}
And then change the ng-class for each panel to ng-class="{'active': activePanel == 'about'}" or ng-class="{'active': activePanel == 'skills'}", etc. Then change ng-click on the panels to ng-click="ChangeActivePanel('about')" or whatever to update the variable. In all honesty, just ng-click="activePanel = 'about'" would work but the ChangeActivePanel function could be expanded to handle behavior of the children panel elements as well. Just a thought rather than having three different functions and toggling all of these variables.
Second option is to create controllers for each panel by declaring ng-controller="aboutController" or ng-controller="skillsController" to each panel and then each panel would have it's own $scope but you'll have to declare and attach each controller to the app module and you'll run into headaches if you need to share data across controllers and will have to use factories/services, etc. I think that's overkill for something like this. Plus, it's difficult to manage which $scope is which across multiple controllers within the same view.
Hopefully this gives you something to work with.

How to bind a part of a variable already binded

I have a loop ng-repeat that displays sevral icons.
<div class="box">
<div class="box-body">
<div class="row" >
<div class="col-sm-6" style="margin-bottom: 5px;" ng-repeat="record in newlayout.display" align="center">
<a class="btn btn-app" ng-href="#newlayout/{{newlayout.url}}{{newlayout.itemValue}}" >
<span class="badge bg-yellow" style="font-size:22px;">{{record.numberOfSamples}}</span>
<i class="fa fa-{{newlayout.labStyle}}"></i> {{record.lab}}
</a>
</div>
</div>
</div>
</div>
My issue is that the second part of the binded variable itemValue should be dynamic
In my Js, I have this
newLayout.url = 'sublabs/?labName=';
newLayout.itemValue = 'record.lab';
The URL is dynamic.
When I click on the first displayed Icon, the url should look like this :
But it didn't work as I had a compilation error..
Does someone have an idea how to fix this:
http://localhost:8181/#/newlayout/sublabs?labName=PIA/C1 - Shiftlabo
Where the record value "PIA/C1 - Shiftlabo" change.
So basically here if I change
<a class="btn btn-app" ng-href="#newlayout/{{newlayout.url}}{{newlayout.itemValue}}" >
{{newlayout.itemValue}} by {{record.lab}} it would work..but the {{record.**lab**}} should be dynamic as it will have another value when I click on the icon. It will change to {{record.subLab}}
Thanks
Use property acccessor bracket notation inside the binding:
<div>{{record[labOrSublab]}}</div>
JS
var isSublab = false;
$scope.labOrSublab = "lab";
$scope.clickHandler = function() {
isSublab = !isSublab;
$scope.labOrSublab = isSublab ? 'subLab' : 'lab';
};

Update number of pages with selected objects in angularjs

I need some help with a problem I'm facing with pagination on AngularJS
Right now I have 3 tables, two of them have available items to select, and the third one, stores and show selected elements of the other tables, then I added pagination to each table, but I'm having some troubles with the selection table, If I add or remove elements individually, everything works as expected and the number of pages on selection table are updated.
The problem is when I use "Check All" function of the first table, the number of the pages doesn't get updated, I don't know what can I do in this case, I guess is something in check all funcition maybe but I run out of ideas right now
This is what I have so far:
http://embed.plnkr.co/e5P6iZ4W3P0Yb0YQy7Fu/preview
This is how the number of pages are calculated in numberOfSelectionPages function:
$scope.numberOfSelectionPages = function() {
return Math.ceil($scope.selection.length / $scope.pageSelSize);
};
And this is how the template is created on the html file:
<div class="pagination pagination-centered" ng-show="selection.length">
<ul class="pagination-controle pagination">
<li>
<button type="button" class="btn btn-primary" ng-disabled="curSelPage == 0"
ng-click="curSelPage=curSelPage-1"> < PREV</button>
</li>
<li>
<span>Page {{curSelPage + 1}} of {{ numberOfSelectionPages() }}</span>
</li>
<li>
<button type="button" class="btn btn-primary"
ng-disabled="curSelPage >= selection.length/pageSelSize - 1"
ng-click="curSelPage = curSelPage+1">NEXT ></button>
</li>
</ul>
</div>
This is what I used for pagination:
http://angulartutorial.blogspot.in/2014/03/client-side-pagination-using-angular-js.html
I hope maybe somebody can give me a hand on this
Thanks in advice!

Angularjs print text not working based on ng-switch

Here is my current code.
What I am trying to do is to: generate different content after click each dropdown toggle.
For example, when text is clicked, "Text" shows under the button.
Could someone help me on that?
Thanks in advance!
You have to remove the ng-model from the li element & add a ng-click handler to your a tag. This way you can use the choice that you selected for whatever you want to do with it.
Example: http://plnkr.co/edit/oTHWf2I266SHjur5Ebv8?p=preview
HTML:
<!-- ADD ITEM BUTTON -->
<li class="dropdown">
<button class="btn btn-default dropdown-toggle">Add item</button>
<ul class="dropdown-menu">
<li ng-repeat="choice in items">
<a ng-click="selectItem(choice)">{{choice.type}}</a>
</li>
</ul>
</li>
{{selection}}
JS:
$scope.selection = {};
$scope.selectItem = function(choice) {
$scope.selection = choice;
}

Resources