/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ var tags = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'), queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: { url: '/tags/getTags', filter: function (list) { tdata = $.map(list, function (tag, key) { return {id: key, name: tag}; }); return tdata; } } }); tags.initialize(); $('#deal-form').cloneya({ minimum: 1, maximum: 5, cloneThis: '.toclone', valueClone: false, dataClone: false, deepClone: true, cloneButton: '.col-sm-12 .clone', deleteButton: '.col-sm-12 .delete', clonePosition: 'after', serializeIndex: true, ignore: 'div.notToClone,.tags_wrap .bootstrap-tagsinput', preserveChildCount: true }).on('after_append.cloneya', function (event, toclone, newclone) { var dealId = newclone.attr('id'); clearForm(dealId); $("#" + dealId + " .link").typeWatch({ callback: function () { perFormFetchItem(dealId); }, wait: 750, highlight: true, allowSubmit: false, captureLength: 2 }); marketPlaceChangeHandler(); $("#" + dealId + " .tags").tagsinput(); $("#" + dealId + " .isInternationalShippingCharge").val('N'); $("#" + dealId + " .isShipping").val('Y'); $("#" + dealId + " .isfreeshipping").val('Y'); tamingselect(); selectSeller ("#" + dealId + " .seller", "#" + dealId + " .seller-id"); getDeployPoints('amounNeededToDeploy|pointsNeededToDeploy', 'deal', 'up'); }).on('remove.cloneya', function (event, clone) { getDeployPoints('amounNeededToDeploy|pointsNeededToDeploy', 'deal', 'down'); }); $(".link").typeWatch({ callback: function () { perFormFetchItem('deal0'); }, wait: 750, highlight: true, allowSubmit: false, captureLength: 2 }); $("#tags").tagsinput({ maxTags: 5, maxChars: 14 // typeaheadjs: { // name: 'tags', // displayKey: 'name', // valueKey: 'name', // source: tags.ttAdapter() // } }); $("#searchtags").tagsinput({ typeaheadjs: { name: 'tags', displayKey: 'name', valueKey: 'name', //valueKey: 'id', source: tags.ttAdapter() } }); $(document).on("keypress",".bootstrap-tagsinput input",function(e){ if(e.keyCode == 13) { e.preventDefault(); return false; } }); $(".custom-select").on('change', 'select', function () { $(this).addClass('select-changed'); var self = this; setTimeout(function () { $(self).removeClass('select-changed'); }, 1000); }); $('#sale-form').cloneya({ minimum: 1, maximum: 5, cloneThis: '.toclone', valueClone: false, dataClone: false, deepClone: true, cloneButton: '.col-sm-12 .clone', deleteButton: '.col-sm-12 .delete', clonePosition: 'after', serializeIndex: true, ignore: 'div.notToClone,.tags_wrap .bootstrap-tagsinput', preserveChildCount: true }).on('after_append.cloneya', function (event, toclone, newclone) { var saleId = newclone.attr('id'); clearForm(saleId); $("#" + saleId + " .tags").tagsinput(); $("#" + saleId + " .shipping_price").hide(); //datepicker in clonya selectSeller ("#" + saleId + " .seller", "#" + saleId + " .seller-id"); $(this).find(".datepicker").each(function() { $(this).removeAttr("id").removeClass("hasDatepicker"); $(".datepicker").datepicker({ //yearRange: "1950:2020", changeMonth: true, changeYear: true, dateFormat: 'd-m-yy' }); }); getDeployPoints('amounNeededToDeploy|pointsNeededToDeploy', 'sale', 'up'); }).on('remove.cloneya', function (event, clone) { getDeployPoints('amounNeededToDeploy|pointsNeededToDeploy', 'sale', 'down'); }); $('#voucher-form').cloneya({ minimum: 1, maximum: 5, cloneThis: '.toclone', valueClone: false, dataClone: false, deepClone: true, cloneButton: '.col-sm-12 .clone', deleteButton: '.col-sm-12 .delete', clonePosition: 'after', serializeIndex: true, ignore: 'div.notToClone,.tags_wrap .bootstrap-tagsinput', preserveChildCount: true }).on('after_append.cloneya', function (event, toclone, newclone) { var voucherId = newclone.attr('id'); clearForm(voucherId); $("#" + voucherId + " .tags").tagsinput(); $("#" + voucherId + " .shipping_price").hide(); selectSeller ("#" + voucherId + " .seller", "#" + voucherId + " .seller-id"); //datepicker in clonya $(this).find(".datepicker").each(function() { $(this).removeAttr("id").removeClass("hasDatepicker"); $(".datepicker").datepicker({ //yearRange: "1950:2020", changeMonth: true, changeYear: true, dateFormat: 'd-m-yy' }); }); getDeployPoints('amounNeededToDeploy|pointsNeededToDeploy', 'voucher', 'up'); }).on('remove.cloneya', function (event, clone) { getDeployPoints('amounNeededToDeploy|pointsNeededToDeploy', 'voucher', 'down'); }); $(function() { $( ".datepicker" ).datepicker({ changeMonth: true, changeYear: true, dateFormat: 'd-m-yy' }); }); // default call for autocomplete store list selectSeller('.seller', '.seller-id'); function getDeployPoints(setting, productType, action) { $.ajax({ url: "/settings/getoption", type: "POST", dataType: "json", delay: 200, data: {option: setting}, success: function (data) { if(data.status != 'success') { alert("Something went wrong. Please try again.") return false; } else { if(action == 'up') { $("."+productType+"Price").text((parseInt($("."+productType+"Price").text()) + parseInt(data.amounNeededToDeploy)).toFixed(2)); $("."+productType+"Points").text((parseInt($("."+productType+"Points").text()) + parseInt(data.pointsNeededToDeploy)).toFixed(0)); } else if(action == 'down') { $("."+productType+"Price").text((parseInt($("."+productType+"Price").text()) - parseInt(data.amounNeededToDeploy)).toFixed(2)); $("."+productType+"Points").text((parseInt($("."+productType+"Points").text()) - parseInt(data.pointsNeededToDeploy)).toFixed(0)); } return;// data.value; } } }); } function selectSeller(selector, updater) { $(selector).autocomplete({ source: function (request, response) { $.ajax({ url: "/store/get", type: "GET", dataType: "json", delay: 200, data: {keyword: request.term}, success: function (data) { if(data.length == 0) { $(updater).val(''); return false; } else { response($.map(data, function (item) { return { label: item.name, avatar: item.picLocation, //rep: item.Reputation, value: item.id }; })); } } }) }, select: function (event, ui) { $(updater).val(ui.item.value); $(selector).val(ui.item.label); // alert(ui.item ? ("You picked '" + ui.item.label) // : "Nothing selected, input was " + this.value); return false; } }).data("ui-autocomplete")._renderItem = function (ul, item) { var inner_html = '
'+item.label+'

'; return $("
  • ") .data("ui-autocomplete-item", item) .append(inner_html) .appendTo(ul); }; }