<commit_before>// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.  Citrix Systems, Inc.
// reserves all rights not expressly granted by the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 
// Automatically generated by addcopyright.py at 04/03/2012
(function($, cloudStack) {

  var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, featuredIsoObjs, communityIsoObjs, myIsoObjs, serviceOfferingObjs, diskOfferingObjs, networkOfferingObjs, physicalNetworkObjs;
  var selectedZoneObj, selectedTemplateObj, selectedHypervisor, selectedDiskOfferingObj; 
  var step5ContainerType = 'nothing-to-select'; //'nothing-to-select', 'select-network', 'select-security-group'

  cloudStack.sections.instances = {
    title: 'label.instances',
    id: 'instances',
    listView: {
      section: 'instances',
      filters: {
        all: { label: 'ui.listView.filters.all' },
        mine: { label: 'ui.listView.filters.mine' },
        running: { label: 'state.Running' },
        stopped: { label: 'state.Stopped' },
        destroyed: {
          preFilter: function(args) {
            if (isAdmin() || isDomainAdmin())
              return true;
            else
              return false;
          },
          label: 'state.Destroyed'
        }
      },			
			preFilter: function(args) {
				var hiddenFields = [];
				if(!isAdmin()) {				
					hiddenFields.push('instancename');
				}			
				return hiddenFields;
			},			
      fields: {        
        displayname: { label: 'label.display.name' },
				instancename: { label: 'label.internal.name' },
        zonename: { label: 'label.zone.name' },
        state: {
          label: 'label.state',         
          indicator: {
            'Running': 'on',
            'Stopped': 'off',
            'Destroyed': 'off',
            'Error': 'off'
          }
        }
      },

      // List view actions
      actions: {
        // Add instance wizard
        add: {
          label: 'label.vm.add',

          action: {
            custom: cloudStack.instanceWizard({
              maxDiskOfferingSize: function() {
                return g_capabilities.customdiskofferingmaxsize;
              },
              steps: [
                // Step 1: Setup
                function(args) {
                  $.ajax({
                    url: createURL("listZones&available=true"),
                    dataType: "json",
                    async: false,
                    success: function(json) {
                      zoneObjs = json.listzonesresponse.zone;
                      args.response.success({ data: {zones: zoneObjs}});
                    }
                  });
                },

                // Step 2: Select template
                function(args) {
                  $(zoneObjs).each(function(){
                    if(this.id == args.currentData.zoneid) {
                      selectedZoneObj = this;
                      return false; //break the $.each() loop
                    }
                  });
                  if(selectedZoneObj == null) {
                    alert("error: can't find matched zone object");
                    return;
                  }

                  $.ajax({
                    url: createURL("listHypervisors&zoneid="+args.currentData.zoneid),
                    dataType: "json",
                    async: false,
                    success: function(json) {
                      hypervisorObjs = json.listhypervisorsresponse.hypervisor;
                    }
                  });

									
									//***** get templates/ISOs (begin) *****
									var hypervisorArray = [];
									$(hypervisorObjs).each(function(index, item) {									 
										hypervisorArray.push(item.name);
									});
																		
                  $.ajax({
                    url: createURL("listTemplates&templatefilter=featured&zoneid="+args.currentData.zoneid),
                    dataType: "json",
                    async: false,
                    success: function(json) {										  
										  featuredTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {											  
											  if($.inArray(item.hypervisor, hypervisorArray) > -1)
											    return true;
											});	
                    }
                  });
                  $.ajax({
                    url: createURL("listTemplates&templatefilter=community&zoneid="+args.currentData.zoneid),
                    dataType: "json",
                    async: false,
                    success: function(json) {
                      communityTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {											  
											  if($.inArray(item.hypervisor, hypervisorArray) > -1)
											    return true;
											});	
                    }
                  });
                  $.ajax({
                    url: createURL("listTemplates&templatefilter=selfexecutable&zoneid="+args.currentData.zoneid),
                    dataType: "json",
                    async: false,
                    success: function(json) {
                      myTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {											  
											  if($.inArray(item.hypervisor, hypervisorArray) > -1)
											    return true;
											});	
                    }
                  });
									
									$.ajax({
                    url: createURL("listIsos&isofilter=featured&zoneid=" + args.currentData.zoneid + "&bootable=true"),
                    dataType: "json",
                    async: false,
                    success: function(json) {
                      featuredIsoObjs = json.listisosresponse.iso;
                    }
                  });
                  $.ajax({
                    url: createURL("listIsos&isofilter=community&zoneid=" + args.currentData.zoneid + "&bootable=true"),
                    dataType: "json",
                    async: false,
                    success: function(json) {
                      communityIsoObjs = json.listisosresponse.iso;
                    }
                  });
                  $.ajax({
                    url: createURL("listIsos&isofilter=selfexecutable&zoneid=" + args.currentData.zoneid + "&bootable=true"),
                    dataType: "json",
                    async: false,
                    success: function(json) {
                      myIsoObjs = json.listisosresponse.iso;
                    }
                  });		
									//***** get templates/ISOs (end) *****

									
                  args.response.success({
                    hypervisor: {
                      idField: 'name',
                      nameField: 'name'
                    },
                    data: {
                      templates: {
                        featuredtemplates: featuredTemplateObjs,
                        communitytemplates: communityTemplateObjs,
                        mytemplates: myTemplateObjs,
                        
												featuredisos: featuredIsoObjs,
                        communityisos: communityIsoObjs,
                        myisos: myIsoObjs 										
                      },
                      hypervisors: hypervisorObjs
                    }
                  });
                },

                // Step 3: Service offering
                function(args) {
                  if(args.currentData["select-template"] == "select-template") {
                    if(featuredTemplateObjs != null && featuredTemplateObjs.length > 0) {
                      for(var i=0; i < featuredTemplateObjs.length; i++) {
                        if(featuredTemplateObjs[i].id == args.currentData.templateid) {
                          selectedTemplateObj = featuredTemplateObjs[i];
                          break;<commit_msg>Make templates or Isos calls when setup new instance on templates tab.<commit_after>// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.  Citrix Systems, Inc.
// reserves all rights not expressly granted by the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 
// Automatically generated by addcopyright.py at 04/03/2012
(function($, cloudStack) {

  var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, featuredIsoObjs, communityIsoObjs, myIsoObjs, serviceOfferingObjs, diskOfferingObjs, networkOfferingObjs, physicalNetworkObjs;
  var selectedZoneObj, selectedTemplateObj, selectedHypervisor, selectedDiskOfferingObj; 
  var step5ContainerType = 'nothing-to-select'; //'nothing-to-select', 'select-network', 'select-security-group'

  cloudStack.sections.instances = {
    title: 'label.instances',
    id: 'instances',
    listView: {
      section: 'instances',
      filters: {
        all: { label: 'ui.listView.filters.all' },
        mine: { label: 'ui.listView.filters.mine' },
        running: { label: 'state.Running' },
        stopped: { label: 'state.Stopped' },
        destroyed: {
          preFilter: function(args) {
            if (isAdmin() || isDomainAdmin())
              return true;
            else
              return false;
          },
          label: 'state.Destroyed'
        }
      },			
			preFilter: function(args) {
				var hiddenFields = [];
				if(!isAdmin()) {				
					hiddenFields.push('instancename');
				}			
				return hiddenFields;
			},			
      fields: {        
        displayname: { label: 'label.display.name' },
				instancename: { label: 'label.internal.name' },
        zonename: { label: 'label.zone.name' },
        state: {
          label: 'label.state',         
          indicator: {
            'Running': 'on',
            'Stopped': 'off',
            'Destroyed': 'off',
            'Error': 'off'
          }
        }
      },

      // List view actions
      actions: {
        // Add instance wizard
        add: {
          label: 'label.vm.add',

          action: {
            custom: cloudStack.instanceWizard({
              maxDiskOfferingSize: function() {
                return g_capabilities.customdiskofferingmaxsize;
              },
              steps: [
                // Step 1: Setup
                function(args) {
                  $.ajax({
                    url: createURL("listZones&available=true"),
                    dataType: "json",
                    async: false,
                    success: function(json) {
                      zoneObjs = json.listzonesresponse.zone;
                      args.response.success({ data: {zones: zoneObjs}});
                    }
                  });
                },

                // Step 2: Select template
                function(args) {
                  $(zoneObjs).each(function(){
                    if(this.id == args.currentData.zoneid) {
                      selectedZoneObj = this;
                      return false; //break the $.each() loop
                    }
                  });
                  if(selectedZoneObj == null) {
                    alert("error: can't find matched zone object");
                    return;
                  }

                  $.ajax({
                    url: createURL("listHypervisors&zoneid="+args.currentData.zoneid),
                    dataType: "json",
                    async: false,
                    success: function(json) {
                      hypervisorObjs = json.listhypervisorsresponse.hypervisor;
                    }
                  });

				  //***** get templates/ISOs (begin) *****
				  var selectedTemplate = args.currentData['select-template'];
				  if (selectedTemplate == 'select-template') {
					  var hypervisorArray = [];
					  $(hypervisorObjs).each(function(index, item) {									 
							hypervisorArray.push(item.name);
					  });
																		
					  $.ajax({
						url: createURL("listTemplates&templatefilter=featured&zoneid="+args.currentData.zoneid),
						dataType: "json",
						async: false,
						success: function(json) {										  
											  featuredTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {											  
												  if($.inArray(item.hypervisor, hypervisorArray) > -1)
													return true;
												});	
						}
					  });
					  $.ajax({
						url: createURL("listTemplates&templatefilter=community&zoneid="+args.currentData.zoneid),
						dataType: "json",
						async: false,
						success: function(json) {
						  communityTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {											  
												  if($.inArray(item.hypervisor, hypervisorArray) > -1)
													return true;
												});	
						}
					  });
					  $.ajax({
						url: createURL("listTemplates&templatefilter=selfexecutable&zoneid="+args.currentData.zoneid),
						dataType: "json",
						async: false,
						success: function(json) {
						  myTemplateObjs = $.grep(json.listtemplatesresponse.template, function(item, index) {											  
												  if($.inArray(item.hypervisor, hypervisorArray) > -1)
													return true;
												});	
						}
					  });
				  } else if (selectedTemplate == 'select-iso') {
					$.ajax({
						url: createURL("listIsos&isofilter=featured&zoneid=" + args.currentData.zoneid + "&bootable=true"),
						dataType: "json",
						async: false,
						success: function(json) {
						  featuredIsoObjs = json.listisosresponse.iso;
						}
					});
					$.ajax({
						url: createURL("listIsos&isofilter=community&zoneid=" + args.currentData.zoneid + "&bootable=true"),
						dataType: "json",
						async: false,
						success: function(json) {
						  communityIsoObjs = json.listisosresponse.iso;
						}
					});
					$.ajax({
						url: createURL("listIsos&isofilter=selfexecutable&zoneid=" + args.currentData.zoneid + "&bootable=true"),
						dataType: "json",
						async: false,
						success: function(json) {
						  myIsoObjs = json.listisosresponse.iso;
						}
					});
				  }
				  //***** get templates/ISOs (end) *****

									
				  var templatesObj = {};
				  if (selectedTemplate == 'select-template') {
					templatesObj = {
						featuredtemplates: featuredTemplateObjs,
						communitytemplates: communityTemplateObjs,
						mytemplates: myTemplateObjs
					}
				  } else if (selectedTemplate == 'select-iso') {
					templatesObj = {
						featuredisos: featuredIsoObjs,
                        communityisos: communityIsoObjs,
                        myisos: myIsoObjs
					}
				  }
				  args.response.success({
                    hypervisor: {
                      idField: 'name',
                      nameField: 'name'
                    },
                    data: {
                      templates: templatesObj,
                      hypervisors: hypervisorObjs
                    }
                  });
                },

                // Step 3: Service offering
                function(args) {
                  if(args.currentData["select-template"] == "select-template") {
                    if(featuredTemplateObjs != null && featuredTemplateObjs.length > 0) {
                      for(var i=0; i < featuredTemplateObjs.length; i++) {
                        if(featuredTemplateObjs[i].id == args.currentData.templateid) {
                          selectedTemplateObj = featuredTemplateObjs[i];
                          break;
{'fraction_non_alphanumeric': 0.10922671891263087, 'fraction_numerical': 0.003061286965040103, 'mean_word_length': 1.4918382913806254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1968563', 'n_tokens_mistral': 5142, 'n_tokens_neox': 4103, 'n_words': 856}