<commit_before>/*************************************************************************
 * Copyright 2009-2012 Eucalyptus Systems, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/.
 *
 * Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
 * CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
 * additional information or have any questions.
 ************************************************************************/

(function($, eucalyptus) {
  $.widget('eucalyptus.eip', $.eucalyptus.eucawidget, {
    options : { 
      from_instance : false,
    },
    baseTable : null,
    tableWrapper : null,
    releaseDialog : null,
    allocateDialog : null,
    associateDialog : null,
    disassociateDialog : null,
    associateBtnId : 'eip-associate-btn',

    _init : function() {
      var thisObj = this;
      var $tmpl = $('html body').find('.templates #eipTblTmpl').clone();
      var $wrapper = $($tmpl.render($.extend($.i18n.map, help_eip)));
      var $eipTable = $wrapper.children().first();
      var $eipHelp = $wrapper.children().last();
      this.baseTable = $eipTable;
      this.tableWrapper = $eipTable.eucatable({
        id : 'eips', // user of this widget should customize these options,
        dt_arg : {
          "bProcessing": true,
          "sAjaxSource": "../ec2?Action=DescribeAddresses",
          "fnServerData": function (sSource, aoData, fnCallback) {
                $.ajax( {
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": "_xsrf="+$.cookie('_xsrf'),
                    "success": fnCallback
                });

          },
          "sAjaxDataProp": "results",
          "bAutoWidth" : false,
          "sPaginationType": "full_numbers",
          "aoColumns": [
            {
              "bSortable": false,
              "fnRender": function(oObj) { return '<input type="checkbox"/>' },
              "sClass": "checkbox-cell"
            },
            { "mDataProp": "public_ip" },
            { "mDataProp": "instance_id" },
            {
              "bVisible": false,
              "fnRender": function(oObj) { 
                return oObj.aData.instance_id ? 'assigned' : 'unassigned' 
              } 
            }
          ],
        },
        text : {
          header_title : eip_h_title,
          create_resource : eip_allocate,
          resource_found : 'eip_found',
          resource_search : eip_search,
          resource_plural : eip_plural,
        },
        menu_actions : function(args){ 
          return thisObj._createMenuActions();
        },
        context_menu_actions : function(row) {
          return thisObj._createMenuActions();
        },
        menu_click_create : function (args) { thisObj.createAction() },
        help_click : function(evt) {
          thisObj._flipToHelp(evt, {content: $eipHelp, url: help_eip.landing_content_url});
        },
        filters : [{name:"eip_state", options: ['all','assigned','unassigned'], filter_col:3, alias: {'assigned':'assigned','unassigned':'unassigned'}, text: [eip_state_selector_all,eip_state_selector_assigned,eip_state_selector_unassigned] }],
      });
      this.tableWrapper.appendTo(this.element);
    },

    _create : function() { 
      var thisObj = this;
      // eip release dialog start
      var $tmpl = $('html body').find('.templates #eipReleaseDlgTmpl').clone();
      var $rendered = $($tmpl.render($.extend($.i18n.map, help_eip)));
      var $release_dialog = $rendered.children().first();
      var $release_help = $rendered.children().last();
      this.releaseDialog = $release_dialog.eucadialog({
         id: 'eips-release',
         title: eip_release_dialog_title,
         buttons: {
           'release': {text: eip_release_dialog_release_btn, click: function() {
                var rowsToDelete = thisObj.releaseDialog.eucadialog('getSelectedResources', 0);
                $release_dialog.eucadialog("close");
                thisObj._releaseListedIps(rowsToDelete);
            }},
           'cancel': {text: dialog_cancel_btn, focus:true, click: function() { $release_dialog.eucadialog("close");}}
         },
         help: { content: $release_help, url: help_eip.dialog_release_content_url },
       });
      // eip release dialog end
      // allocate eip dialog end
      var allocateButtonId = 'eip-allocate-btn';
      $tmpl = $('html body').find('.templates #eipAllocateDlgTmpl').clone();
      var $rendered = $($tmpl.render($.extend($.i18n.map, help_eip)));
      var $eip_allocate_dialog = $rendered.children().first();
      var $eip_allocate_dialog_help = $rendered.children().last();
      this.allocateDialog = $eip_allocate_dialog.eucadialog({
         id: 'eip-allocate',
         title: eip_allocate_dialog_title,
         buttons: {
           'create': { domid: allocateButtonId, text: eip_allocate_dialog_allocate_btn, disabled: true, click: function() {
                var numberOfIps = asText($eip_allocate_dialog.find('#eip-allocate-count').val());
                if ( numberOfIps != parseInt(numberOfIps) ) {
                  $eip_allocate_dialog.eucadialog('showError', eip_allocate_count_error_msg);
                } else {
                  $eip_allocate_dialog.eucadialog("close");
                  thisObj._allocateIps(numberOfIps);
                }
              } 
            },
           'cancel': { text: dialog_cancel_btn, focus:true, click: function() { $eip_allocate_dialog.eucadialog("close"); } }
         },
         help: { content: $eip_allocate_dialog_help, url: help_eip.dialog_allocate_content_url },
       });
      var $ip_count_edit = $eip_allocate_dialog.find('#eip-allocate-count');
      $eip_allocate_dialog.eucadialog('buttonOnKeyup', $ip_count_edit,  allocateButtonId, function(){
        return $ip_count_edit.val() == parseInt($ip_count_edit.val());
      });
      // allocate eip dialog end
      // associate eip dialog end
      $tmpl = $('html body').find('.templates #eipAssociateDlgTmpl').clone();
      var $rendered = $($tmpl.render($.extend($.i18n.map, help_eip)));<commit_msg>EUCA-3815: Do not activate allocate IPs button on negative count<commit_after>/*************************************************************************
 * Copyright 2009-2012 Eucalyptus Systems, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/.
 *
 * Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
 * CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
 * additional information or have any questions.
 ************************************************************************/

(function($, eucalyptus) {
  $.widget('eucalyptus.eip', $.eucalyptus.eucawidget, {
    options : { 
      from_instance : false,
    },
    baseTable : null,
    tableWrapper : null,
    releaseDialog : null,
    allocateDialog : null,
    associateDialog : null,
    disassociateDialog : null,
    associateBtnId : 'eip-associate-btn',

    _init : function() {
      var thisObj = this;
      var $tmpl = $('html body').find('.templates #eipTblTmpl').clone();
      var $wrapper = $($tmpl.render($.extend($.i18n.map, help_eip)));
      var $eipTable = $wrapper.children().first();
      var $eipHelp = $wrapper.children().last();
      this.baseTable = $eipTable;
      this.tableWrapper = $eipTable.eucatable({
        id : 'eips', // user of this widget should customize these options,
        dt_arg : {
          "bProcessing": true,
          "sAjaxSource": "../ec2?Action=DescribeAddresses",
          "fnServerData": function (sSource, aoData, fnCallback) {
                $.ajax( {
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": "_xsrf="+$.cookie('_xsrf'),
                    "success": fnCallback
                });

          },
          "sAjaxDataProp": "results",
          "bAutoWidth" : false,
          "sPaginationType": "full_numbers",
          "aoColumns": [
            {
              "bSortable": false,
              "fnRender": function(oObj) { return '<input type="checkbox"/>' },
              "sClass": "checkbox-cell"
            },
            { "mDataProp": "public_ip" },
            { "mDataProp": "instance_id" },
            {
              "bVisible": false,
              "fnRender": function(oObj) { 
                return oObj.aData.instance_id ? 'assigned' : 'unassigned' 
              } 
            }
          ],
        },
        text : {
          header_title : eip_h_title,
          create_resource : eip_allocate,
          resource_found : 'eip_found',
          resource_search : eip_search,
          resource_plural : eip_plural,
        },
        menu_actions : function(args){ 
          return thisObj._createMenuActions();
        },
        context_menu_actions : function(row) {
          return thisObj._createMenuActions();
        },
        menu_click_create : function (args) { thisObj.createAction() },
        help_click : function(evt) {
          thisObj._flipToHelp(evt, {content: $eipHelp, url: help_eip.landing_content_url});
        },
        filters : [{name:"eip_state", options: ['all','assigned','unassigned'], filter_col:3, alias: {'assigned':'assigned','unassigned':'unassigned'}, text: [eip_state_selector_all,eip_state_selector_assigned,eip_state_selector_unassigned] }],
      });
      this.tableWrapper.appendTo(this.element);
    },

    _create : function() { 
      var thisObj = this;
      // eip release dialog start
      var $tmpl = $('html body').find('.templates #eipReleaseDlgTmpl').clone();
      var $rendered = $($tmpl.render($.extend($.i18n.map, help_eip)));
      var $release_dialog = $rendered.children().first();
      var $release_help = $rendered.children().last();
      this.releaseDialog = $release_dialog.eucadialog({
         id: 'eips-release',
         title: eip_release_dialog_title,
         buttons: {
           'release': {text: eip_release_dialog_release_btn, click: function() {
                var rowsToDelete = thisObj.releaseDialog.eucadialog('getSelectedResources', 0);
                $release_dialog.eucadialog("close");
                thisObj._releaseListedIps(rowsToDelete);
            }},
           'cancel': {text: dialog_cancel_btn, focus:true, click: function() { $release_dialog.eucadialog("close");}}
         },
         help: { content: $release_help, url: help_eip.dialog_release_content_url },
       });
      // eip release dialog end
      // allocate eip dialog end
      var allocateButtonId = 'eip-allocate-btn';
      $tmpl = $('html body').find('.templates #eipAllocateDlgTmpl').clone();
      var $rendered = $($tmpl.render($.extend($.i18n.map, help_eip)));
      var $eip_allocate_dialog = $rendered.children().first();
      var $eip_allocate_dialog_help = $rendered.children().last();
      this.allocateDialog = $eip_allocate_dialog.eucadialog({
         id: 'eip-allocate',
         title: eip_allocate_dialog_title,
         buttons: {
           'create': { domid: allocateButtonId, text: eip_allocate_dialog_allocate_btn, disabled: true, click: function() {
                var numberOfIps = asText($eip_allocate_dialog.find('#eip-allocate-count').val());
                if ( numberOfIps != parseInt(numberOfIps) ) {
                  $eip_allocate_dialog.eucadialog('showError', eip_allocate_count_error_msg);
                } else {
                  $eip_allocate_dialog.eucadialog("close");
                  thisObj._allocateIps(numberOfIps);
                }
              } 
            },
           'cancel': { text: dialog_cancel_btn, focus:true, click: function() { $eip_allocate_dialog.eucadialog("close"); } }
         },
         help: { content: $eip_allocate_dialog_help, url: help_eip.dialog_allocate_content_url },
       });
      var $ip_count_edit = $eip_allocate_dialog.find('#eip-allocate-count');
      $eip_allocate_dialog.eucadialog('buttonOnKeyup', $ip_count_edit,  allocateButtonId, function(){
        var count = parseInt($ip_count_edit.val())
        return $ip_count_edit.val() == count && count > 0;
      });
      // allocate eip dialog end
      // associate eip dialog end
      $tmpl = $('html body').find('.templates #eipAssociateDlgTmpl').clone();
      var $rendered = $($tmpl.render($.extend($.i18n.map, help_eip)));
{'fraction_non_alphanumeric': 0.14903703703703702, 'fraction_numerical': 0.004666666666666667, 'mean_word_length': 2.537070998166099, 'pattern_counts': {'":': 36, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3576014', 'n_tokens_mistral': 4059, 'n_tokens_neox': 3880, 'n_words': 831}