A more complete Angularjs+bootstrap application Interface Controller

Source: Internet
Author: User

Define (["App"],function (APP) {

Return App.controller ("Transactionsfundcontroller", Function ($scope, $compile, $location) {
$scope. transactionsfund={};//Defining objects
$scope. transactionsfundlist=[];//defining an array of objects

$scope. pages = 1; Default Query Total pages
$scope. size = 0; Default number of bars per page
$scope. Total = 0;


Empty modal frame
$ (". Modal"). On ("Hidden.bs.modal", function () {
$ (this). Removedata ("Bs.modal");
});
$ (' #myModal '). On (' Shown.bs.modal ', function () {

$ ("#myModal"). HTML ($compile ($ ("#myModal"). html ()) ($scope));
});
$ (' #myModalModify '). On (' Shown.bs.modal ', function () {
$ ("#myModalModify"). HTML ($compile ($ ("#myModalModify"). html ()) ($scope));
});

/************ Load Execution Method *******************/
$scope. Load = function () {

$scope. Querylist ();

};
/************ Query List *******************/
$scope. Querylist=function () {

$scope. transactionsfund.page=1;
$scope. transactionsfund.size=20;
Datacenter.find ("Transactionsfund", $scope. Transactionsfund);
}
/************ List return *******************/
Datacenter.addeventlistener ("Transactionsfundlist", function (e) {
Console.log ("xxxxxxxxxxxxxxxxxxx" +e.data);
$scope. transactionsfundlist = e.data.list;
$scope. pages = e.data.pages;
$scope. page = E.data.pagenum;
$scope. size= e.data.size;
$scope. total= e.data.total;
$scope. $apply ();
});
Datacenter.addeventlistener ("Tranfundlist", function () {
$scope. transactionsfund.page=1;
$scope. transactionsfund.size=20;
Datacenter.find ("Transactionsfund", $scope. Transactionsfund);
});

==================modify=======================

$scope. Modifys = function (ID) {
$location. Search (' Fund_id_mdf ', ID);
}

===================== Delete ==============================

Delete
$scope. del = function (ID) {
$location. Search (' Fund_id_mdf ', ID);
Console.log ("##################", id);


if (Confirm (' Confirm delete? ')) {
Datacenter.modify ("Transactionsfund/del", {id:id, stt:99}, ID);
}

};
Datacenter.addeventlistener ("Delfund", function (e) {

Datacenter.find ("Transactionsfund", $scope. Transactionsfund);
Datacenter.addeventlistener ("Delfund", function (e) {
Alert (' Delete succeeded! ');

});
});

--------------Page Selection--------------
$scope. selectpage = function (page) {
if (page!=null&&page>0&&page<= $scope. pages) {
$scope. Transactionsprocesss.page=page;
$scope. transactionsprocesss.size=5;

Datacenter.find ("Transactionsprocess", $scope. transactionsprocesss);
}else if (page> $scope. pages) {
$ ("#errInfo"). HTML ("Input pages cannot be greater than the total number of pages!") ");
$ (' #errModal '). Modal (' show ');
}else if (page==0) {
$ ("#errInfo"). HTML ("no Records!") ");
$ (' #errModal '). Modal (' show ');
}else{
$ ("#errInfo"). HTML ("Number of pages cannot be empty!") ");
$ (' #errModal '). Modal (' show ');
}
};

}). directive (' pagination ', function () {//Dynamic paging display
return {
Restrict: ' E ',
Scope: {
NumPages: ' = ',
Currpage: ' = ',
Onselectpage: ' & '
},

Template: ' <ul class= ' pagination > '
+ ' <li ng-class= ' {disabled:nopreviouspage ()} ' > '
+ ' <a ng-click= ' selecthomepage () "href=" "> Home </a>"
+ ' </li> '

+ ' <li ng-class= ' {disabled:nopreviouspage ()} ' > '
+ ' <a ng-click= ' selectpreviouspage () "href=" "> Previous </a>"
+ ' </li> '

+ ' <li ng-repeat= "page in pages" ng-class= "{active:isactivepage (page)}" > "
+ ' <a ng-click= ' selectpage (page) "href=" ">{{page}}</a>"
+ ' </li> '

+ ' <li ng-class= ' {disabled:nonextpage ()} ' > '
+ ' <a ng-click= ' selectnextpage () "href=" "> Next </a>"
+ ' </li> '

+ ' <li ng-class= ' {disabled:nonextpage ()} ' > '
+ ' <a ng-click= ' selectbackpage () "href=" "> Last </a>"
+ ' </li> '
+ ' </ul> ',

Replace:true,
Link:function (s) {
/***************currpage Monitoring Event *********************/
S. $watch (' Currpage ', function (value) {
S.pages = []; Define an array for ng-repeat use
if (s.numpages>=10) {//When the total number of pages is greater than 10 (10 is the dividing line because the page input is 10 per display)

if (S.currpage>=math.floor ((s.numpages)/10) *10) {//current page is greater than Math.floor ((last page)/10) *10). Traverse all pages that are the same as the last page 10 bits

if (s.numpages%10!=0) {
for (Var i=-1;i<=s.numpages%10;i++) {
S.pages.push (Math.floor (S.NUMPAGES/10) *10+i);
}
}else{
for (Var i=-10;i<=0;i++) {
S.pages.push (Math.floor (S.NUMPAGES/10) *10+i);
}
}

}else if (S.currpage<math.floor (S.NUMPAGES/10) *10) {//current page is less than Math.floor ((last page)/10) *10). Traverses all pages with the same 10-bit current page

for (Var i=-1;i<=10;i++) {
if (Math.floor (S.CURRPAGE/10) *10+i>0) {
S.pages.push (Math.floor (S.CURRPAGE/10) *10+i);
}
};
The last page shows the total number of pages indicated.
}

}else if (s.numpages<10) {//Show all pages when the total number of pages is less than 10

for (Var i=1;i<=s.numpages;i++) {
S.pages.push (i);
}

}

if (S.currpage > value) {
S.selectpage (value);
}
});

/***************numpages Monitoring Event *********************/
S. $watch (' NumPages ', function (value) {
S.pages = []; Define an array for ng-repeat use
if (s.numpages>=10) {//When the total number of pages is greater than 10 (10 is the dividing line because the page input is 10 per display)

if (S.currpage>=math.floor ((s.numpages)/10) *10) {//current page is greater than Math.floor ((last page)/10) *10). Traverse all pages that are the same as the last page 10 bits

if (s.numpages%10!=0) {
for (Var i=-1;i<=s.numpages%10;i++) {
S.pages.push (Math.floor (S.NUMPAGES/10) *10+i);
}
}else{
for (Var i=-10;i<=0;i++) {
S.pages.push (Math.floor (S.NUMPAGES/10) *10+i);
}
}

}else if (S.currpage<math.floor (S.NUMPAGES/10) *10) {//current page is less than Math.floor ((last page)/10) *10). Traverses all pages with the same 10-bit current page

for (Var i=-1;i<=10;i++) {
if (Math.floor (S.CURRPAGE/10) *10+i>0) {
S.pages.push (Math.floor (S.CURRPAGE/10) *10+i);
}
};
The last page shows the total number of pages indicated.
}

}else if (s.numpages<10) {//Show all pages when the total number of pages is less than 10

for (Var i=1;i<=s.numpages;i++) {
S.pages.push (i);
}

}

if (S.currpage > value) {
S.selectpage (value);
}
});


Determine if there is a previous page
S.nopreviouspage = function () {
return S.currpage = = = 1;
};

Determine if there is a next page
S.nonextpage = function () {
return S.currpage = = = S.numpages;
};

Determines whether the current page is selected
S.isactivepage = function (page) {
return s.currpage===page;
};

Select number of pages
S.selectpage = function (page) {
if (!s.isactivepage (page)) {
s.currpage = page;
S.onselectpage ({page:page});
}
};

Select Next Page
S.selectnextpage = function () {
if (!s.nonextpage ()) {
S.selectpage (s.currpage+1);
}
};

Select Previous Page
S.selectpreviouspage = function () {
if (!s.nopreviouspage ()) {
S.selectpage (s.currpage-1);
}
};
Select Home
S.selecthomepage = function () {
S.selectpage (1);
};
Select Last
S.selectbackpage = function () {
S.selectpage (s.numpages);
};
}
};
});//end page

});;

A more complete Angularjs+bootstrap application Interface Controller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.