|
16 | 16 | // under the License. |
17 | 17 | (function(cloudStack, $) { |
18 | 18 | var ostypeObjs; |
| 19 | + var previousCollection = []; |
| 20 | + var previousFilterType = null; |
19 | 21 |
|
20 | 22 | cloudStack.sections.templates = { |
21 | 23 | title: 'label.menu.templates', |
|
881 | 883 | var ignoreProject = false; |
882 | 884 | if (args.filterBy != null) { //filter dropdown |
883 | 885 | if (args.filterBy.kind != null) { |
| 886 | + if (previousFilterType != args.filterBy.kind || args.page == 1) { |
| 887 | + previousFilterType = args.filterBy.kind; |
| 888 | + previousCollection = []; |
| 889 | + } |
884 | 890 | switch (args.filterBy.kind) { |
885 | 891 | case "all": |
886 | 892 | ignoreProject = true; |
|
924 | 930 | var itemsView = []; |
925 | 931 |
|
926 | 932 | $(items).each(function(index, item) { |
927 | | - var existing = $.grep(itemsView, function(it){ |
| 933 | + var existing = $.grep(previousCollection, function(it){ |
928 | 934 | return it != null && it.id !=null && it.id == item.id; |
929 | 935 | }); |
930 | 936 |
|
931 | | - if (existing.length == 0) { |
932 | | - itemsView.push($.extend(item, { |
| 937 | + if (existing.length > 0) { |
| 938 | + return true; // skip adding this entry |
| 939 | + } else { |
| 940 | + var templateItem = $.extend(item, { |
933 | 941 | zones: item.zonename, |
934 | 942 | zoneids: [item.zoneid] |
935 | | - })); |
936 | | - } |
937 | | - else { |
938 | | - existing[0].zones = 'label.multiplezones'; |
939 | | - existing[0].zoneids.push(item.zoneid); |
| 943 | + }); |
| 944 | + itemsView.push(templateItem); |
| 945 | + previousCollection.push(templateItem); |
940 | 946 | } |
941 | 947 | }); |
942 | 948 |
|
|
1377 | 1383 |
|
1378 | 1384 |
|
1379 | 1385 | dataProvider: function(args) { // UI > Templates menu (listing) > select a template from listing > Details tab > Zones tab (listing) |
| 1386 | + var data = { templatefilter: "self", |
| 1387 | + id: args.context.templates[0].id |
| 1388 | + }; |
| 1389 | + listViewDataProvider(args, data); |
1380 | 1390 | $.ajax({ |
1381 | 1391 | url: createURL("listTemplates"), |
1382 | | - data: { |
1383 | | - templatefilter: "self", |
1384 | | - id: args.context.templates[0].id |
1385 | | - }, |
| 1392 | + data: data, |
1386 | 1393 | success: function(json) { |
1387 | 1394 | var jsonObjs = json.listtemplatesresponse.template; |
1388 | 1395 |
|
|
2021 | 2028 | var ignoreProject = false; |
2022 | 2029 | if (args.filterBy != null) { //filter dropdown |
2023 | 2030 | if (args.filterBy.kind != null) { |
| 2031 | + if (previousFilterType != args.filterBy.kind || args.page == 1) { |
| 2032 | + previousFilterType = args.filterBy.kind; |
| 2033 | + previousCollection = []; |
| 2034 | + } |
2024 | 2035 | switch (args.filterBy.kind) { |
2025 | 2036 | case "all": |
2026 | 2037 | ignoreProject = true; |
|
2064 | 2075 |
|
2065 | 2076 | var itemsView = []; |
2066 | 2077 | $(items).each(function(index, item) { |
2067 | | - var existing = $.grep(itemsView, function(it){ |
| 2078 | + var existing = $.grep(previousCollection, function(it){ |
2068 | 2079 | return it != null && it.id !=null && it.id == item.id; |
2069 | 2080 | }); |
2070 | | - if (existing.length == 0) { |
2071 | | - itemsView.push({ |
| 2081 | + |
| 2082 | + |
| 2083 | + if (existing.length > 0) { |
| 2084 | + return true; // skip adding this entry |
| 2085 | + } else { |
| 2086 | + var isoItem = { |
2072 | 2087 | id: item.id, |
2073 | 2088 | name: item.name, |
2074 | 2089 | description: item.description, |
2075 | 2090 | ostypeid: item.ostypeid, |
2076 | 2091 | zones: item.zonename, |
2077 | 2092 | zoneids: [item.zoneid] |
2078 | | - }); |
2079 | | - } |
2080 | | - else { |
2081 | | - existing[0].zones = 'Multiple Zones'; |
2082 | | - existing[0].zoneids.push(item.zoneid); |
| 2093 | + }; |
| 2094 | + itemsView.push(isoItem); |
| 2095 | + previousCollection.push(isoItem); |
2083 | 2096 | } |
2084 | 2097 | } |
2085 | 2098 | ); |
|
2382 | 2395 | hideSearchBar: true, |
2383 | 2396 |
|
2384 | 2397 | dataProvider: function(args) { |
2385 | | - var jsonObj = args.context.isos[0]; |
2386 | | - var apiCmd = "listIsos&isofilter=self&id=" + jsonObj.id; |
2387 | | - |
| 2398 | + var data = { |
| 2399 | + isofilter: 'self', |
| 2400 | + id: args.context.isos[0].id |
| 2401 | + }; |
| 2402 | + listViewDataProvider(args, data); |
2388 | 2403 | $.ajax({ |
2389 | | - url: createURL(apiCmd), |
| 2404 | + url: createURL('listIsos'), |
| 2405 | + data: data, |
2390 | 2406 | dataType: "json", |
2391 | 2407 | success: function(json) { |
2392 | 2408 | var isos = json.listisosresponse.iso; |
|
0 commit comments