PageRenderTime 470ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/backend/bePro/js/demo-editable.js

https://gitlab.com/kaouech/theme
JavaScript | 182 lines | 145 code | 29 blank | 8 comment | 15 complexity | 461d5a3e8d2d2e6a5ee099115db7c96a MD5 | raw file
  1. /* file: demo-editable.js
  2. * version: 1.3
  3. * last changed: 23.03.2014
  4. * description: This file can be removed before you use template in production.
  5. * It contains with elements used only for editable form demo
  6. */
  7. $(document).ready(function(){
  8. gFormEditable = {
  9. init: function(){
  10. $('#enable').click(function() {
  11. $('#user .editable').editable('toggleDisabled');
  12. });
  13. $.fn.editable.defaults.url = 'assets/form-editable.php';
  14. $.fn.editable.defaults.inputclass = 'form-control';
  15. //editables
  16. $('#username').editable({
  17. type: 'text',
  18. pk: 1,
  19. name: 'username',
  20. title: 'Enter username'
  21. });
  22. $('#firstname').editable({
  23. validate: function(value) {
  24. if($.trim(value) == '') return 'This field is required';
  25. }
  26. });
  27. $('#sex').editable({
  28. prepend: "not selected",
  29. source: [
  30. {value: 1, text: 'Male'},
  31. {value: 2, text: 'Female'}
  32. ],
  33. display: function(value, sourceData) {
  34. var colors = {"": "gray", 1: "green", 2: "blue"},
  35. elem = $.grep(sourceData, function(o){return o.value == value;});
  36. if(elem.length) {
  37. $(this).text(elem[0].text).css("color", colors[value]);
  38. } else {
  39. $(this).empty();
  40. }
  41. }
  42. });
  43. $('#status').editable();
  44. $('#group').editable({
  45. showbuttons: false
  46. });
  47. $('#vacation').editable({
  48. datepicker: {
  49. todayBtn: 'linked'
  50. }
  51. });
  52. $('#dob').editable();
  53. $('#event').editable({
  54. placement: 'right',
  55. combodate: {
  56. firstItem: 'name'
  57. }
  58. });
  59. $('#meeting_start').editable({
  60. format: 'yyyy-mm-dd hh:ii',
  61. viewformat: 'dd/mm/yyyy hh:ii',
  62. validate: function(v) {
  63. if(v && v.getDate() == 10) return 'Day cant be 10!';
  64. },
  65. datetimepicker: {
  66. todayBtn: 'linked',
  67. weekStart: 1
  68. }
  69. });
  70. $('#comments').editable({
  71. showbuttons: 'bottom'
  72. });
  73. $('#note').editable();
  74. $('#pencil').click(function(e) {
  75. e.stopPropagation();
  76. e.preventDefault();
  77. $('#note').editable('toggle');
  78. });
  79. $('#state').editable({
  80. source: ["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]
  81. });
  82. $('#state2').editable({
  83. value: 'California',
  84. typeahead: {
  85. name: 'state',
  86. local: ["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]
  87. }
  88. });
  89. $('#fruits').editable({
  90. pk: 1,
  91. limit: 3,
  92. source: [
  93. {value: 1, text: 'banana'},
  94. {value: 2, text: 'peach'},
  95. {value: 3, text: 'apple'},
  96. {value: 4, text: 'watermelon'},
  97. {value: 5, text: 'orange'}
  98. ]
  99. });
  100. $('#tags').editable({
  101. inputclass: 'input-large',
  102. select2: {
  103. tags: ['html', 'javascript', 'css', 'ajax'],
  104. tokenSeparators: [",", " "]
  105. }
  106. });
  107. var countries = [];
  108. $.each({"BD": "Bangladesh", "BE": "Belgium", "BF": "Burkina Faso", "BG": "Bulgaria", "BA": "Bosnia and Herzegovina", "BB": "Barbados", "WF": "Wallis and Futuna", "BL": "Saint Bartelemey", "BM": "Bermuda", "BN": "Brunei Darussalam", "BO": "Bolivia", "BH": "Bahrain", "BI": "Burundi", "BJ": "Benin", "BT": "Bhutan", "JM": "Jamaica", "BV": "Bouvet Island", "BW": "Botswana", "WS": "Samoa", "BR": "Brazil", "BS": "Bahamas", "JE": "Jersey", "BY": "Belarus", "O1": "Other Country", "LV": "Latvia", "RW": "Rwanda", "RS": "Serbia", "TL": "Timor-Leste", "RE": "Reunion", "LU": "Luxembourg", "TJ": "Tajikistan", "RO": "Romania", "PG": "Papua New Guinea", "GW": "Guinea-Bissau", "GU": "Guam", "GT": "Guatemala", "GS": "South Georgia and the South Sandwich Islands", "GR": "Greece", "GQ": "Equatorial Guinea", "GP": "Guadeloupe", "JP": "Japan", "GY": "Guyana", "GG": "Guernsey", "GF": "French Guiana", "GE": "Georgia", "GD": "Grenada", "GB": "United Kingdom", "GA": "Gabon", "SV": "El Salvador", "GN": "Guinea", "GM": "Gambia", "GL": "Greenland", "GI": "Gibraltar", "GH": "Ghana", "OM": "Oman", "TN": "Tunisia", "JO": "Jordan", "HR": "Croatia", "HT": "Haiti", "HU": "Hungary", "HK": "Hong Kong", "HN": "Honduras", "HM": "Heard Island and McDonald Islands", "VE": "Venezuela", "PR": "Puerto Rico", "PS": "Palestinian Territory", "PW": "Palau", "PT": "Portugal", "SJ": "Svalbard and Jan Mayen", "PY": "Paraguay", "IQ": "Iraq", "PA": "Panama", "PF": "French Polynesia", "BZ": "Belize", "PE": "Peru", "PK": "Pakistan", "PH": "Philippines", "PN": "Pitcairn", "TM": "Turkmenistan", "PL": "Poland", "PM": "Saint Pierre and Miquelon", "ZM": "Zambia", "EH": "Western Sahara", "RU": "Russian Federation", "EE": "Estonia", "EG": "Egypt", "TK": "Tokelau", "ZA": "South Africa", "EC": "Ecuador", "IT": "Italy", "VN": "Vietnam", "SB": "Solomon Islands", "EU": "Europe", "ET": "Ethiopia", "SO": "Somalia", "ZW": "Zimbabwe", "SA": "Saudi Arabia", "ES": "Spain", "ER": "Eritrea", "ME": "Montenegro", "MD": "Moldova, Republic of", "MG": "Madagascar", "MF": "Saint Martin", "MA": "Morocco", "MC": "Monaco", "UZ": "Uzbekistan", "MM": "Myanmar", "ML": "Mali", "MO": "Macao", "MN": "Mongolia", "MH": "Marshall Islands", "MK": "Macedonia", "MU": "Mauritius", "MT": "Malta", "MW": "Malawi", "MV": "Maldives", "MQ": "Martinique", "MP": "Northern Mariana Islands", "MS": "Montserrat", "MR": "Mauritania", "IM": "Isle of Man", "UG": "Uganda", "TZ": "Tanzania, United Republic of", "MY": "Malaysia", "MX": "Mexico", "IL": "Israel", "FR": "France", "IO": "British Indian Ocean Territory", "FX": "France, Metropolitan", "SH": "Saint Helena", "FI": "Finland", "FJ": "Fiji", "FK": "Falkland Islands (Malvinas)", "FM": "Micronesia, Federated States of", "FO": "Faroe Islands", "NI": "Nicaragua", "NL": "Netherlands", "NO": "Norway", "NA": "Namibia", "VU": "Vanuatu", "NC": "New Caledonia", "NE": "Niger", "NF": "Norfolk Island", "NG": "Nigeria", "NZ": "New Zealand", "NP": "Nepal", "NR": "Nauru", "NU": "Niue", "CK": "Cook Islands", "CI": "Cote d'Ivoire", "CH": "Switzerland", "CO": "Colombia", "CN": "China", "CM": "Cameroon", "CL": "Chile", "CC": "Cocos (Keeling) Islands", "CA": "Canada", "CG": "Congo", "CF": "Central African Republic", "CD": "Congo, The Democratic Republic of the", "CZ": "Czech Republic", "CY": "Cyprus", "CX": "Christmas Island", "CR": "Costa Rica", "CV": "Cape Verde", "CU": "Cuba", "SZ": "Swaziland", "SY": "Syrian Arab Republic", "KG": "Kyrgyzstan", "KE": "Kenya", "SR": "Suriname", "KI": "Kiribati", "KH": "Cambodia", "KN": "Saint Kitts and Nevis", "KM": "Comoros", "ST": "Sao Tome and Principe", "SK": "Slovakia", "KR": "Korea, Republic of", "SI": "Slovenia", "KP": "Korea, Democratic People's Republic of", "KW": "Kuwait", "SN": "Senegal", "SM": "San Marino", "SL": "Sierra Leone", "SC": "Seychelles", "KZ": "Kazakhstan", "KY": "Cayman Islands", "SG": "Singapore", "SE": "Sweden", "SD": "Sudan", "DO": "Dominican Republic", "DM": "Dominica", "DJ": "Djibouti", "DK": "Denmark", "VG": "Virgin Islands, British", "DE": "Germany", "YE": "Yemen", "DZ": "Algeria", "US": "United States", "UY": "Uruguay", "YT": "Mayotte", "UM": "United States Minor Outlying Islands", "LB": "Lebanon", "LC": "Saint Lucia", "LA": "Lao People's Democratic Republic", "TV": "Tuvalu", "TW": "Taiwan", "TT": "Trinidad and Tobago", "TR": "Turkey", "LK": "Sri Lanka", "LI": "Liechtenstein", "A1": "Anonymous Proxy", "TO": "Tonga", "LT": "Lithuania", "A2": "Satellite Provider", "LR": "Liberia", "LS": "Lesotho", "TH": "Thailand", "TF": "French Southern Territories", "TG": "Togo", "TD": "Chad", "TC": "Turks and Caicos Islands", "LY": "Libyan Arab Jamahiriya", "VA": "Holy See (Vatican City State)", "VC": "Saint Vincent and the Grenadines", "AE": "United Arab Emirates", "AD": "Andorra", "AG": "Antigua and Barbuda", "AF": "Afghanistan", "AI": "Anguilla", "VI": "Virgin Islands, U.S.", "IS": "Iceland", "IR": "Iran, Islamic Republic of", "AM": "Armenia", "AL": "Albania", "AO": "Angola", "AN": "Netherlands Antilles", "AQ": "Antarctica", "AP": "Asia/Pacific Region", "AS": "American Samoa", "AR": "Argentina", "AU": "Australia", "AT": "Austria", "AW": "Aruba", "IN": "India", "AX": "Aland Islands", "AZ": "Azerbaijan", "IE": "Ireland", "ID": "Indonesia", "UA": "Ukraine", "QA": "Qatar", "MZ": "Mozambique"}, function(k, v) {
  109. countries.push({id: k, text: v});
  110. });
  111. $('#country').editable({
  112. source: countries,
  113. select2: {
  114. width: 200,
  115. placeholder: 'Select country',
  116. allowClear: true
  117. }
  118. });
  119. $('#address').editable({
  120. value: {
  121. city: "Kyiv",
  122. street: "Revutskogo",
  123. building: "44"
  124. },
  125. validate: function(value) {
  126. if(value.city == '') return 'city is required!';
  127. },
  128. display: function(value) {
  129. if(!value) {
  130. $(this).empty();
  131. return;
  132. }
  133. var html = '<b>' + $('<div>').text(value.city).html() + '</b>, ' + $('<div>').text(value.street).html() + ' st., bld. ' + $('<div>').text(value.building).html();
  134. $(this).html(html);
  135. }
  136. });
  137. $('#user .editable').on('hidden', function(e, reason){
  138. if(reason === 'save' || reason === 'nochange') {
  139. var $next = $(this).closest('tr').next().find('.editable');
  140. if($('#autoopen').is(':checked')) {
  141. setTimeout(function() {
  142. $next.editable('show');
  143. }, 300);
  144. } else {
  145. $next.focus();
  146. }
  147. }
  148. });
  149. /* Eof Form X-editable */
  150. }
  151. }
  152. gFormEditable.init();
  153. });