sample.js 322 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665
  1. /*jshint -W030 */ // Expected an assignment or function call and instead saw an expression (a && a.fun1())
  2. /*jshint -W004 */ // {a} is already defined (can use let instead of var in es6)
  3. var spreadNS = GC.Spread.Sheets;
  4. var DataValidation = spreadNS.DataValidation;
  5. var ConditionalFormatting = spreadNS.ConditionalFormatting;
  6. var ComparisonOperators = ConditionalFormatting.ComparisonOperators;
  7. var Calc = GC.Spread.CalcEngine;
  8. var ExpressionType = Calc.ExpressionType;
  9. var SheetsCalc = spreadNS.CalcEngine;
  10. var Sparklines = spreadNS.Sparklines;
  11. var isSafari = (function () {
  12. var tem, M = navigator.userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
  13. if (!/trident/i.test(M[1]) && M[1] !== 'Chrome') {
  14. M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
  15. if ((tem = navigator.userAgent.match(/version\/(\d+)/i)) != null) M.splice(1, 1, tem[1]);
  16. return M[0].toLowerCase() === "safari";
  17. }
  18. return false;
  19. })();
  20. var isIE = navigator.userAgent.toLowerCase().indexOf('compatible') < 0 && /(trident)(?:.*? rv ([\w.]+)|)/.exec(navigator.userAgent.toLowerCase()) !== null;
  21. var DOWNLOAD_DIALOG_WIDTH = 300;
  22. var spread, excelIO;
  23. var tableIndex = 1, pictureIndex = 1;
  24. var fbx, isShiftKey = false;
  25. var resourceMap = {},
  26. conditionalFormatTexts = {};
  27. function toggleState() {
  28. var $element = $(this),
  29. $parent = $element.parent(),
  30. $content = $parent.siblings(".insp-group-content"),
  31. $target = $parent.find("span.group-state"),
  32. collapsed = $target.hasClass("fa-caret-right");
  33. if (collapsed) {
  34. $target.removeClass("fa-caret-right").addClass("fa-caret-down");
  35. $content.slideToggle("fast");
  36. } else {
  37. $target.addClass("fa-caret-right").removeClass("fa-caret-down");
  38. $content.slideToggle("fast");
  39. }
  40. }
  41. function updateMergeButtonsState() {
  42. var sheet = spread.getActiveSheet();
  43. var sels = sheet.getSelections(),
  44. mergable = false,
  45. unmergable = false;
  46. sels.forEach(function (range) {
  47. var ranges = sheet.getSpans(range),
  48. spanCount = ranges.length;
  49. if (!mergable) {
  50. if (spanCount > 1 || (spanCount === 0 && (range.rowCount > 1 || range.colCount > 1))) {
  51. mergable = true;
  52. } else if (spanCount === 1) {
  53. var range2 = ranges[0];
  54. if (range2.row !== range.row || range2.col !== range.col ||
  55. range2.rowCount !== range2.rowCount || range2.colCount !== range.colCount) {
  56. mergable = true;
  57. }
  58. }
  59. }
  60. if (!unmergable) {
  61. unmergable = spanCount > 0;
  62. }
  63. });
  64. $("#mergeCells").attr("disabled", mergable ? null : "disabled");
  65. $("#unmergeCells").attr("disabled", unmergable ? null : "disabled");
  66. }
  67. function updateCellStyleState(sheet, row, column) {
  68. var style = sheet.getActualStyle(row, column);
  69. if (style) {
  70. var sfont = style.font;
  71. // Font
  72. var font
  73. if (sfont) {
  74. font = parseFont(sfont);
  75. setFontStyleButtonActive("bold", ["bold", "bolder", "700", "800", "900"].indexOf(font.fontWeight) !== -1);
  76. setFontStyleButtonActive("italic", font.fontStyle !== 'normal');
  77. setDropDownText($("#cellTab div.insp-dropdown-list[data-name='fontFamily']"), font.fontFamily.replace(/'/g, ""));
  78. setDropDownText($("#cellTab div.insp-dropdown-list[data-name='fontSize']"), parseFloat(font.fontSize));
  79. }
  80. var underline = spreadNS.TextDecorationType.underline,
  81. linethrough = spreadNS.TextDecorationType.lineThrough,
  82. overline = spreadNS.TextDecorationType.overline,
  83. textDecoration = style.textDecoration;
  84. setFontStyleButtonActive("underline", textDecoration && ((textDecoration & underline) === underline));
  85. setFontStyleButtonActive("strikethrough", textDecoration && ((textDecoration & linethrough) === linethrough));
  86. setFontStyleButtonActive("overline", textDecoration && ((textDecoration & overline) === overline));
  87. setColorValue("foreColor", style.foreColor || "#000");
  88. setColorValue("backColor", style.backColor || "#fff");
  89. // Alignment
  90. setRadioButtonActive("hAlign", style.hAlign); // general (3, auto detect) without setting button just like Excel
  91. setRadioButtonActive("vAlign", style.vAlign);
  92. setCheckValue("wrapText", style.wordWrap);
  93. //cell padding
  94. var cellPadding = style.cellPadding;
  95. if (cellPadding) {
  96. setTextValue("cellPadding", cellPadding);
  97. } else {
  98. setTextValue("cellPadding", "");
  99. }
  100. //watermark
  101. var watermark = style.watermark;
  102. if (watermark) {
  103. setTextValue("watermark", watermark);
  104. } else {
  105. setTextValue("watermark", "");
  106. }
  107. //label options
  108. var labelOptions = style.labelOptions;
  109. if (labelOptions) {
  110. var lFont = labelOptions.font;
  111. if (lFont) {
  112. font = parseFont(lFont);
  113. setFontStyleButtonActive("labelBold", ["bold", "bolder", "700", "800", "900"].indexOf(font.fontWeight) !== -1);
  114. setFontStyleButtonActive("labelItalic", font.fontStyle !== 'normal');
  115. setDropDownText($("#cellTab div.insp-dropdown-list[data-name='labelFontFamily']"), font.fontFamily.replace(/'/g, ""));
  116. setDropDownText($("#cellTab div.insp-dropdown-list[data-name='labelFontSize']"), parseFloat(font.fontSize));
  117. } else {
  118. setFontStyleButtonActive("labelBold", ["bold", "bolder", "700", "800", "900"].indexOf(font.fontWeight) !== -1);
  119. setFontStyleButtonActive("labelItalic", font.fontStyle !== 'normal');
  120. setDropDownText($("#cellTab div.insp-dropdown-list[data-name='labelFontFamily']"), font.fontFamily.replace(/'/g, ""));
  121. setDropDownText($("#cellTab div.insp-dropdown-list[data-name='labelFontSize']"), parseFloat(font.fontSize));
  122. }
  123. setColorValue("labelForeColor", labelOptions.foreColor || "#000");
  124. setTextValue("labelMargin", labelOptions.margin || "");
  125. setDropDownValueByIndex($("#cellLabelVisibility"), labelOptions.visibility === undefined ? 2 : labelOptions.visibility);
  126. setDropDownValueByIndex($("#cellLabelAlignment"), labelOptions.alignment || 0);
  127. }
  128. }
  129. }
  130. function setFontStyleButtonActive(name, active) {
  131. var $target = $("div.group-container>span[data-name='" + name + "']");
  132. if (active) {
  133. $target.addClass("active");
  134. } else {
  135. $target.removeClass("active");
  136. }
  137. }
  138. function setRadioButtonActive(name, index) {
  139. var $items = $("div.insp-radio-button-group[data-name='" + name + "'] div>span");
  140. $items.removeClass("active");
  141. $($items[index]).addClass("active");
  142. }
  143. function parseFont(font) {
  144. var fontFamily = null,
  145. fontSize = null,
  146. fontStyle = "normal",
  147. fontWeight = "normal",
  148. fontVariant = "normal",
  149. lineHeight = "normal";
  150. var elements = font.split(/\s+/);
  151. var element;
  152. while ((element = elements.shift())) {
  153. switch (element) {
  154. case "normal":
  155. break;
  156. case "italic":
  157. case "oblique":
  158. fontStyle = element;
  159. break;
  160. case "small-caps":
  161. fontVariant = element;
  162. break;
  163. case "bold":
  164. case "bolder":
  165. case "lighter":
  166. case "100":
  167. case "200":
  168. case "300":
  169. case "400":
  170. case "500":
  171. case "600":
  172. case "700":
  173. case "800":
  174. case "900":
  175. fontWeight = element;
  176. break;
  177. default:
  178. if (!fontSize) {
  179. var parts = element.split("/");
  180. fontSize = parts[0];
  181. if (fontSize.indexOf("px") !== -1) {
  182. fontSize = px2pt(parseFloat(fontSize)) + 'pt';
  183. }
  184. if (parts.length > 1) {
  185. lineHeight = parts[1];
  186. if (lineHeight.indexOf("px") !== -1) {
  187. lineHeight = px2pt(parseFloat(lineHeight)) + 'pt';
  188. }
  189. }
  190. break;
  191. }
  192. fontFamily = element;
  193. if (elements.length)
  194. fontFamily += " " + elements.join(" ");
  195. return {
  196. "fontStyle": fontStyle,
  197. "fontVariant": fontVariant,
  198. "fontWeight": fontWeight,
  199. "fontSize": fontSize,
  200. "lineHeight": lineHeight,
  201. "fontFamily": fontFamily
  202. };
  203. }
  204. }
  205. return {
  206. "fontStyle": fontStyle,
  207. "fontVariant": fontVariant,
  208. "fontWeight": fontWeight,
  209. "fontSize": fontSize,
  210. "lineHeight": lineHeight,
  211. "fontFamily": fontFamily
  212. };
  213. }
  214. var tempSpan = $("<span></span>");
  215. function px2pt(pxValue) {
  216. tempSpan.css({
  217. "font-size": "96pt",
  218. "display": "none"
  219. });
  220. tempSpan.appendTo($(document.body));
  221. var tempPx = tempSpan.css("font-size");
  222. if (tempPx.indexOf("px") !== -1) {
  223. var tempPxValue = parseFloat(tempPx);
  224. return Math.round(pxValue * 96 / tempPxValue);
  225. }
  226. else { // when browser have not convert pt to px, use 96 DPI.
  227. return Math.round(pxValue * 72 / 96);
  228. }
  229. }
  230. function processRadioButtonClicked(key, $item, $group) {
  231. var name = $item.data("name");
  232. // only need process when click on radio button or relate label like text
  233. if ($item.hasClass("radiobutton") || $item.hasClass("text")) {
  234. $group.find("div.radiobutton").removeClass("checked");
  235. $group.find("div.radiobutton[data-name='" + name + "']").addClass("checked");
  236. switch (key) {
  237. case "referenceStyle":
  238. setReferenceStyle(name);
  239. break;
  240. case "slicerMoveAndSize":
  241. setSlicerSetting("moveSize", name);
  242. break;
  243. case "pictureMoveAndSize":
  244. var picture = _activePicture;
  245. if (name === "picture-move-size") {
  246. picture.dynamicMove(true);
  247. picture.dynamicSize(true);
  248. }
  249. if (name === "picture-move-nosize") {
  250. picture.dynamicMove(true);
  251. picture.dynamicSize(false);
  252. }
  253. if (name === "picture-nomove-size") {
  254. picture.dynamicMove(false);
  255. picture.dynamicSize(false);
  256. }
  257. break;
  258. }
  259. }
  260. }
  261. function setReferenceStyle(name) {
  262. var referenceStyle, columnHeaderAutoText;
  263. if (name === "a1style") {
  264. referenceStyle = spreadNS.ReferenceStyle.a1;
  265. columnHeaderAutoText = spreadNS.HeaderAutoText.letters;
  266. } else {
  267. referenceStyle = spreadNS.ReferenceStyle.r1c1;
  268. columnHeaderAutoText = spreadNS.HeaderAutoText.numbers;
  269. }
  270. spread.options.referenceStyle = referenceStyle;
  271. spread.sheets.forEach(function (sheet) {
  272. sheet.options.colHeaderAutoText = columnHeaderAutoText;
  273. });
  274. updatePositionBox(spread.getActiveSheet());
  275. }
  276. function checkedChanged() {
  277. var $element = $(this),
  278. name = $element.data("name");
  279. if ($element.hasClass("disabled")) {
  280. return;
  281. }
  282. // radio buttons need special process
  283. switch (name) {
  284. case "referenceStyle":
  285. case "slicerMoveAndSize":
  286. case "pictureMoveAndSize":
  287. processRadioButtonClicked(name, $(event.target), $element);
  288. return;
  289. }
  290. var $target = $("div.button", $element),
  291. value = !$target.hasClass("checked");
  292. var sheet = spread.getActiveSheet();
  293. $target.toggleClass("checked");
  294. spread.suspendPaint();
  295. var options = spread.options;
  296. switch (name) {
  297. case "allowCopyPasteExcelStyle":
  298. options.allowCopyPasteExcelStyle = value;
  299. break;
  300. case "allowExtendPasteRange":
  301. options.allowExtendPasteRange = value;
  302. break;
  303. case "referenceStyle":
  304. options.referenceStyle = (value ? spreadNS.ReferenceStyle.r1c1 : spreadNS.ReferenceStyle.a1);
  305. break;
  306. case "cutCopyIndicatorVisible":
  307. options.cutCopyIndicatorVisible = value;
  308. break;
  309. case "showVerticalScrollbar":
  310. options.showVerticalScrollbar = value;
  311. break;
  312. case "showHorizontalScrollbar":
  313. options.showHorizontalScrollbar = value;
  314. break;
  315. case "scrollIgnoreHidden":
  316. options.scrollIgnoreHidden = value;
  317. break;
  318. case "scrollbarMaxAlign":
  319. options.scrollbarMaxAlign = value;
  320. break;
  321. case "scrollbarShowMax":
  322. options.scrollbarShowMax = value;
  323. break;
  324. case "tabStripVisible":
  325. options.tabStripVisible = value;
  326. break;
  327. case "newTabVisible":
  328. options.newTabVisible = value;
  329. break;
  330. case "tabEditable":
  331. options.tabEditable = value;
  332. break;
  333. case "showTabNavigation":
  334. options.tabNavigationVisible = value;
  335. break;
  336. case "showDragDropTip":
  337. options.showDragDropTip = value;
  338. break;
  339. case "showDragFillTip":
  340. options.showDragFillTip = value;
  341. break;
  342. case "sheetVisible":
  343. var sheetIndex = $target.data("sheetIndex"),
  344. sheetName = $target.data("sheetName"),
  345. selectedSheet = spread.sheets[sheetIndex];
  346. // be sure related sheet not changed (such add / remove sheet, rename sheet)
  347. if (selectedSheet && selectedSheet.name() === sheetName) {
  348. selectedSheet.visible(value);
  349. } else {
  350. console.log("selected sheet' info was changed, please select the sheet and set visible again.");
  351. }
  352. break;
  353. case "allowUserDragDrop":
  354. spread.options.allowUserDragDrop = value;
  355. break;
  356. case "allowUserDragFill":
  357. spread.options.allowUserDragFill = value;
  358. break;
  359. case "allowZoom":
  360. spread.options.allowUserZoom = value;
  361. break;
  362. case "allowOverflow":
  363. spread.sheets.forEach(function (sheet) {
  364. sheet.options.allowCellOverflow = value;
  365. });
  366. break;
  367. case "showDragFillSmartTag":
  368. spread.options.showDragFillSmartTag = value;
  369. break;
  370. case "showVerticalGridline":
  371. sheet.options.gridline.showVerticalGridline = value;
  372. break;
  373. case "showHorizontalGridline":
  374. sheet.options.gridline.showHorizontalGridline = value;
  375. break;
  376. case "showRowHeader":
  377. sheet.options.rowHeaderVisible = value;
  378. break;
  379. case "showColumnHeader":
  380. sheet.options.colHeaderVisible = value;
  381. break;
  382. case "wrapText":
  383. setWordWrap(sheet);
  384. break;
  385. case "hideSelection":
  386. spread.options.hideSelection = value;
  387. break;
  388. case "showRowOutline":
  389. sheet.showRowOutline(value);
  390. break;
  391. case "showColumnOutline":
  392. sheet.showColumnOutline(value);
  393. break;
  394. case "highlightInvalidData":
  395. spread.options.highlightInvalidData = value;
  396. break;
  397. /* table realted items */
  398. case "tableFilterButton":
  399. _activeTable && _activeTable.filterButtonVisible(value);
  400. break;
  401. case "tableHeaderRow":
  402. _activeTable && _activeTable.showHeader(value);
  403. break;
  404. case "tableTotalRow":
  405. _activeTable && _activeTable.showFooter(value);
  406. break;
  407. case "tableBandedRows":
  408. _activeTable && _activeTable.bandRows(value);
  409. break;
  410. case "tableBandedColumns":
  411. _activeTable && _activeTable.bandColumns(value);
  412. break;
  413. case "tableFirstColumn":
  414. _activeTable && _activeTable.highlightFirstColumn(value);
  415. break;
  416. case "tableLastColumn":
  417. _activeTable && _activeTable.highlightLastColumn(value);
  418. break;
  419. /* table realted items (end) */
  420. /* comment related items */
  421. case "commentDynamicSize":
  422. _activeComment && _activeComment.dynamicSize(value);
  423. break;
  424. case "commentDynamicMove":
  425. _activeComment && _activeComment.dynamicMove(value);
  426. break;
  427. case "commentLockText":
  428. _activeComment && _activeComment.lockText(value);
  429. break;
  430. case "commentShowShadow":
  431. _activeComment && _activeComment.showShadow(value);
  432. break;
  433. /* comment related items (end) */
  434. /* picture related items */
  435. case "pictureDynamicSize":
  436. _activePicture && _activePicture.dynamicSize(value);
  437. break;
  438. case "pictureDynamicMove":
  439. _activePicture && _activePicture.dynamicMove(value);
  440. break;
  441. case "pictureFixedPosition":
  442. _activePicture && _activePicture.fixedPosition(value);
  443. break;
  444. /* picture related items (end) */
  445. /* protect sheet realted items */
  446. case "checkboxProtectSheet":
  447. syncProtectSheetRelatedItems(sheet, value);
  448. break;
  449. case "checkboxSelectLockedCells":
  450. setProtectionOption(sheet, "allowSelectLockedCells", value);
  451. break;
  452. case "checkboxSelectUnlockedCells":
  453. setProtectionOption(sheet, "allowSelectUnlockedCells", value);
  454. break;
  455. case "checkboxSort":
  456. setProtectionOption(sheet, "allowSort", value);
  457. break;
  458. case "checkboxUseAutoFilter":
  459. setProtectionOption(sheet, "allowFilter", value);
  460. break;
  461. case "checkboxResizeRows":
  462. setProtectionOption(sheet, "allowResizeRows", value);
  463. break;
  464. case "checkboxResizeColumns":
  465. setProtectionOption(sheet, "allowResizeColumns", value);
  466. break;
  467. case "checkboxEditObjects":
  468. setProtectionOption(sheet, "allowEditObjects", value);
  469. break;
  470. /* protect sheet realted items (end) */
  471. /* slicer related items */
  472. case "displaySlicerHeader":
  473. setSlicerSetting("showHeader", value);
  474. break;
  475. case "lockSlicer":
  476. setSlicerSetting("lock", value);
  477. break;
  478. /* slicer related items (end) */
  479. default:
  480. console.log("not added code for", name);
  481. break;
  482. }
  483. spread.resumePaint();
  484. }
  485. function updateNumberProperty() {
  486. var $element = $(this),
  487. $parent = $element.parent(),
  488. name = $parent.data("name"),
  489. value = parseInt($element.val(), 10);
  490. if (isNaN(value)) {
  491. return;
  492. }
  493. var sheet = spread.getActiveSheet();
  494. spread.suspendPaint();
  495. switch (name) {
  496. case "rowCount":
  497. sheet.setRowCount(value);
  498. break;
  499. case "columnCount":
  500. sheet.setColumnCount(value);
  501. break;
  502. case "frozenRowCount":
  503. sheet.frozenRowCount(value);
  504. break;
  505. case "frozenColumnCount":
  506. sheet.frozenColumnCount(value);
  507. break;
  508. case "trailingFrozenRowCount":
  509. sheet.frozenTrailingRowCount(value);
  510. break;
  511. case "trailingFrozenColumnCount":
  512. sheet.frozenTrailingColumnCount(value);
  513. break;
  514. case "commentBorderWidth":
  515. _activeComment && _activeComment.borderWidth(value);
  516. break;
  517. case "commentOpacity":
  518. _activeComment && _activeComment.opacity(value / 100);
  519. break;
  520. case "pictureBorderWidth":
  521. _activePicture && _activePicture.borderWidth(value);
  522. break;
  523. case "pictureBorderRadius":
  524. _activePicture && _activePicture.borderRadius(value);
  525. break;
  526. case "slicerColumnNumber":
  527. setSlicerSetting("columnCount", value);
  528. break;
  529. case "slicerButtonHeight":
  530. setSlicerSetting("itemHeight", value);
  531. break;
  532. case "slicerButtonWidth":
  533. setSlicerSetting("itemWidth", value);
  534. break;
  535. default:
  536. console.log("updateNumberProperty need add for", name);
  537. break;
  538. }
  539. spread.resumePaint();
  540. }
  541. function updateStringProperty() {
  542. var $element = $(this),
  543. $parent = $element.parent(),
  544. name = $parent.data("name"),
  545. value = $element.val();
  546. var sheet = spread.getActiveSheet();
  547. switch (name) {
  548. case "sheetName":
  549. if (value && value !== sheet.name()) {
  550. try {
  551. sheet.name(value);
  552. } catch (ex) {
  553. alert(getResource("messages.duplicatedSheetName"));
  554. $element.val(sheet.name());
  555. }
  556. }
  557. break;
  558. case "tableName":
  559. if (value && _activeTable && value !== _activeTable.name()) {
  560. if (!sheet.tables.findByName(value)) {
  561. _activeTable.name(value);
  562. } else {
  563. alert(getResource("messages.duplicatedTableName"));
  564. $element.val(_activeTable.name());
  565. }
  566. }
  567. break;
  568. case "commentPadding":
  569. setCommentPadding(value);
  570. break;
  571. case "customFormat":
  572. setFormatter(value);
  573. break;
  574. case "slicerName":
  575. setSlicerSetting("name", value);
  576. break;
  577. case "slicerCaptionName":
  578. setSlicerSetting("captionName", value);
  579. break;
  580. case "watermark":
  581. setWatermark(sheet, value);
  582. break;
  583. case "cellPadding":
  584. setCellPadding(sheet, value);
  585. break;
  586. case "labelmargin":
  587. setLabelOptions(sheet, value, "margin");
  588. break;
  589. default:
  590. console.log("updateStringProperty w/o process of ", name);
  591. break;
  592. }
  593. }
  594. function setCommentPadding(padding) {
  595. if (_activeComment && padding) {
  596. var para = padding.split(",");
  597. if (para.length === 1) {
  598. _activeComment.padding(new spreadNS.Comments.Padding(parseInt(para[0], 10)));
  599. } else if (para.length === 4) {
  600. _activeComment.padding(new spreadNS.Comments.Padding(parseInt(para[0], 10), parseInt(para[1], 10), parseInt(para[2], 10), parseInt(para[3], 10)));
  601. }
  602. }
  603. }
  604. function fillSheetNameList($container) {
  605. var html = "";
  606. // unbind event if present
  607. $container.find(".menu-item").off('click');
  608. spread.sheets.forEach(function (sheet, index) {
  609. html += '<div class="menu-item"><div class="image"></div><div class="text" data-value="' + index + '">' + sheet.name() + '</div></div>';
  610. });
  611. $container.html(html);
  612. // bind event for new added elements
  613. $container.find(".menu-item").on('click', itemSelected);
  614. }
  615. function syncSpreadPropertyValues() {
  616. var options = spread.options;
  617. // General
  618. setCheckValue("allowUserDragDrop", options.allowUserDragDrop);
  619. setCheckValue("allowUserDragFill", options.allowUserDragFill);
  620. setCheckValue("allowZoom", options.allowUserZoom);
  621. setCheckValue("allowOverflow", spread.getActiveSheet().options.allowCellOverflow);
  622. setCheckValue("showDragFillSmartTag", options.showDragFillSmartTag);
  623. setDropDownValue("resizeZeroIndicator", options.resizeZeroIndicator);
  624. // Calculation
  625. setRadioItemChecked("referenceStyle", options.referenceStyle === spreadNS.ReferenceStyle.r1c1 ? "r1c1style" : "a1style");
  626. // Scroll Bar
  627. setCheckValue("showVerticalScrollbar", options.showVerticalScrollbar);
  628. setCheckValue("showHorizontalScrollbar", options.showHorizontalScrollbar);
  629. setCheckValue("scrollbarMaxAlign", options.scrollbarMaxAlign);
  630. setCheckValue("scrollbarShowMax", options.scrollbarShowMax);
  631. setCheckValue("scrollIgnoreHidden", options.scrollIgnoreHidden);
  632. // TabStrip
  633. setCheckValue("tabStripVisible", options.tabStripVisible);
  634. setCheckValue("newTabVisible", options.newTabVisible);
  635. setCheckValue("tabEditable", options.tabEditable);
  636. setCheckValue("allowSheetReorder", options.allowSheetReorder);
  637. setCheckValue("showTabNavigation", options.tabNavigationVisible);
  638. // Color
  639. setColorValue("spreadBackcolor", options.backColor);
  640. setColorValue("grayAreaBackcolor", options.grayAreaBackColor);
  641. // Tip
  642. setDropDownValue($("div.insp-dropdown-list[data-name='scrollTip']"), options.showScrollTip);
  643. setDropDownValue($("div.insp-dropdown-list[data-name='resizeTip']"), options.showResizeTip);
  644. setCheckValue("showDragDropTip", options.showDragDropTip);
  645. setCheckValue("showDragFillTip", options.showDragFillTip);
  646. // Cut / Copy Indicator
  647. setCheckValue("cutCopyIndicatorVisible", options.cutCopyIndicatorVisible);
  648. setColorValue("cutCopyIndicatorBorderColor", options.cutCopyIndicatorBorderColor);
  649. // Data validation
  650. setCheckValue("highlightInvalidData", options.highlightInvalidData);
  651. }
  652. function syncForzenProperties(sheet) {
  653. setNumberValue("frozenRowCount", sheet.frozenRowCount());
  654. setNumberValue("frozenColumnCount", sheet.frozenColumnCount());
  655. setNumberValue("trailingFrozenRowCount", sheet.frozenTrailingRowCount());
  656. setNumberValue("trailingFrozenColumnCount", sheet.frozenTrailingColumnCount());
  657. }
  658. function syncSheetPropertyValues() {
  659. var sheet = spread.getActiveSheet(),
  660. options = sheet.options;
  661. // General
  662. setNumberValue("rowCount", sheet.getRowCount());
  663. setNumberValue("columnCount", sheet.getColumnCount());
  664. setTextValue("sheetName", sheet.name());
  665. setColorValue("sheetTabColor", options.sheetTabColor);
  666. // Grid Line
  667. setCheckValue("showVerticalGridline", options.gridline.showVerticalGridline);
  668. setCheckValue("showHorizontalGridline", options.gridline.showHorizontalGridline);
  669. setColorValue("gridlineColor", options.gridline.color);
  670. // Header
  671. setCheckValue("showRowHeader", options.rowHeaderVisible);
  672. setCheckValue("showColumnHeader", options.colHeaderVisible);
  673. // Freeze
  674. setColorValue("frozenLineColor", options.frozenlineColor);
  675. syncForzenProperties(sheet);
  676. // Selection
  677. setDropDownValue($("#sheetTab div.insp-dropdown-list[data-name='selectionPolicy']"), sheet.selectionPolicy());
  678. setDropDownValue($("#sheetTab div.insp-dropdown-list[data-name='selectionUnit']"), sheet.selectionUnit());
  679. setColorValue("selectionBorderColor", options.selectionBorderColor);
  680. setColorValue("selectionBackColor", options.selectionBackColor);
  681. setCheckValue("hideSelection", spread.options.hideSelection);
  682. // Protection
  683. var isProtected = options.isProtected;
  684. setCheckValue("checkboxProtectSheet", isProtected);
  685. syncProtectSheetRelatedItems(sheet, isProtected);
  686. getCurrentSheetProtectionOption(sheet);
  687. updateCellStyleState(sheet, sheet.getActiveRowIndex(), sheet.getActiveColumnIndex());
  688. // Zoom
  689. setZoomFactor(sheet.zoom());
  690. // Group
  691. setCheckValue("showRowOutline", sheet.showRowOutline());
  692. setCheckValue("showColumnOutline", sheet.showColumnOutline());
  693. if (!$(sheet).data("bind")) {
  694. $(sheet).data("bind", true);
  695. sheet.bind(spreadNS.Events.UserZooming, function (event, args) {
  696. setZoomFactor(args.newZoomFactor);
  697. });
  698. sheet.bind(spreadNS.Events.RangeChanged, function (event, args) {
  699. if (args.action === spreadNS.RangeChangedAction.clear) {
  700. // check special type items and switch to cell tab (laze process)
  701. if (isSpecialTabSelected()) {
  702. onCellSelected();
  703. }
  704. }
  705. });
  706. sheet.bind(spreadNS.Events.FloatingObjectRemoved, function (event, args) {
  707. // check special type items and switch to cell tab (laze process)
  708. if (isSpecialTabSelected()) {
  709. onCellSelected();
  710. }
  711. });
  712. sheet.bind(spreadNS.Events.CommentRemoved, function (event, args) {
  713. // check special type items and switch to cell tab (laze process)
  714. if (isSpecialTabSelected()) {
  715. onCellSelected();
  716. }
  717. });
  718. }
  719. }
  720. function setZoomFactor(zoom) {
  721. setDropDownText("#toolbar div.insp-dropdown-list[data-name='zoomSpread']", Math.round(zoom * 100) + "%");
  722. }
  723. function setNumberValue(name, value) {
  724. $("div.insp-number[data-name='" + name + "'] input.editor").val(value);
  725. }
  726. function getNumberValue(name) {
  727. return +$("div[data-name='" + name + "'] input.editor").val();
  728. }
  729. function setTextValue(name, value) {
  730. $("div.insp-text[data-name='" + name + "'] input.editor").val(value);
  731. }
  732. function getTextValue(name) {
  733. return $("div.insp-text[data-name='" + name + "'] input.editor").val();
  734. }
  735. function setCheckValue(name, value, options) {
  736. var $target = $("div.insp-checkbox[data-name='" + name + "'] div.button");
  737. if (value) {
  738. $target.addClass("checked");
  739. } else {
  740. $target.removeClass("checked");
  741. }
  742. if (options) {
  743. $target.data(options);
  744. }
  745. }
  746. function getCheckValue(name) {
  747. var $target = $("div.insp-checkbox[data-name='" + name + "'] div.button");
  748. return $target.hasClass("checked");
  749. }
  750. function setColorValue(name, value) {
  751. $("div.insp-color-picker[data-name='" + name + "'] div.color-view").css("background-color", value || "");
  752. }
  753. var _dropdownitem;
  754. var _colorpicker;
  755. var _needShow = true;
  756. var _handlePopupCloseEvents = 'mousedown touchstart MSPointerDown pointerdown'.split(' ');
  757. function processEventListenerHandleClosePopup(add) {
  758. if (add) {
  759. _handlePopupCloseEvents.forEach(function (value) {
  760. document.addEventListener(value, documentMousedownHandler, true);
  761. });
  762. } else {
  763. _handlePopupCloseEvents.forEach(function (value) {
  764. document.removeEventListener(value, documentMousedownHandler, true);
  765. });
  766. }
  767. }
  768. function showDropdown() {
  769. if (!_needShow) {
  770. _needShow = true;
  771. return;
  772. }
  773. var DROPDOWN_OFFSET = 10;
  774. var $element = $(this),
  775. $container = $element.parent(),
  776. name = $container.data("name"),
  777. targetId = $container.data("list-ref"),
  778. $target = $("#" + targetId);
  779. if ($target && !$target.hasClass("show")) {
  780. if (name === "sheetName") {
  781. fillSheetNameList($target);
  782. }
  783. $target.data("dropdown", this);
  784. _dropdownitem = $target[0];
  785. var $dropdown = $element,
  786. offset = $dropdown.offset();
  787. var height = $element.outerHeight(),
  788. targetHeight = $target.outerHeight(),
  789. width = $element.outerWidth(),
  790. targetWidth = $target.outerWidth(),
  791. top = offset.top + height;
  792. // adjust drop down' width to same
  793. if (targetWidth < width) {
  794. $target.width(width);
  795. }
  796. var $inspContainer = $(".insp-container"),
  797. maxTop = $inspContainer.height() + $inspContainer.offset().top;
  798. // adjust top when out of bottom range
  799. if (top + targetHeight + DROPDOWN_OFFSET > maxTop) {
  800. top = offset.top - targetHeight;
  801. }
  802. $target.css({
  803. top: top,
  804. left: offset.left - $target.width() + $dropdown.width() + 16
  805. });
  806. // select corresponding item
  807. if (name === "borderLine") {
  808. var text = $("#border-line-type").attr("class");
  809. $("div.image", $target).removeClass("fa-check");
  810. $("div.text", $target).filter(function () {
  811. return $(this).find("div").attr("class") === text;
  812. }).siblings("div.image").addClass("fa fa-check");
  813. $("div.image.nocheck", $target).removeClass("fa-check");
  814. }
  815. else {
  816. var text = $("span.display", $dropdown).text();
  817. $("div.image", $target).removeClass("fa-check");
  818. $("div.text", $target).filter(function () {
  819. return $(this).text() === text;
  820. }).siblings("div.image").addClass("fa fa-check");
  821. // remove check for special items mark with nocheck class
  822. $("div.image.nocheck", $target).removeClass("fa-check");
  823. }
  824. $target.addClass("show");
  825. processEventListenerHandleClosePopup(true);
  826. }
  827. }
  828. function documentMousedownHandler(event) {
  829. var target = event.target,
  830. container = _dropdownitem || _colorpicker || $("#clearActionList:visible")[0] || $("#exportActionList:visible")[0];
  831. if (container) {
  832. if (container === target || $.contains(container, target)) {
  833. return;
  834. }
  835. // click on related item popup the dropdown, close it
  836. var dropdown = $(container).data("dropdown");
  837. if (dropdown && $.contains(dropdown, target)) {
  838. hidePopups();
  839. _needShow = false;
  840. return false;
  841. }
  842. }
  843. hidePopups();
  844. $("#passwordError").hide();
  845. }
  846. function hidePopups() {
  847. hideDropdown();
  848. hideColorPicker();
  849. hideClearActionDropDown();
  850. hideExportActionDropDown();
  851. }
  852. function hideClearActionDropDown() {
  853. if ($("#clearActionList:visible").length > 0) {
  854. $("#clearActionList").hide();
  855. processEventListenerHandleClosePopup(false);
  856. }
  857. }
  858. function hideExportActionDropDown() {
  859. if ($("#exportActionList:visible").length > 0) {
  860. $("#exportActionList").hide();
  861. processEventListenerHandleClosePopup(false);
  862. }
  863. }
  864. function hideDropdown() {
  865. if (_dropdownitem) {
  866. $(_dropdownitem).removeClass("show");
  867. _dropdownitem = null;
  868. }
  869. processEventListenerHandleClosePopup(false);
  870. }
  871. function showColorPicker() {
  872. if (!_needShow) {
  873. _needShow = true;
  874. return;
  875. }
  876. var MIN_TOP = 30, MIN_BOTTOM = 4;
  877. var $element = $(this),
  878. $container = $element.parent(),
  879. name = $container.data("name"),
  880. $target = $("#colorpicker");
  881. if ($target && !$target.hasClass("colorpicker-visible")) {
  882. $target.data("dropdown", this);
  883. // save related name for later use
  884. $target.data("name", name);
  885. var $nofill = $target.find("div.nofill-color");
  886. if ($container.hasClass("show-nofill-color")) {
  887. $nofill.show();
  888. } else {
  889. $nofill.hide();
  890. }
  891. _colorpicker = $target[0];
  892. var $dropdown = $element,
  893. offset = $dropdown.offset();
  894. var height = $target.height(),
  895. top = offset.top - (height - $element.height()) / 2 + 3, // 3 = padding (4) - border-width(1)
  896. yOffset = 0;
  897. if (top < MIN_TOP) {
  898. yOffset = MIN_TOP - top;
  899. top = MIN_TOP;
  900. } else {
  901. var $inspContainer = $(".insp-container"),
  902. maxTop = $inspContainer.height() + $inspContainer.offset().top;
  903. // adjust top when out of bottom range
  904. if (top + height > maxTop - MIN_BOTTOM) {
  905. var newTop = maxTop - MIN_BOTTOM - height;
  906. yOffset = newTop - top;
  907. top = newTop;
  908. }
  909. }
  910. $target.css({
  911. top: top,
  912. left: offset.left - $target.width() - 20
  913. });
  914. // v-center the pointer
  915. var $pointer = $target.find(".cp-pointer");
  916. $pointer.css({top: (height - 24) / 2 - yOffset}); // 24 = pointer height
  917. $target.addClass("colorpicker-visible");
  918. processEventListenerHandleClosePopup(true);
  919. }
  920. }
  921. function hideColorPicker() {
  922. if (_colorpicker) {
  923. $(_colorpicker).removeClass("colorpicker-visible");
  924. _colorpicker = null;
  925. }
  926. processEventListenerHandleClosePopup(false);
  927. }
  928. function itemSelected() {
  929. // get related dropdown item
  930. var dropdown = $(_dropdownitem).data("dropdown");
  931. hideDropdown();
  932. if (this.parentElement.id === "clearActionList") {
  933. processClearAction($(this.parentElement), $("div.text", this).data("value"));
  934. return;
  935. }
  936. if (this.parentElement.id === "exportActionList") {
  937. processExportAction($(this.parentElement), $("div.text", this).data("value"));
  938. return;
  939. }
  940. var sheet = spread.getActiveSheet();
  941. var name = $(dropdown.parentElement).data("name"),
  942. $text = $("div.text", this),
  943. dataValue = $text.data("value"), // data-value includes both number value and string value, should pay attention when use it
  944. numberValue = +dataValue,
  945. text = $text.text(),
  946. value = text,
  947. nameValue = dataValue || text;
  948. var options = spread.options;
  949. switch (name) {
  950. case "scrollTip":
  951. options.showScrollTip = numberValue;
  952. break;
  953. case "resizeTip":
  954. options.showResizeTip = numberValue;
  955. break;
  956. case "fontFamily":
  957. setStyleFont(sheet, "font-family", false, [value], value);
  958. break;
  959. case "labelFontFamily":
  960. setStyleFont(sheet, "font-family", true, [value], value);
  961. break;
  962. case "fontSize":
  963. value += "pt";
  964. setStyleFont(sheet, "font-size", false, [value], value);
  965. break;
  966. case "labelFontSize":
  967. value += "pt";
  968. setStyleFont(sheet, "font-size", true, [value], value);
  969. break;
  970. case "cellLabelVisibility":
  971. setLabelOptions(sheet, nameValue, "visibility");
  972. break;
  973. case "cellLabelAlignment":
  974. setLabelOptions(sheet, nameValue, "alignment");
  975. break;
  976. case "selectionPolicy":
  977. sheet.selectionPolicy(numberValue);
  978. break;
  979. case "selectionUnit":
  980. sheet.selectionUnit(numberValue);
  981. break;
  982. case "sheetName":
  983. var selectedSheet = spread.sheets[numberValue];
  984. setCheckValue("sheetVisible", selectedSheet.visible(), {
  985. sheetIndex: numberValue,
  986. sheetName: selectedSheet.name()
  987. });
  988. break;
  989. case "commentFontFamily":
  990. _activeComment && _activeComment.fontFamily(value);
  991. break;
  992. case "commentFontSize":
  993. value += "pt";
  994. _activeComment && _activeComment.fontSize(value);
  995. break;
  996. case "commentDisplayMode":
  997. _activeComment && _activeComment.displayMode(numberValue);
  998. break;
  999. case "commentFontStyle":
  1000. _activeComment && _activeComment.fontStyle(nameValue);
  1001. break;
  1002. case "commentFontWeight":
  1003. _activeComment && _activeComment.fontWeight(nameValue);
  1004. break;
  1005. case "commentBorderStyle":
  1006. _activeComment && _activeComment.borderStyle(nameValue);
  1007. break;
  1008. case "commentHorizontalAlign":
  1009. _activeComment && _activeComment.horizontalAlign(numberValue);
  1010. break;
  1011. case "pictureBorderStyle":
  1012. _activePicture && _activePicture.borderStyle(nameValue);
  1013. break;
  1014. case "pictureStretch":
  1015. _activePicture && _activePicture.pictureStretch(numberValue);
  1016. break;
  1017. case "conditionalFormat":
  1018. processConditionalFormatDetailSetting(nameValue);
  1019. break;
  1020. case "ruleType":
  1021. updateEnumTypeOfCF(numberValue);
  1022. break;
  1023. case "comparisonOperator":
  1024. processComparisonOperator(numberValue);
  1025. break;
  1026. case "iconSetType":
  1027. updateIconCriteriaItems(numberValue);
  1028. break;
  1029. case "minType":
  1030. processMinItems(numberValue, "minValue");
  1031. break;
  1032. case "midType":
  1033. processMidItems(numberValue, "midValue");
  1034. break;
  1035. case "maxType":
  1036. processMaxItems(numberValue, "maxValue");
  1037. break;
  1038. case "cellTypes":
  1039. processCellTypeSetting(nameValue);
  1040. break;
  1041. case "validatorType":
  1042. processDataValidationSetting(nameValue, value);
  1043. break;
  1044. case "numberValidatorComparisonOperator":
  1045. processNumberValidatorComparisonOperatorSetting(numberValue);
  1046. break;
  1047. case "dateValidatorComparisonOperator":
  1048. processDateValidatorComparisonOperatorSetting(numberValue);
  1049. break;
  1050. case "textLengthValidatorComparisonOperator":
  1051. processTextLengthValidatorComparisonOperatorSetting(numberValue);
  1052. break;
  1053. case "sparklineExType":
  1054. processSparklineSetting(nameValue, value);
  1055. break;
  1056. case "zoomSpread":
  1057. processZoomSetting(nameValue, value);
  1058. break;
  1059. case "commomFormat":
  1060. processFormatSetting(nameValue, value);
  1061. break;
  1062. case "borderLine":
  1063. processBorderLineSetting(nameValue);
  1064. break;
  1065. case "minAxisType":
  1066. updateManual(nameValue, "manualMin");
  1067. break;
  1068. case "maxAxisType":
  1069. updateManual(nameValue, "manualMax");
  1070. break;
  1071. case "slicerItemSorting":
  1072. processSlicerItemSorting(numberValue);
  1073. break;
  1074. case "spreadTheme":
  1075. processChangeSpreadTheme(nameValue);
  1076. break;
  1077. case "resizeZeroIndicator":
  1078. spread.options.resizeZeroIndicator = numberValue;
  1079. break;
  1080. case "copyPasteHeaderOptions":
  1081. spread.options.copyPasteHeaderOptions = GC.Spread.Sheets.CopyPasteHeaderOptions[nameValue]
  1082. break;
  1083. default:
  1084. console.log("TODO add itemSelected for ", name, value);
  1085. break;
  1086. }
  1087. setDropDownText(dropdown, text);
  1088. }
  1089. function setDropDownText(container, value) {
  1090. var refList = "#" + $(container).data("list-ref"),
  1091. $items = $(".menu-item div.text", refList),
  1092. $item = $items.filter(function () {
  1093. return $(this).data("value") === value;
  1094. });
  1095. var text = $item.text() || value;
  1096. $("span.display", container).text(text);
  1097. }
  1098. function setDropDownValue(container, value, host) {
  1099. if (typeof container === "string") {
  1100. host = host || document;
  1101. container = $(host).find("div.insp-dropdown-list[data-name='" + container + "']");
  1102. }
  1103. var refList = "#" + $(container).data("list-ref");
  1104. $("span.display", container).text($(".menu-item>div.text[data-value='" + value + "']", refList).text());
  1105. }
  1106. function setDropDownValueByIndex(container, index) {
  1107. var refList = "#" + $(container).data("list-ref"),
  1108. $item = $(".menu-item:eq(" + index + ") div.text", refList);
  1109. $("span.display", container).text($item.text());
  1110. return {text: $item.text(), value: $item.data("value")};
  1111. }
  1112. function getDropDownValue(name, host) {
  1113. host = host || document;
  1114. var container = $(host).find("div.insp-dropdown-list[data-name='" + name + "']"),
  1115. refList = "#" + $(container).data("list-ref"),
  1116. text = $("span.display", container).text();
  1117. var value = $("div.text", refList).filter(function () {
  1118. return $(this).text() === text;
  1119. }).data("value");
  1120. return value;
  1121. }
  1122. function colorSelected() {
  1123. var themeColor = $(this).data("name");
  1124. var value = $(this).css("background-color");
  1125. var name = $(_colorpicker).data("name");
  1126. var sheet = spread.getActiveSheet();
  1127. $("div.color-view", $(_colorpicker).data("dropdown")).css("background-color", value);
  1128. // No Fills need special process
  1129. if ($(this).hasClass("auto-color-cell")) {
  1130. if (name === "backColor") {
  1131. value = undefined;
  1132. }
  1133. }
  1134. var options = spread.options;
  1135. spread.suspendPaint();
  1136. switch (name) {
  1137. case "spreadBackcolor":
  1138. options.backColor = value;
  1139. break;
  1140. case "grayAreaBackcolor":
  1141. options.grayAreaBackColor = value;
  1142. break;
  1143. case "cutCopyIndicatorBorderColor":
  1144. options.cutCopyIndicatorBorderColor = value;
  1145. break;
  1146. case "sheetTabColor":
  1147. sheet.options.sheetTabColor = value;
  1148. break;
  1149. case "frozenLineColor":
  1150. sheet.options.frozenlineColor = value;
  1151. break;
  1152. case "gridlineColor":
  1153. sheet.options.gridline.color = value;
  1154. break;
  1155. case "foreColor":
  1156. case "backColor":
  1157. setColor(sheet, name, themeColor || value);
  1158. break;
  1159. case "labelForeColor":
  1160. setLabelOptions(sheet, value, "foreColor");
  1161. break;
  1162. case "selectionBorderColor":
  1163. sheet.options.selectionBorderColor = value;
  1164. break;
  1165. case "selectionBackColor":
  1166. // change to rgba (alpha: 0.2) to make cell content visible
  1167. value = getRGBAColor(value, 0.2);
  1168. sheet.options.selectionBackColor = value;
  1169. $("div.color-view", $(_colorpicker).data("dropdown")).css("background-color", value);
  1170. break;
  1171. case "commentBorderColor":
  1172. _activeComment && _activeComment.borderColor(value);
  1173. break;
  1174. case "commentForeColor":
  1175. _activeComment && _activeComment.foreColor(value);
  1176. break;
  1177. case "commentBackColor":
  1178. _activeComment && _activeComment.backColor(value);
  1179. break;
  1180. case "pictureBorderColor":
  1181. _activePicture && _activePicture.borderColor(value);
  1182. break;
  1183. case "pictureBackColor":
  1184. _activePicture && _activePicture.backColor(value);
  1185. break;
  1186. default:
  1187. console.log("TODO colorSelected", name);
  1188. break;
  1189. }
  1190. spread.resumePaint();
  1191. }
  1192. function getRGBAColor(color, alpha) {
  1193. var result = color,
  1194. prefix = "rgb(";
  1195. // get rgb color use jquery
  1196. if (color.substr(0, 4) !== prefix) {
  1197. var $temp = $("#setfontstyle");
  1198. $temp.css("background-color", color);
  1199. color = $temp.css("background-color");
  1200. }
  1201. // adding alpha to make rgba
  1202. if (color.substr(0, 4) === prefix) {
  1203. var length = color.length;
  1204. result = "rgba(" + color.substring(4, length - 1) + ", " + alpha + ")";
  1205. }
  1206. return result;
  1207. }
  1208. function setColor(sheet, method, value) {
  1209. var sels = sheet.getSelections();
  1210. var rowCount = sheet.getRowCount(),
  1211. columnCount = sheet.getColumnCount();
  1212. sheet.suspendPaint();
  1213. for (var n = 0; n < sels.length; n++) {
  1214. var sel = getActualCellRange(sheet, sels[n], rowCount, columnCount);
  1215. sheet.getRange(sel.row, sel.col, sel.rowCount, sel.colCount)[method](value);
  1216. }
  1217. sheet.resumePaint();
  1218. }
  1219. function buttonClicked() {
  1220. var $element = $(this),
  1221. name = $element.data("name"),
  1222. container;
  1223. var sheet = spread.getActiveSheet();
  1224. // get group
  1225. if ((container = $element.parents(".insp-radio-button-group")).length > 0) {
  1226. name = container.data("name");
  1227. $element.siblings().removeClass("active");
  1228. $element.addClass("active");
  1229. switch (name) {
  1230. case "vAlign":
  1231. case "hAlign":
  1232. setAlignment(sheet, name, $element.data("name"));
  1233. break;
  1234. }
  1235. } else if ($element.parents(".insp-button-group").length > 0) {
  1236. if (!$element.hasClass("no-toggle")) {
  1237. $element.toggleClass("active");
  1238. }
  1239. switch (name) {
  1240. case "bold":
  1241. setStyleFont(sheet, "font-weight", false, ["700", "bold"], "normal");
  1242. break;
  1243. case "labelBold":
  1244. setStyleFont(sheet, "font-weight", true, ["700", "bold"], "normal");
  1245. break;
  1246. case "italic":
  1247. setStyleFont(sheet, "font-style", false, ["italic"], "normal");
  1248. break;
  1249. case "labelItalic":
  1250. setStyleFont(sheet, "font-style", true, ["italic"], "normal");
  1251. break;
  1252. case "underline":
  1253. setTextDecoration(sheet, spreadNS.TextDecorationType.underline);
  1254. break;
  1255. case "strikethrough":
  1256. setTextDecoration(sheet, spreadNS.TextDecorationType.lineThrough);
  1257. break;
  1258. case "overline":
  1259. setTextDecoration(sheet, spreadNS.TextDecorationType.overline);
  1260. break;
  1261. case "increaseIndent":
  1262. setTextIndent(sheet, 1);
  1263. break;
  1264. case "decreaseIndent":
  1265. setTextIndent(sheet, -1);
  1266. break;
  1267. case "percentStyle":
  1268. setFormatter(uiResource.cellTab.format.percentValue);
  1269. break;
  1270. case "commaStyle":
  1271. setFormatter(uiResource.cellTab.format.commaValue);
  1272. break;
  1273. case "increaseDecimal":
  1274. increaseDecimal();
  1275. break;
  1276. case "decreaseDecimal":
  1277. decreaseDecimal();
  1278. break;
  1279. case "comment-underline":
  1280. case "comment-overline":
  1281. case "comment-strikethrough":
  1282. setCommentTextDecoration(+$element.data("value"));
  1283. break;
  1284. default:
  1285. console.log("buttonClicked w/o process code for ", name);
  1286. break;
  1287. }
  1288. }
  1289. }
  1290. function setCommentTextDecoration(flag) {
  1291. if (_activeComment) {
  1292. var textDecoration = _activeComment.textDecoration();
  1293. _activeComment.textDecoration(textDecoration ^ flag);
  1294. }
  1295. }
  1296. // Increase Decimal related items
  1297. function increaseDecimal() {
  1298. var sheet = spread.getActiveSheet();
  1299. execInSelections(sheet, "formatter", function (sheet, row, column) {
  1300. var style = sheet.getStyle(row, column);
  1301. if (!style) {
  1302. style = new spreadNS.Style();
  1303. }
  1304. var activeCell = sheet.getCell(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex());
  1305. var activeCellValue = activeCell.value();
  1306. var activeCellFormatter = activeCell.formatter();
  1307. var activeCellText = activeCell.text();
  1308. if (activeCellValue) {
  1309. var formatString = null;
  1310. var zero = "0";
  1311. var numberSign = "#";
  1312. var decimalPoint = ".";
  1313. var zeroPointZero = "0" + decimalPoint + "0";
  1314. var scientificNotationCheckingFormatter = getScientificNotationCheckingFormattter(activeCellFormatter);
  1315. if (!activeCellFormatter || ((activeCellFormatter == "General" || (scientificNotationCheckingFormatter &&
  1316. (scientificNotationCheckingFormatter.indexOf("E") >= 0 || scientificNotationCheckingFormatter.indexOf('e') >= 0))))) {
  1317. if (!isNaN(activeCellValue)) {
  1318. var result = activeCellText.split('.');
  1319. if (result.length == 1) {
  1320. if (result[0].indexOf('E') >= 0 || result[0].indexOf('e') >= 0)
  1321. formatString = zeroPointZero + "E+00";
  1322. else
  1323. formatString = zeroPointZero;
  1324. }
  1325. else if (result.length == 2) {
  1326. result[0] = "0";
  1327. var isScience = false;
  1328. var sb = "";
  1329. for (var i = 0; i < result[1].length + 1; i++) {
  1330. sb = sb + '0';
  1331. if (i < result[1].length && (result[1].charAt(i) == 'e' || result[1].charAt(i) == 'E')) {
  1332. isScience = true;
  1333. break;
  1334. }
  1335. }
  1336. if (isScience)
  1337. sb = sb + "E+00";
  1338. if (sb) {
  1339. result[1] = sb.toString();
  1340. formatString = result[0] + decimalPoint + result[1];
  1341. }
  1342. }
  1343. }
  1344. }
  1345. else {
  1346. formatString = activeCellFormatter;
  1347. if (formatString) {
  1348. var formatters = formatString.split(';');
  1349. for (var i = 0; i < formatters.length && i < 2; i++) {
  1350. if (formatters[i] && formatters[i].indexOf("/") < 0 && formatters[i].indexOf(":") < 0 && formatters[i].indexOf("?") < 0) {
  1351. var indexOfDecimalPoint = formatters[i].lastIndexOf(decimalPoint);
  1352. if (indexOfDecimalPoint != -1) {
  1353. formatters[i] = formatters[i].slice(0, indexOfDecimalPoint + 1) + zero + formatters[i].slice(indexOfDecimalPoint + 1);
  1354. }
  1355. else {
  1356. var indexOfZero = formatters[i].lastIndexOf(zero);
  1357. var indexOfNumberSign = formatters[i].lastIndexOf(numberSign);
  1358. var insertIndex = indexOfZero > indexOfNumberSign ? indexOfZero : indexOfNumberSign;
  1359. if (insertIndex >= 0)
  1360. formatters[i] = formatters[i].slice(0, insertIndex + 1) + decimalPoint + zero + formatters[i].slice(insertIndex + 1);
  1361. }
  1362. }
  1363. }
  1364. formatString = formatters.join(";");
  1365. }
  1366. }
  1367. style.formatter = formatString;
  1368. sheet.setStyle(row, column, style);
  1369. }
  1370. });
  1371. }
  1372. //This method is used to get the formatter which not include the string and color
  1373. //in order to not misleading with the charactor 'e' / 'E' in scientific notation.
  1374. function getScientificNotationCheckingFormattter(formatter) {
  1375. if (!formatter) {
  1376. return formatter;
  1377. }
  1378. var i;
  1379. var signalQuoteSubStrings = getSubStrings(formatter, '\'', '\'');
  1380. for (i = 0; i < signalQuoteSubStrings.length; i++) {
  1381. formatter = formatter.replace(signalQuoteSubStrings[i], '');
  1382. }
  1383. var doubleQuoteSubStrings = getSubStrings(formatter, '\"', '\"');
  1384. for (i = 0; i < doubleQuoteSubStrings.length; i++) {
  1385. formatter = formatter.replace(doubleQuoteSubStrings[i], '');
  1386. }
  1387. var colorStrings = getSubStrings(formatter, '[', ']');
  1388. for (i = 0; i < colorStrings.length; i++) {
  1389. formatter = formatter.replace(colorStrings[i], '');
  1390. }
  1391. return formatter;
  1392. }
  1393. function getSubStrings(source, beginChar, endChar) {
  1394. if (!source) {
  1395. return [];
  1396. }
  1397. var subStrings = [], tempSubString = '', inSubString = false;
  1398. for (var index = 0; index < source.length; index++) {
  1399. if (!inSubString && source[index] === beginChar) {
  1400. inSubString = true;
  1401. tempSubString = source[index];
  1402. continue;
  1403. }
  1404. if (inSubString) {
  1405. tempSubString += source[index];
  1406. if (source[index] === endChar) {
  1407. subStrings.push(tempSubString);
  1408. tempSubString = "";
  1409. inSubString = false;
  1410. }
  1411. }
  1412. }
  1413. return subStrings;
  1414. }
  1415. // Increase Decimal related items (end)
  1416. // Decrease Decimal related items
  1417. function decreaseDecimal() {
  1418. var sheet = spread.getActiveSheet();
  1419. execInSelections(sheet, "formatter", function (sheet, row, column) {
  1420. var style = sheet.getStyle(row, column);
  1421. if (!style) {
  1422. style = new spreadNS.Style();
  1423. }
  1424. var activeCell = sheet.getCell(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex());
  1425. var activeCellValue = activeCell.value();
  1426. var activeCellFormatter = activeCell.formatter();
  1427. var activeCellText = activeCell.text();
  1428. var decimalPoint = ".";
  1429. if (activeCellValue) {
  1430. var formatString = null;
  1431. if (!activeCellFormatter || activeCellFormatter == "General") {
  1432. if (!isNaN(activeCellValue)) {
  1433. var result = activeCellText.split('.');
  1434. if (result.length == 2) {
  1435. result[0] = "0";
  1436. var isScience = false;
  1437. var sb = "";
  1438. for (var i = 0; i < result[1].length - 1; i++) {
  1439. if ((i + 1 < result[1].length) && (result[1].charAt(i + 1) == 'e' || result[1].charAt(i + 1) == 'E')) {
  1440. isScience = true;
  1441. break;
  1442. }
  1443. sb = sb + ('0');
  1444. }
  1445. if (isScience)
  1446. sb = sb + ("E+00");
  1447. if (sb !== null) {
  1448. result[1] = sb.toString();
  1449. formatString = result[0] + (result[1] !== "" ? decimalPoint + result[1] : "");
  1450. }
  1451. }
  1452. }
  1453. }
  1454. else {
  1455. formatString = activeCellFormatter;
  1456. if (formatString) {
  1457. var formatters = formatString.split(';');
  1458. for (var i = 0; i < formatters.length && i < 2; i++) {
  1459. if (formatters[i] && formatters[i].indexOf("/") < 0 && formatters[i].indexOf(":") < 0 && formatters[i].indexOf("?") < 0) {
  1460. var indexOfDecimalPoint = formatters[i].lastIndexOf(decimalPoint);
  1461. if (indexOfDecimalPoint != -1 && indexOfDecimalPoint + 1 < formatters[i].length) {
  1462. formatters[i] = formatters[i].slice(0, indexOfDecimalPoint + 1) + formatters[i].slice(indexOfDecimalPoint + 2);
  1463. var tempString = indexOfDecimalPoint + 1 < formatters[i].length ? formatters[i].substr(indexOfDecimalPoint + 1, 1) : "";
  1464. if (tempString === "" || tempString !== "0")
  1465. formatters[i] = formatters[i].slice(0, indexOfDecimalPoint) + formatters[i].slice(indexOfDecimalPoint + 1);
  1466. }
  1467. else {
  1468. //do nothing.
  1469. }
  1470. }
  1471. }
  1472. formatString = formatters.join(";");
  1473. }
  1474. }
  1475. style.formatter = formatString;
  1476. sheet.setStyle(row, column, style);
  1477. }
  1478. });
  1479. }
  1480. // Decrease Decimal related items (end)
  1481. function setAlignment(sheet, type, value) {
  1482. var sels = sheet.getSelections(),
  1483. rowCount = sheet.getRowCount(),
  1484. columnCount = sheet.getColumnCount(),
  1485. align;
  1486. value = value.toLowerCase();
  1487. if (value === "middle") {
  1488. value = "center";
  1489. }
  1490. if (type === "hAlign") {
  1491. align = spreadNS.HorizontalAlign[value];
  1492. } else {
  1493. align = spreadNS.VerticalAlign[value];
  1494. }
  1495. sheet.suspendPaint();
  1496. for (var n = 0; n < sels.length; n++) {
  1497. var sel = getActualCellRange(sheet, sels[n], rowCount, columnCount);
  1498. sheet.getRange(sel.row, sel.col, sel.rowCount, sel.colCount)[type](align);
  1499. }
  1500. sheet.resumePaint();
  1501. }
  1502. function setTextDecoration(sheet, flag) {
  1503. var sels = sheet.getSelections();
  1504. var rowCount = sheet.getRowCount(),
  1505. columnCount = sheet.getColumnCount();
  1506. sheet.suspendPaint();
  1507. for (var n = 0; n < sels.length; n++) {
  1508. var sel = getActualCellRange(sheet, sels[n], rowCount, columnCount),
  1509. textDecoration = sheet.getCell(sel.row, sel.col).textDecoration();
  1510. if ((textDecoration & flag) === flag) {
  1511. textDecoration = textDecoration - flag;
  1512. } else {
  1513. textDecoration = textDecoration | flag;
  1514. }
  1515. sheet.getRange(sel.row, sel.col, sel.rowCount, sel.colCount).textDecoration(textDecoration);
  1516. }
  1517. sheet.resumePaint();
  1518. }
  1519. function setWordWrap(sheet) {
  1520. var sels = sheet.getSelections();
  1521. var rowCount = sheet.getRowCount(),
  1522. columnCount = sheet.getColumnCount();
  1523. sheet.suspendPaint();
  1524. for (var n = 0; n < sels.length; n++) {
  1525. var sel = getActualCellRange(sheet, sels[n], rowCount, columnCount),
  1526. wordWrap = !sheet.getCell(sel.row, sel.col).wordWrap(),
  1527. startRow = sel.row,
  1528. endRow = sel.row + sel.rowCount - 1;
  1529. sheet.getRange(startRow, sel.col, sel.rowCount, sel.colCount).wordWrap(wordWrap);
  1530. for (var row = startRow; row <= endRow; row++) {
  1531. sheet.autoFitRow(row);
  1532. }
  1533. }
  1534. sheet.resumePaint();
  1535. }
  1536. function setTextIndent(sheet, step) {
  1537. var sels = sheet.getSelections();
  1538. var rowCount = sheet.getRowCount(),
  1539. columnCount = sheet.getColumnCount();
  1540. sheet.suspendPaint();
  1541. for (var n = 0; n < sels.length; n++) {
  1542. var sel = getActualCellRange(sheet, sels[n], rowCount, columnCount),
  1543. indent = sheet.getCell(sel.row, sel.col).textIndent();
  1544. if (isNaN(indent)) {
  1545. indent = 0;
  1546. }
  1547. var value = indent + step;
  1548. if (value < 0) {
  1549. value = 0;
  1550. }
  1551. sheet.getRange(sel.row, sel.col, sel.rowCount, sel.colCount).textIndent(value);
  1552. }
  1553. sheet.resumePaint();
  1554. }
  1555. function divButtonClicked() {
  1556. var sheet = spread.getActiveSheet(),
  1557. id = this.id;
  1558. spread.suspendPaint();
  1559. switch (id) {
  1560. case "mergeCells":
  1561. mergeCells(sheet);
  1562. updateMergeButtonsState();
  1563. break;
  1564. case "unmergeCells":
  1565. unmergeCells(sheet);
  1566. updateMergeButtonsState();
  1567. break;
  1568. case "freezePane":
  1569. sheet.frozenRowCount(sheet.getActiveRowIndex());
  1570. sheet.frozenColumnCount(sheet.getActiveColumnIndex());
  1571. syncForzenProperties(sheet);
  1572. break;
  1573. case "unfreeze":
  1574. sheet.frozenRowCount(0);
  1575. sheet.frozenColumnCount(0);
  1576. sheet.frozenTrailingRowCount(0);
  1577. sheet.frozenTrailingColumnCount(0);
  1578. syncForzenProperties(sheet);
  1579. break;
  1580. case "sortAZ":
  1581. case "sortZA":
  1582. sortData(sheet, id === "sortAZ");
  1583. break;
  1584. case "filter":
  1585. updateFilter(sheet);
  1586. break;
  1587. case "group":
  1588. addGroup(sheet);
  1589. break;
  1590. case "ungroup":
  1591. removeGroup(sheet);
  1592. break;
  1593. case "showDetail":
  1594. toggleGroupDetail(sheet, true);
  1595. break;
  1596. case "hideDetail":
  1597. toggleGroupDetail(sheet, false);
  1598. break;
  1599. default:
  1600. console.log("TODO add code for ", id);
  1601. break;
  1602. }
  1603. spread.resumePaint();
  1604. }
  1605. function mergeCells(sheet) {
  1606. var sels = sheet.getSelections();
  1607. var rowCount = sheet.getRowCount(),
  1608. columnCount = sheet.getColumnCount();
  1609. for (var n = 0; n < sels.length; n++) {
  1610. var sel = getActualCellRange(sheet, sels[n], rowCount, columnCount);
  1611. sheet.addSpan(sel.row, sel.col, sel.rowCount, sel.colCount);
  1612. }
  1613. }
  1614. function unmergeCells(sheet) {
  1615. function removeSpan(range) {
  1616. sheet.removeSpan(range.row, range.col);
  1617. }
  1618. var sels = sheet.getSelections();
  1619. var rowCount = sheet.getRowCount(),
  1620. columnCount = sheet.getColumnCount();
  1621. for (var n = 0; n < sels.length; n++) {
  1622. var sel = getActualCellRange(sheet, sels[n], rowCount, columnCount);
  1623. sheet.getSpans(sel).forEach(removeSpan);
  1624. }
  1625. }
  1626. function sortData(sheet, ascending) {
  1627. var sels = sheet.getSelections();
  1628. var rowCount = sheet.getRowCount(),
  1629. columnCount = sheet.getColumnCount();
  1630. for (var n = 0; n < sels.length; n++) {
  1631. var sel = getActualCellRange(sheet, sels[n], rowCount, columnCount);
  1632. sheet.sortRange(sel.row, sel.col, sel.rowCount, sel.colCount, true,
  1633. [
  1634. {index: sel.col, ascending: ascending}
  1635. ]);
  1636. }
  1637. }
  1638. function updateFilter(sheet) {
  1639. if (sheet.rowFilter()) {
  1640. sheet.rowFilter(null);
  1641. } else {
  1642. var sels = sheet.getSelections();
  1643. if (sels.length > 0) {
  1644. var sel = sels[0];
  1645. sheet.rowFilter(new spreadNS.Filter.HideRowFilter(sel));
  1646. }
  1647. }
  1648. }
  1649. function setCheckboxEnable($element, enable) {
  1650. if (enable) {
  1651. $element.removeClass("disabled");
  1652. $element.find(".button").addClass("checked");
  1653. } else {
  1654. $element.addClass("disabled");
  1655. }
  1656. }
  1657. function addGroup(sheet) {
  1658. var sels = sheet.getSelections();
  1659. var sel = sels[0];
  1660. if (!sel) return;
  1661. if (sel.col === -1) // row selection
  1662. {
  1663. spread.commandManager().execute({
  1664. cmd: 'outlineRow',
  1665. sheetName: sheet.name(),
  1666. index: sel.row,
  1667. count: sel.rowCount
  1668. });
  1669. }
  1670. else if (sel.row === -1) // column selection
  1671. {
  1672. spread.commandManager().execute({
  1673. cmd: 'outlineColumn',
  1674. sheetName: sheet.name(),
  1675. index: sel.col,
  1676. count: sel.colCount
  1677. });
  1678. }
  1679. else // cell range selection
  1680. {
  1681. alert(getResource("messages.rowColumnRangeRequired"));
  1682. }
  1683. }
  1684. function removeGroup(sheet) {
  1685. var sels = sheet.getSelections();
  1686. var sel = sels[0];
  1687. if (!sel) return;
  1688. if (sel.col === -1 && sel.row === -1) // sheet selection
  1689. {
  1690. sheet.rowOutlines.ungroup(0, sheet.getRowCount());
  1691. sheet.columnOutlines.ungroup(0, sheet.getColumnCount());
  1692. }
  1693. else if (sel.col === -1) // row selection
  1694. {
  1695. spread.commandManager().execute({
  1696. cmd: 'removeRowOutline',
  1697. sheetName: sheet.name(),
  1698. index: sel.row,
  1699. count: sel.rowCount
  1700. });
  1701. }
  1702. else if (sel.row === -1) // column selection
  1703. {
  1704. spread.commandManager().execute({
  1705. cmd: 'removeColumnOutline',
  1706. sheetName: sheet.name(),
  1707. index: sel.col,
  1708. count: sel.colCount
  1709. });
  1710. }
  1711. else // cell range selection
  1712. {
  1713. alert(getResource("messages.rowColumnRangeRequired"));
  1714. }
  1715. }
  1716. function toggleGroupDetail(sheet, expand) {
  1717. var sels = sheet.getSelections();
  1718. var sel = sels[0];
  1719. if (!sel) return;
  1720. if (sel.col === -1 && sel.row === -1) // sheet selection
  1721. {
  1722. }
  1723. else if (sel.col === -1) // row selection
  1724. {
  1725. for (var i = 0; i < sel.rowCount; i++) {
  1726. var rgi = sheet.rowOutlines.find(sel.row + i, 0);
  1727. if (rgi) {
  1728. sheet.rowOutlines.expand(rgi.level, expand);
  1729. }
  1730. }
  1731. }
  1732. else if (sel.row === -1) // column selection
  1733. {
  1734. for (var i = 0; i < sel.colCount; i++) {
  1735. var rgi = sheet.columnOutlines.find(sel.col + i, 0);
  1736. if (rgi) {
  1737. sheet.columnOutlines.expand(rgi.level, expand);
  1738. }
  1739. }
  1740. }
  1741. else // cell range selection
  1742. {
  1743. }
  1744. }
  1745. var MARGIN_BOTTOM = 4;
  1746. function adjustSpreadSize() {
  1747. var height = $("#inner-content-container").height() - $("#formulaBar").height() - MARGIN_BOTTOM,
  1748. spreadHeight = $("#ss").height();
  1749. if (spreadHeight !== height) {
  1750. $("#controlPanel").height(height);
  1751. $("#ss").height(height);
  1752. $("#ss").data("workbook").refresh();
  1753. }
  1754. }
  1755. function screenAdoption() {
  1756. hideSpreadContextMenu();
  1757. adjustSpreadSize();
  1758. // adjust toolbar items position
  1759. var $toolbar = $("#toolbar"),
  1760. sectionWidth = Math.floor($toolbar.width() / 3);
  1761. $(".toolbar-left-section", $toolbar).width(sectionWidth);
  1762. // + 2 to make sure the right section with enough space to show in same line
  1763. if (sectionWidth > 375 + 2) { // 340 = (380 + 300) / 2, where 380 is min-width of left section, 300 is the width of right section
  1764. $(".toolbar-middle-section", $toolbar).width(sectionWidth);
  1765. } else {
  1766. $(".toolbar-middle-section", $toolbar).width("auto");
  1767. }
  1768. // explicit set formula box' width instead of 100% because it's contained in table
  1769. var width = $("#inner-content-container").width() - $("#positionbox").outerWidth() - 1; // 1: border' width of td contains formulabox (left only)
  1770. $("#formulabox").css({width: width});
  1771. }
  1772. function doPrepareWork() {
  1773. /*
  1774. 1. expand / collapse .insp-group by checking expanded class
  1775. */
  1776. function processDisplayGroups() {
  1777. $("div.insp-group").each(function () {
  1778. var $group = $(this),
  1779. expanded = $group.hasClass("expanded"),
  1780. $content = $group.find("div.insp-group-content"),
  1781. $state = $group.find("span.group-state");
  1782. if (expanded) {
  1783. $content.show();
  1784. $state.addClass("fa-caret-down");
  1785. } else {
  1786. $content.hide();
  1787. $state.addClass("fa-caret-right");
  1788. }
  1789. });
  1790. }
  1791. function addEventHandlers() {
  1792. $("div.insp-group-title>span").click(toggleState);
  1793. $("div.insp-checkbox").click(checkedChanged);
  1794. $("div.insp-number>input.editor").blur(updateNumberProperty);
  1795. $("div.insp-dropdown-list .dropdown").click(showDropdown);
  1796. $("div.insp-menu .menu-item").click(itemSelected);
  1797. $("div.insp-color-picker .picker").click(showColorPicker);
  1798. $("li.color-cell").click(colorSelected);
  1799. $(".insp-button-group span.btn").click(buttonClicked);
  1800. $(".insp-radio-button-group span.btn").click(buttonClicked);
  1801. $(".insp-buttons .btn").click(divButtonClicked);
  1802. $(".insp-text input.editor").blur(updateStringProperty);
  1803. }
  1804. processDisplayGroups();
  1805. addEventHandlers();
  1806. $("input[type='number']:not('.not-min-zero')").attr("min", 0);
  1807. // set default values
  1808. var item = setDropDownValueByIndex($("#conditionalFormatType"), -1);
  1809. processConditionalFormatDetailSetting(item.value, true);
  1810. var cellTypeItem = setDropDownValueByIndex($("#cellTypes"), -1);
  1811. processCellTypeSetting(cellTypeItem.value, true); // CellType Setting
  1812. var validationTypeItem = setDropDownValueByIndex($("#validatorType"), 0);
  1813. processDataValidationSetting(validationTypeItem.value); // Data Validation Setting
  1814. var sparklineTypeItem = setDropDownValueByIndex($("#sparklineExTypeDropdown"), 0);
  1815. processSparklineSetting(sparklineTypeItem.value); // SparklineEx Setting
  1816. setDropDownValue("numberValidatorComparisonOperator", 0); // NumberValidator Comparison Operator
  1817. processNumberValidatorComparisonOperatorSetting(0);
  1818. setDropDownValue("dateValidatorComparisonOperator", 0); // DateValidator Comparison Operator
  1819. processDateValidatorComparisonOperatorSetting(0);
  1820. setDropDownValue("textLengthValidatorComparisonOperator", 0); // TextLengthValidator Comparison Operator
  1821. processTextLengthValidatorComparisonOperatorSetting(0);
  1822. processBorderLineSetting("thin"); // Border Line Setting
  1823. setDropDownValue("minType", 1); // LowestValue
  1824. setDropDownValue("midType", 4); // Percentile
  1825. setDropDownValue("maxType", 2); // HighestValue
  1826. setDropDownValue("minimumType", 5); // Automin
  1827. setDropDownValue("maximumType", 7); // Automax
  1828. setDropDownValue("dataBarDirection", 0); // Left-to-Right
  1829. setDropDownValue("axisPosition", 0); // Automatic
  1830. setDropDownValue("iconSetType", 0); // ThreeArrowsColored
  1831. setDropDownValue("checkboxCellTypeTextAlign", 3); // Right
  1832. setDropDownValue("comboboxCellTypeEditorValueType", 2); // Value
  1833. setDropDownValue("errorAlert", 0); // Data Validation Error Alert Type
  1834. setDropDownValue("zoomSpread", 1); // Zoom Value
  1835. setDropDownValueByIndex($("#commomFormatType"), 0); // Format Setting
  1836. setDropDownValueByIndex($("#boxplotClassType"), 0); // BoxPlotSparkline Class
  1837. setDropDownValue("boxplotSparklineStyleType", 0); // BoxPlotSparkline Style
  1838. setDropDownValue("dataOrientationType", 0); // CompatibleSparkline DataOrientation
  1839. setDropDownValue("paretoLabelList", 0); // ParetoSparkline Label
  1840. setDropDownValue("spreadSparklineStyleType", 4); // SpreadSparkline Style
  1841. setDropDownValue("stackedSparklineTextOrientation", 0); // StackedSparkline TextOrientation
  1842. setDropDownValueByIndex($("#spreadTheme"), 1); // Spread Theme
  1843. setDropDownValue("resizeZeroIndicator", 1); // ResizeZeroIndicator
  1844. setDropDownValueByIndex($("#copyPasteHeaderOptions"), 3); // CopyPasteHeaderOptins
  1845. setDropDownValueByIndex($("#cellLabelVisibility"), 0); // CellLabelVisibility
  1846. setDropDownValueByIndex($("#cellLabelAlignment"), 0); // CellLabelAlignment
  1847. conditionalFormatTexts = uiResource.conditionalFormat.texts;
  1848. }
  1849. function initSpread() {
  1850. //formulabox
  1851. fbx = new spreadNS.FormulaTextBox.FormulaTextBox(document.getElementById('formulabox'));
  1852. fbx.workbook(spread);
  1853. setCellContent();
  1854. setFormulaContent();
  1855. setConditionalFormatContent();
  1856. setTableContent();
  1857. setSparklineContent();
  1858. setCommentContent();
  1859. setPictureContent();
  1860. setDataContent();
  1861. setSlicerContent();
  1862. }
  1863. // Sample Content related items
  1864. function setFormulaContent() {
  1865. var sheet = new spreadNS.Worksheet("Formula");
  1866. spread.addSheet(spread.getSheetCount(), sheet);
  1867. sheet.suspendPaint();
  1868. sheet.setColumnCount(50);
  1869. sheet.setColumnWidth(0, 100);
  1870. sheet.setColumnWidth(2, 100);
  1871. sheet.setColumnWidth(6, 103);
  1872. sheet.setColumnWidth(8, 150);
  1873. var row = 1, col = 2; // basic function
  1874. sheet.getCell(row, 0).value("Basic Function").font("700 11pt Calibri");
  1875. sheet.getCell(row, col).value("Name");
  1876. sheet.getCell(row, ++col).value("Age");
  1877. row++, col = 2;
  1878. sheet.getCell(row, col).value("Jack").hAlign(spreadNS.HorizontalAlign.right);
  1879. sheet.getCell(row, ++col).value(17);
  1880. row++, col = 2;
  1881. sheet.getCell(row, col).value("Lily").hAlign(spreadNS.HorizontalAlign.right);
  1882. sheet.getCell(row, ++col).value(23);
  1883. row++, col = 2;
  1884. sheet.getCell(row, col).value("Bob").hAlign(spreadNS.HorizontalAlign.right);
  1885. sheet.getCell(row, ++col).value(30);
  1886. row++, col = 2;
  1887. sheet.getCell(row, col).value("Mary").hAlign(spreadNS.HorizontalAlign.right);
  1888. sheet.getCell(row, ++col).value(25);
  1889. row++, col = 2;
  1890. sheet.getCell(row, col).value("Average Age:");
  1891. sheet.getCell(row, ++col).formula("=AVERAGE(D3:D6)");
  1892. row++, col = 2;
  1893. sheet.getCell(row, col).value("Max Age:");
  1894. sheet.getCell(row, ++col).formula("=MAX(D3:D6)");
  1895. row++, col = 2;
  1896. sheet.getCell(row, col).value("Min Age:");
  1897. sheet.getCell(row, ++col).formula("=MIN(D3:D6)");
  1898. row = 1, col = 8; // indirect function
  1899. sheet.getCell(row, 6).value("Indirect Function").font("700 11pt Calibri");
  1900. sheet.getCell(row, col).value("J2");
  1901. sheet.getCell(row, ++col).value(1);
  1902. row++, col = 8;
  1903. sheet.getCell(row, col).value("I");
  1904. sheet.getCell(row, ++col).value(2);
  1905. row++, col = 8;
  1906. sheet.getCell(row, col).value("J");
  1907. sheet.getCell(row, ++col).value(3);
  1908. row = row + 2, col = 8;
  1909. var formulaStr = "=INDIRECT(\"I2\")";
  1910. sheet.getCell(row, col).value(formulaStr);
  1911. sheet.getCell(row, ++col).formula(formulaStr);
  1912. row++, col = 8;
  1913. formulaStr = "=INDIRECT(I2)";
  1914. sheet.getCell(row, col).value(formulaStr);
  1915. sheet.getCell(row, ++col).formula(formulaStr);
  1916. row++, col = 8;
  1917. formulaStr = "=INDIRECT(\"I\"&(1+2))";
  1918. sheet.getCell(row, col).value(formulaStr);
  1919. sheet.getCell(row, ++col).formula(formulaStr);
  1920. row++, col = 8;
  1921. formulaStr = "=INDIRECT(I4&J3)";
  1922. sheet.getCell(row, col).value(formulaStr);
  1923. sheet.getCell(row, ++col).formula(formulaStr);
  1924. row++, col = 8;
  1925. formulaStr = "=INDIRECT(\"" + sheet.name() + "!\"&I2)";
  1926. sheet.getCell(row, col).value(formulaStr);
  1927. sheet.getCell(row, ++col).formula(formulaStr);
  1928. row++, col = 8;
  1929. formulaStr = "=INDIRECT(\"" + sheet.name() + "!I2\")";
  1930. sheet.getCell(row, col).value(formulaStr);
  1931. sheet.getCell(row, ++col).formula(formulaStr);
  1932. row = 12; // array formula
  1933. sheet.getCell(row, 0).value("Array Formula").font("700 11pt Calibri");
  1934. sheet.addSpan(row, 2, 1, 6);
  1935. sheet.getCell(row, 2).value("Calculation");
  1936. sheet.setArray(13, 2, [
  1937. ["", "Match", "Physical", "Chemistry", "", "Sum"],
  1938. ["Alice", 97, 61, 53],
  1939. ["John", 65, 76, 65],
  1940. ["Bob", 55, 70, 64],
  1941. ["Jack", 89, 77, 73]
  1942. ]);
  1943. sheet.setArrayFormula(14, 7, 4, 1, "=SUBTOTAL(9,OFFSET($D$15,ROW($D$15:$D$18)-ROW($D$15),,1,3))");
  1944. row = 19;
  1945. sheet.addSpan(row, 2, 1, 6);
  1946. sheet.getCell(row, 2).value("Search");
  1947. sheet.setArray(20, 2, [
  1948. ["apple", "apple"],
  1949. ["banana", "pear"],
  1950. ["pear", "potato"],
  1951. ["tomato", "potato"],
  1952. ["potato", "dumpling"],
  1953. ["cake"],
  1954. ["noodel"]
  1955. ]);
  1956. sheet.addSpan(20, 6, 1, 5);
  1957. sheet.getCell(20, 6).value("Find out the first value on D21:D25 that doesn't contain on D21:D27");
  1958. sheet.addSpan(22, 6, 1, 2);
  1959. sheet.getCell(22, 6).value("ArrayFormula Result:");
  1960. sheet.addSpan(23, 6, 1, 2);
  1961. sheet.getCell(23, 6).value("NomalFormula Result:");
  1962. sheet.setArrayFormula(22, 8, 1, 1, "=INDEX(D21:D25,MATCH(TRUE,ISNA(MATCH(D21:D25,C21:C27,0)),0))");
  1963. sheet.setFormula(23, 8, "=INDEX(D21:D25,MATCH(TRUE,ISNA(MATCH(D21:D25,C21:C27,0)),0))");
  1964. row = 28;
  1965. sheet.addSpan(row, 2, 1, 6);
  1966. sheet.getCell(row, 2).value("Statistics");
  1967. sheet.setArray(29, 2, [
  1968. ["Product", "Salesman", "Units Sold"],
  1969. ["Fax", "Brown", 1],
  1970. ["Phone", "Smith", 10],
  1971. ["Fax", "Jones", 20],
  1972. ["Fax", "Smith", 30],
  1973. ["Phone", "Jones", 40],
  1974. ["PC", "Smith", 50],
  1975. ["Fax", "Brown", 60],
  1976. ["Phone", "Davis", 70],
  1977. ["PC", "Jones", 80]
  1978. ]);
  1979. sheet.addSpan(29, 6, 1, 4);
  1980. sheet.getCell(29, 6).value("Summing Sales: Faxes Sold By Brown");
  1981. sheet.setArrayFormula(30, 6, 1, 1, "=SUM((C31:C39=\"Fax\")*(D31:D39=\"Brown\")*(E31:E39))");
  1982. sheet.addSpan(31, 6, 1, 4);
  1983. sheet.getCell(31, 6).value("Logical AND (Faxes And Brown)");
  1984. sheet.setArrayFormula(32, 6, 1, 1, "=SUM((C31:C39=\"Fax\")*(D31:D39=\"Brown\"))");
  1985. sheet.addSpan(33, 6, 1, 4);
  1986. sheet.getCell(33, 6).value("Logical OR (Faxes Or Jones)");
  1987. sheet.setArrayFormula(34, 6, 1, 1, "=SUM(IF((C31:C39=\"Fax\")+(D31:D39=\"Jones\"),1,0))");
  1988. sheet.addSpan(35, 6, 1, 4);
  1989. sheet.getCell(35, 6).value("Logical XOR (Fax Or Jones but not both)");
  1990. sheet.setArrayFormula(36, 6, 1, 1, "=SUM(IF(MOD((C31:C39=\"Fax\")+(D31:D39=\"Jones\"),2),1,0))");
  1991. sheet.addSpan(37, 6, 1, 4);
  1992. sheet.getCell(37, 6).value("Logical NAND (All Sales Except Fax And Jones)");
  1993. sheet.setArrayFormula(38, 6, 1, 1, "=SUM(IF((C31:C39=\"Fax\")+(D31:D39=\"Jones\")<>2,1,0))");
  1994. sheet.resumePaint();
  1995. }
  1996. function setCellContent() {
  1997. var sheet = new spreadNS.Worksheet("Cell");
  1998. spread.removeSheet(0);
  1999. spread.addSheet(spread.getSheetCount(), sheet);
  2000. sheet.suspendPaint();
  2001. sheet.setColumnCount(50);
  2002. sheet.setColumnWidth(0, 100);
  2003. sheet.setColumnWidth(1, 20);
  2004. for (var col = 2; col < 11; col++) {
  2005. sheet.setColumnWidth(col, 88);
  2006. }
  2007. var Range = spreadNS.Range;
  2008. var row = 1, col = 0; // cell background
  2009. sheet.getCell(row, col).value("Background").font("700 11pt Calibri");
  2010. sheet.getCell(row, col + 2).backColor("#1E90FF");
  2011. sheet.getCell(row, col + 4).backColor("#00ff00");
  2012. row = row + 2; // line border
  2013. var borderColor = "red";
  2014. var lineStyle = spreadNS.LineStyle;
  2015. var lineBorder = spreadNS.LineBorder;
  2016. var option = {all: true};
  2017. sheet.getCell(row, 0).value("Border").font("700 11pt Calibri");
  2018. col = 1;
  2019. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.empty), option);
  2020. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.hair), option);
  2021. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.dotted), option);
  2022. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.dashDotDot), option);
  2023. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.dashDot), option);
  2024. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.dashed), option);
  2025. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.thin), option);
  2026. row = row + 2, col = 1;
  2027. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.mediumDashDotDot), option);
  2028. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.slantedDashDot), option);
  2029. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.mediumDashDot), option);
  2030. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.mediumDashed), option);
  2031. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.medium), option);
  2032. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.thick), option);
  2033. sheet.getRange(row, ++col, 1, 1).setBorder(new lineBorder(borderColor, lineStyle.double), option);
  2034. row = row + 2, col = 1;
  2035. sheet.getRange(row, ++col, 2, 2).setBorder(new lineBorder("blue", lineStyle.dashed), {all: true});
  2036. sheet.getRange(row, col + 3, 2, 2).setBorder(new lineBorder("yellowgreen", lineStyle.double), {outline: true});
  2037. sheet.getRange(row, col + 6, 2, 2).setBorder(new lineBorder("black", lineStyle.mediumDashed), {innerHorizontal: true});
  2038. sheet.getRange(row, col + 6, 2, 2).setBorder(new lineBorder("black", lineStyle.slantedDashDot), {innerVertical: true});
  2039. row = row + 3, col = 2;
  2040. sheet.getRange(row, col, 3, 2).setBorder(new lineBorder("lightgreen", lineStyle.thick), {outline: true});
  2041. sheet.getRange(row, col, 3, 2).setBorder(new lineBorder("lightgreen", lineStyle.thick), {innerHorizontal: true});
  2042. col = col + 3;
  2043. sheet.getRange(row, col, 3, 3).setBorder(new lineBorder("#CDCD00", lineStyle.thick), {outline: true});
  2044. sheet.getRange(row, col, 3, 3).setBorder(new lineBorder("#CDCD00", lineStyle.thick), {innerVertical: true});
  2045. row = row + 3, col = 1; // merge cell
  2046. sheet.getCell(row + 1, 0).value("Span").font("700 11pt Calibri");
  2047. sheet.addSpan(row + 1, ++col, 1, 2);
  2048. sheet.addSpan(row, col + 3, 3, 1);
  2049. sheet.addSpan(row, col + 5, 3, 2);
  2050. row = row + 4, col = 1; // font
  2051. var TextDecorationType = spreadNS.TextDecorationType;
  2052. var fontText = "SPREADJS";
  2053. sheet.getCell(row, 0).value("Font").font("700 11pt Calibri");
  2054. sheet.getCell(row, ++col).value(fontText);
  2055. sheet.getCell(row, ++col).value(fontText).font("13pt Calibri");
  2056. sheet.getCell(row, ++col).value(fontText).font("11pt Arial");
  2057. sheet.getCell(row, ++col).value(fontText).font("13pt Times New Roman");
  2058. sheet.getCell(row, ++col).value(fontText).backColor("#FFD700");
  2059. sheet.getCell(row, ++col).value(fontText).foreColor("#436EEE");
  2060. row = row + 2, col = 1;
  2061. sheet.getCell(row, ++col).value(fontText).foreColor("#FFD700").backColor("#436EEE");
  2062. sheet.getCell(row, ++col).value(fontText).font("700 11pt Calibri");
  2063. sheet.getCell(row, ++col).value(fontText).font("italic 11pt Calibri");
  2064. sheet.getCell(row, ++col).value(fontText).textDecoration(TextDecorationType.underline);
  2065. sheet.getCell(row, ++col).value(fontText).textDecoration(TextDecorationType.lineThrough);
  2066. sheet.getCell(row, ++col).value(fontText).textDecoration(TextDecorationType.overline);
  2067. row = row + 2, col = 1; // format
  2068. var number = 0.25;
  2069. sheet.getCell(row, 0).value("Format").font("700 11pt Calibri");
  2070. sheet.getCell(row, ++col).value(number).formatter("0.00");
  2071. sheet.getCell(row, ++col).value(number).formatter("$#,##0.00");
  2072. sheet.getCell(row, ++col).value(number).formatter("$ #,##0.00;$ (#,##0.00);$ \"-\"??;@");
  2073. sheet.getCell(row, ++col).value(number).formatter("0%");
  2074. sheet.getCell(row, ++col).value(number).formatter("# ?/?");
  2075. row = row + 2, col = 1;
  2076. sheet.getCell(row, ++col).value(number).formatter("0.00E+00");
  2077. sheet.getCell(row, ++col).value(number).formatter("@");
  2078. sheet.getCell(row, ++col).value(number).formatter("h:mm:ss AM/PM");
  2079. sheet.getCell(row, ++col).value(number).formatter("m/d/yyyy");
  2080. sheet.getCell(row, ++col).value(number).formatter("dddd, mmmm dd, yyyy");
  2081. row = row + 2, col = 1; // text alignment
  2082. var HorizontalAlign = spreadNS.HorizontalAlign;
  2083. var VerticalAlign = spreadNS.VerticalAlign;
  2084. sheet.setRowHeight(row, 60);
  2085. sheet.getCell(row, 0).value("Alignment").font("700 11pt Calibri");
  2086. sheet.getCell(row, ++col).value("Top Left").vAlign(VerticalAlign.top).hAlign(HorizontalAlign.left);
  2087. sheet.getCell(row, ++col).value("Top Center").vAlign(VerticalAlign.top).hAlign(HorizontalAlign.center);
  2088. sheet.getCell(row, ++col).value("Top Right").vAlign(VerticalAlign.top).hAlign(HorizontalAlign.right);
  2089. sheet.getCell(row, ++col).value("Center Left").vAlign(VerticalAlign.center).hAlign(HorizontalAlign.left);
  2090. sheet.getCell(row, ++col).value("Center Center").vAlign(VerticalAlign.center).hAlign(HorizontalAlign.center);
  2091. sheet.getCell(row, ++col).value("Center Right").vAlign(VerticalAlign.center).hAlign(HorizontalAlign.right);
  2092. sheet.getCell(row, ++col).value("Bottom Left").vAlign(VerticalAlign.bottom).hAlign(HorizontalAlign.left);
  2093. sheet.getCell(row, ++col).value("Bottom Center").vAlign(VerticalAlign.bottom).hAlign(HorizontalAlign.center);
  2094. sheet.getCell(row, ++col).value("Bottom Right").vAlign(VerticalAlign.bottom).hAlign(HorizontalAlign.right);
  2095. row = row + 2, col = 1; // lock cell
  2096. sheet.getCell(row, 0).value("Locked").font("700 11pt Calibri");
  2097. sheet.getCell(row, ++col).value("TRUE").locked(true);
  2098. sheet.getCell(row, ++col).value("FALSE").locked(false);
  2099. row = row + 2, col = 1; // word wrap
  2100. sheet.setRowHeight(row, 60);
  2101. sheet.getCell(row, 0).value("WordWrap").font("700 11pt Calibri");
  2102. sheet.getCell(row, ++col).value("ABCDEFGHIJKLMNOPQRSTUVWXYZ").wordWrap(true);
  2103. sheet.getCell(row, ++col).value("ABCDEFGHIJKLMNOPQRSTUVWXYZ").wordWrap(false);
  2104. row = row + 2, col = 1; // celltype
  2105. sheet.setRowHeight(row, 25);
  2106. var cellType;
  2107. sheet.getCell(row, 0).value("CellType").font("700 11pt Calibri");
  2108. cellType = new spreadNS.CellTypes.Button();
  2109. cellType.buttonBackColor("#FFFF00");
  2110. cellType.text("I'm a button");
  2111. sheet.getCell(row, ++col).cellType(cellType);
  2112. cellType = new spreadNS.CellTypes.CheckBox();
  2113. cellType.caption("caption");
  2114. cellType.textTrue("true");
  2115. cellType.textFalse("false");
  2116. cellType.textIndeterminate("indeterminate");
  2117. cellType.textAlign(spreadNS.CellTypes.CheckBoxTextAlign.right);
  2118. cellType.isThreeState(true);
  2119. sheet.getCell(row, ++col).cellType(cellType);
  2120. cellType = new spreadNS.CellTypes.ComboBox();
  2121. cellType.items(["apple", "banana", "cat", "dog"]);
  2122. sheet.getCell(row, ++col).cellType(cellType);
  2123. cellType = new spreadNS.CellTypes.HyperLink();
  2124. cellType.linkColor("blue");
  2125. cellType.visitedLinkColor("red");
  2126. cellType.text("SpreadJS");
  2127. cellType.linkToolTip("SpreadJS Web Site");
  2128. sheet.getCell(row, ++col).cellType(cellType).value("http://spread.grapecity.com/Products/SpreadJS/");
  2129. row = row + 2, col = 1; // celltype
  2130. sheet.setRowHeight(row, 100);
  2131. sheet.setColumnWidth(0, 150);
  2132. sheet.getCell(row, 0).value("CellPadding&Label").font("700 11pt Calibri");
  2133. sheet.getCell(row, ++col, GC.Spread.Sheets.SheetArea.viewport).watermark("User ID").cellPadding('20');
  2134. sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport).labelOptions({
  2135. foreColor: 'red',
  2136. visibility: 2,
  2137. font: 'bold 15px Arial'
  2138. });
  2139. var b = new GC.Spread.Sheets.CellTypes.Button();
  2140. b.text("Click Me!");
  2141. sheet.setColumnWidth(3, 200);
  2142. sheet.setCellType(row, ++col, b, GC.Spread.Sheets.SheetArea.viewport);
  2143. sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport).watermark("Button Cell Type").cellPadding('20 20');
  2144. sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport).labelOptions({
  2145. alignment: 2,
  2146. visibility: 1,
  2147. font: 'bold 15px Arial',
  2148. foreColor: 'grey'
  2149. });
  2150. var c = new GC.Spread.Sheets.CellTypes.CheckBox();
  2151. c.isThreeState(false);
  2152. c.textTrue("Checked!");
  2153. c.textFalse("Check Me!");
  2154. sheet.setColumnWidth(4, 200);
  2155. sheet.setCellType(row, ++col, c, GC.Spread.Sheets.SheetArea.viewport);
  2156. sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport).watermark("CheckBox Cell Type").cellPadding('30');
  2157. sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport).labelOptions({
  2158. alignment: 5,
  2159. visibility: 0,
  2160. foreColor: 'green'
  2161. });
  2162. sheet.resumePaint();
  2163. }
  2164. function setConditionalFormatContent(sheet) {
  2165. var sheet = new spreadNS.Worksheet("Conditional Format");
  2166. spread.addSheet(spread.getSheetCount(), sheet);
  2167. sheet.suspendPaint();
  2168. sheet.setColumnCount(50);
  2169. sheet.setColumnWidth(0, 20);
  2170. sheet.setColumnWidth(1, 20);
  2171. for (var col = 2; col < 11; col++) {
  2172. sheet.setColumnWidth(col, 83);
  2173. }
  2174. for (var row = 1; row < 16; row++) {
  2175. sheet.addSpan(row, 10, 1, 2);
  2176. }
  2177. var Range = spreadNS.Range;
  2178. var row = 1, col = 1;
  2179. var style = new spreadNS.Style();
  2180. style.backColor = "red";
  2181. var cfs = sheet.conditionalFormats;
  2182. sheet.getCell(row, ++col).value("Cell Value").font("700 11pt Calibri");
  2183. sheet.getCell(row, col + 2).value("Specific Text").font("700 11pt Calibri");
  2184. sheet.getCell(row, col + 4).value("Unique").font("700 11pt Calibri");
  2185. sheet.getCell(row, col + 6).value("Duplicate").font("700 11pt Calibri");
  2186. sheet.getCell(row, col + 8).value("Date Occurring").font("700 11pt Calibri");
  2187. var rowCount = 6;
  2188. row++, col;
  2189. sheet.getCell(row, col).value(0);
  2190. sheet.getCell(row + 1, col).value(1);
  2191. sheet.getCell(row + 2, col).value(2);
  2192. sheet.getCell(row + 3, col).value(3);
  2193. sheet.getCell(row + 4, col).value(4);
  2194. sheet.getCell(row + 5, col).value(5);
  2195. cfs.addCellValueRule(ComparisonOperators.between, 2, 4, style, [new Range(row, col, rowCount, 1)]);
  2196. col = col + 2;
  2197. sheet.getCell(row, col).value("test");
  2198. sheet.getCell(row + 1, col).value("bad");
  2199. sheet.getCell(row + 2, col).value("good");
  2200. sheet.getCell(row + 3, col).value("testing");
  2201. sheet.getCell(row + 4, col).value("tested");
  2202. sheet.getCell(row + 5, col).value("general");
  2203. cfs.addSpecificTextRule(ConditionalFormatting.TextComparisonOperators.contains, "test", style, [new Range(row, col, rowCount, 1)]);
  2204. col = col + 2;
  2205. sheet.getCell(row, col).value(50);
  2206. sheet.getCell(row + 1, col).value(50);
  2207. sheet.getCell(row + 2, col).value(11);
  2208. sheet.getCell(row + 3, col).value(5);
  2209. sheet.getCell(row + 4, col).value(50);
  2210. sheet.getCell(row + 5, col).value(120);
  2211. cfs.addUniqueRule(style, [new Range(row, col, rowCount, 1)]);
  2212. col = col + 2;
  2213. sheet.getCell(row, col).value(50);
  2214. sheet.getCell(row + 1, col).value(50);
  2215. sheet.getCell(row + 2, col).value(11);
  2216. sheet.getCell(row + 3, col).value(5);
  2217. sheet.getCell(row + 4, col).value(50);
  2218. sheet.getCell(row + 5, col).value(120);
  2219. cfs.addDuplicateRule(style, [new Range(row, col, rowCount, 1)]);
  2220. col = col + 2;
  2221. var date = new Date();
  2222. sheet.getCell(row, col).value(date);
  2223. sheet.getCell(row + 1, col).value(new Date(date.setDate(date.getDate() + 1)));
  2224. sheet.getCell(row + 2, col).value(new Date(date.setDate(date.getDate() + 5)));
  2225. sheet.getCell(row + 3, col).value(new Date(date.setDate(date.getDate() + 1)));
  2226. sheet.getCell(row + 4, col).value(new Date(date.setDate(date.getDate() + 7)));
  2227. sheet.getCell(row + 5, col).value(new Date(date.setDate(date.getDate() + 8)));
  2228. cfs.addDateOccurringRule(ConditionalFormatting.DateOccurringType.nextWeek, style, [new Range(row, col, rowCount, 1)]);
  2229. row = row + 7, col = 1;
  2230. sheet.getCell(row, ++col).value("Top/Bottom").font("700 11pt Calibri");
  2231. sheet.getCell(row, col + 2).value("Average").font("700 11pt Calibri");
  2232. sheet.getCell(row, col + 4).value("2-Color Scale").font("700 11pt Calibri");
  2233. sheet.getCell(row, col + 6).value("3-Color Scale").font("700 11pt Calibri");
  2234. sheet.getCell(row, col + 8).value("Data Bar").font("700 11pt Calibri");
  2235. row++;
  2236. sheet.getCell(row, col).value(0);
  2237. sheet.getCell(row + 1, col).value(1);
  2238. sheet.getCell(row + 2, col).value(2);
  2239. sheet.getCell(row + 3, col).value(3);
  2240. sheet.getCell(row + 4, col).value(4);
  2241. sheet.getCell(row + 5, col).value(5);
  2242. cfs.addTop10Rule(ConditionalFormatting.Top10ConditionType.top, 4, style, [new Range(row, col, rowCount, 1)]);
  2243. for (var c = col + 2; c < col + 7; c = c + 2) {
  2244. sheet.getCell(row, c).value(1);
  2245. sheet.getCell(row + 1, c).value(50);
  2246. sheet.getCell(row + 2, c).value(100);
  2247. sheet.getCell(row + 3, c).value(2);
  2248. sheet.getCell(row + 4, c).value(60);
  2249. sheet.getCell(row + 5, c).value(3);
  2250. }
  2251. cfs.addAverageRule(ConditionalFormatting.AverageConditionType.above, style, [new Range(row, col + 2, rowCount, 1)]);
  2252. cfs.add2ScaleRule(1, 1, "red", 2, 100, "yellow", [new Range(row, col + 4, rowCount, 1)]);
  2253. cfs.add3ScaleRule(1, 1, "red", 0, 50, "blue", 2, 100, "yellow", [new Range(row, col + 6, rowCount, 1)]);
  2254. col = col + 8;
  2255. sheet.getCell(row, col).value(1);
  2256. sheet.getCell(row + 1, col).value(15);
  2257. sheet.getCell(row + 2, col).value(25);
  2258. sheet.getCell(row + 3, col).value(-1);
  2259. sheet.getCell(row + 4, col).value(-15);
  2260. sheet.getCell(row + 5, col).value(-25);
  2261. var ScaleValueNumber = ConditionalFormatting.ScaleValueType.number;
  2262. cfs.addDataBarRule(1, null, 2, null, "green", [new Range(row, col, rowCount, 1)]);
  2263. row = row + 8, col = 1;
  2264. sheet.getCell(row, ++col).value("Icon Set").font("700 11pt Calibri");
  2265. sheet.addSpan(row, col, 1, 10);
  2266. sheet.addSpan(row + 6, col, 1, 10);
  2267. row++;
  2268. for (var column = col; column < col + 10; column++) {
  2269. sheet.getCell(row, column).value(-50);
  2270. sheet.getCell(row + 1, column).value(-25);
  2271. sheet.getCell(row + 2, column).value(0);
  2272. sheet.getCell(row + 3, column).value(25);
  2273. sheet.getCell(row + 4, column).value(50);
  2274. sheet.getCell(row + 6, column).value(-50);
  2275. sheet.getCell(row + 7, column).value(-25);
  2276. sheet.getCell(row + 8, column).value(0);
  2277. sheet.getCell(row + 9, column).value(25);
  2278. sheet.getCell(row + 10, column).value(50);
  2279. }
  2280. rowCount = 5;
  2281. cfs.addIconSetRule(0, [new Range(row, col, rowCount, 1)]);
  2282. cfs.addIconSetRule(1, [new Range(row, ++col, rowCount, 1)]);
  2283. cfs.addIconSetRule(2, [new Range(row, ++col, rowCount, 1)]);
  2284. cfs.addIconSetRule(3, [new Range(row, ++col, rowCount, 1)]);
  2285. cfs.addIconSetRule(4, [new Range(row, ++col, rowCount, 1)]);
  2286. cfs.addIconSetRule(5, [new Range(row, ++col, rowCount, 1)]);
  2287. cfs.addIconSetRule(6, [new Range(row, ++col, rowCount, 1)]);
  2288. cfs.addIconSetRule(7, [new Range(row, ++col, rowCount, 1)]);
  2289. cfs.addIconSetRule(8, [new Range(row, ++col, rowCount, 1)]);
  2290. cfs.addIconSetRule(9, [new Range(row, ++col, rowCount, 1)]);
  2291. col = 1;
  2292. cfs.addIconSetRule(10, [new Range(row + 6, ++col, rowCount, 1)]);
  2293. cfs.addIconSetRule(11, [new Range(row + 6, ++col, rowCount, 1)]);
  2294. cfs.addIconSetRule(12, [new Range(row + 6, ++col, rowCount, 1)]);
  2295. cfs.addIconSetRule(13, [new Range(row + 6, ++col, rowCount, 1)]);
  2296. cfs.addIconSetRule(14, [new Range(row + 6, ++col, rowCount, 1)]);
  2297. cfs.addIconSetRule(15, [new Range(row + 6, ++col, rowCount, 1)]);
  2298. cfs.addIconSetRule(16, [new Range(row + 6, ++col, rowCount, 1)]);
  2299. cfs.addIconSetRule(17, [new Range(row + 6, ++col, rowCount, 1)]);
  2300. cfs.addIconSetRule(18, [new Range(row + 6, ++col, rowCount, 1)]);
  2301. cfs.addIconSetRule(19, [new Range(row + 6, ++col, rowCount, 1)]);
  2302. sheet.resumePaint();
  2303. }
  2304. function getRandomNumber() {
  2305. var num = Math.random();
  2306. if (num - 0.5 > 0) {
  2307. return Math.round(Math.random() * 100);
  2308. }
  2309. else {
  2310. return Math.round(Math.random() * (-100));
  2311. }
  2312. }
  2313. function setTableContent() {
  2314. var sheet = new spreadNS.Worksheet("Table");
  2315. spread.addSheet(spread.getSheetCount(), sheet);
  2316. sheet.suspendPaint();
  2317. sheet.setColumnCount(50);
  2318. // table
  2319. var table, rowCount = 5, colCount = 5;
  2320. var row = 0, col = 1;
  2321. sheet.addSpan(row, col, 1, colCount);
  2322. sheet.getCell(row, col).value("Table Style - light7").font("700 11pt Calibri");
  2323. sheet.tables.add("sampleTable0", ++row, col, rowCount, colCount, spreadNS.Tables.TableThemes.light7);
  2324. sheet.addSpan(row + 7, col, 1, colCount);
  2325. sheet.getCell(row + 7, col).value("Table Style - medium7").font("700 11pt Calibri");
  2326. sheet.tables.add("sampleTable1", row + 8, col, rowCount, colCount, spreadNS.Tables.TableThemes.medium7);
  2327. sheet.addSpan(row + 15, col, 1, colCount);
  2328. sheet.getCell(row + 15, col).value("Table Style - dark7").font("700 11pt Calibri");
  2329. sheet.tables.add("sampleTable2", row + 16, col, rowCount, colCount, spreadNS.Tables.TableThemes.dark7);
  2330. sheet.addSpan(row + 23, col, 1, colCount);
  2331. sheet.getCell(row + 23, col).value("Hide Filter Button").font("700 11pt Calibri");
  2332. table = sheet.tables.add("sampleTable3", row + 24, col, rowCount, colCount);
  2333. table.filterButtonVisible(false);
  2334. row = 0, col = col + 7;
  2335. sheet.addSpan(row, col, 1, colCount);
  2336. sheet.getCell(row, col).value("Hide Header Row").font("700 11pt Calibri");
  2337. table = sheet.tables.add("sampleTable4", ++row, col, rowCount, colCount);
  2338. table.showHeader(false);
  2339. sheet.addSpan(row + 7, col, 1, colCount);
  2340. sheet.getCell(row + 7, col).value("Show Total Row").font("700 11pt Calibri");
  2341. table = sheet.tables.add("sampleTable5", row + 8, col, rowCount, colCount);
  2342. table.showFooter(true);
  2343. sheet.addSpan(row + 15, col, 1, colCount);
  2344. sheet.getCell(row + 15, col).value("Don't display alternating row style").font("700 11pt Calibri");
  2345. table = sheet.tables.add("sampleTable6", row + 16, col, rowCount, colCount);
  2346. table.bandRows(false);
  2347. sheet.addSpan(row + 23, col, 1, colCount);
  2348. sheet.getCell(row + 23, col).value("Display alternating column style").font("700 11pt Calibri");
  2349. table = sheet.tables.add("sampleTable7", row + 24, col, rowCount, colCount);
  2350. table.bandRows(false);
  2351. table.bandColumns(true);
  2352. row = 32, col = 1;
  2353. var data = [
  2354. ["bob", "36", "man", "Beijing", "80"],
  2355. ["Betty", "28", "woman", "Xi'an", "52"],
  2356. ["Gary", "23", "man", "NewYork", "63"],
  2357. ["Hunk", "45", "man", "Beijing", "80"],
  2358. ["Cherry", "37", "woman", "Shanghai", "58"]];
  2359. sheet.addSpan(row, col, 1, colCount);
  2360. sheet.getCell(row, col).value("Highlight first column").font("700 11pt Calibri");
  2361. table = sheet.tables.addFromDataSource("sampleTable8", row + 1, col, data);
  2362. table.highlightFirstColumn(true);
  2363. col = col + 7;
  2364. sheet.addSpan(row, col, 1, colCount);
  2365. sheet.getCell(row, col).value("Highlight last column").font("700 11pt Calibri");
  2366. table = sheet.tables.addFromDataSource("sampleTable9", row + 1, col, data);
  2367. table.highlightLastColumn(true);
  2368. sheet.resumePaint();
  2369. }
  2370. function getHBarFormula(range) {
  2371. return "IF(" + range + ">=0.8,HBARSPARKLINE(" + range + ",\"green\"), " +
  2372. "IF(" + range + ">=0.6,HBARSPARKLINE(" + range + ",\"blue\"), " +
  2373. "IF(" + range + ">=0.4,HBARSPARKLINE(" + range + ",\"yellow\"), " +
  2374. "IF(" + range + ">=0.2,HBARSPARKLINE(" + range + ",\"orange\"), " +
  2375. "IF(" + range + ">=0,HBARSPARKLINE(" + range + ",\"red\"), HBARSPARKLINE(" + range + ",\"red\") " + ")))))";
  2376. }
  2377. function getVBarFormula(row) {
  2378. return "=IF((Q3:W3>0)=(ROW(Q13:W14)=ROW($Q$13)),VBARSPARKLINE((Q3:W3)/MAX(ABS(Q3:W3)),Q12:W12),\"\")".replace(/(Q|W)3/g, "$1" + row);
  2379. }
  2380. function setSparklineContent() {
  2381. var sheet = new spreadNS.Worksheet("Sparkline");
  2382. spread.addSheet(spread.getSheetCount(), sheet);
  2383. sheet.suspendPaint();
  2384. sheet.setColumnCount(50);
  2385. addCompatibleContent(sheet);
  2386. addPieContent(sheet);
  2387. addAreaContent(sheet);
  2388. addScatterContent(sheet);
  2389. addStackedContent(sheet);
  2390. addBulletContent(sheet);
  2391. addBoxPlotContent(sheet);
  2392. addVariContent(sheet);
  2393. addCascadeContent(sheet);
  2394. addSpreadContent(sheet);
  2395. addParetoContent(sheet);
  2396. addHBarContent(sheet);
  2397. addVBarContent(sheet);
  2398. addMonthContent(sheet);
  2399. addYearContent(sheet);
  2400. sheet.resumePaint();
  2401. }
  2402. function addMonthContent(sheet) {
  2403. sheet.addSpan(51, 3, 4, 2);
  2404. sheet.addSpan(55, 3, 1, 2);
  2405. var day = 1;
  2406. for (var row = 51; row < 82; row++) {
  2407. sheet.setValue(row, 0, new Date(2016, 0, day++));
  2408. sheet.setValue(row, 1, Math.round(Math.random() * 100));
  2409. sheet.setFormatter(row, 0, "MM/DD/YYYY");
  2410. }
  2411. sheet.setFormula(51, 3, '=MONTHSPARKLINE(2016, 1, A52:B82, "lightgray", "lightgreen", "green", "darkgreen")');
  2412. sheet.setFormula(55, 3, '=TEXT(DATE(2016,1, 1),"mmmm")');
  2413. }
  2414. function addYearContent(sheet) {
  2415. sheet.addSpan(51, 6, 4, 8);
  2416. sheet.setFormula(51, 6, '=YEARSPARKLINE(2016, A52:B82, "lightgray", "lightgreen", "green", "darkgreen")');
  2417. }
  2418. function addCompatibleContent(sheet) {
  2419. sheet.addSpan(0, 0, 1, 8);
  2420. sheet.getCell(0, 0).value("The company revenue in 2014").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2421. sheet.addSpan(1, 2, 1, 2);
  2422. sheet.addSpan(1, 4, 1, 2);
  2423. sheet.addSpan(1, 6, 1, 2);
  2424. sheet.setValue(1, 0, "Month");
  2425. sheet.setValue(1, 1, "Revenue");
  2426. sheet.setValue(1, 2, "Diagram 1");
  2427. sheet.setValue(1, 4, "Diagram 2");
  2428. sheet.setValue(1, 6, "Diagram 3");
  2429. sheet.getRange(1, 0, 1, 7).backColor("Accent 4").foreColor("white");
  2430. for (var i = 2; i < 5; i++) {
  2431. sheet.setValue(i, 0, new Date(2014, i - 1, 1));
  2432. sheet.setFormatter(i, 0, "mm/dd/yyyy");
  2433. }
  2434. sheet.setColumnWidth(0, 80);
  2435. sheet.setValue(2, 1, 30);
  2436. sheet.setValue(3, 1, -60);
  2437. sheet.setValue(4, 1, 80);
  2438. sheet.addSpan(2, 2, 3, 2);
  2439. sheet.setFormula(2, 2, '=LINESPARKLINE(B3:B5,0,A3:A5,0,"{ac:#ffff00,fmc:brown,hmc:red,lastmc:blue,lowmc:green,mc:purple,nc:yellowgreen,sc:pink,dxa:true,sf:true,sh:true,slast:true,slow:true,sn:true,sm:true,lw:3,dh:false,deca:1,rtl:false,minat:1,maxat:1,mmax:5,mmin:-3}")');
  2440. sheet.addSpan(2, 4, 3, 2);
  2441. sheet.setFormula(2, 4, '=COLUMNSPARKLINE(B3:B5,0,A3:A5,0,"{ac:#ffff00,fmc:brown,hmc:red,lastmc:blue,lowmc:green,mc:purple,nc:yellowgreen,sc:pink,dxa:true,sf:true,sh:true,slast:true,slow:true,sn:true,sm:true,lw:3,dh:false,deca:1,rtl:false,minat:1,maxat:1,mmax:5,mmin:-3}")');
  2442. sheet.addSpan(2, 6, 3, 2);
  2443. sheet.setFormula(2, 6, '=WINLOSSSPARKLINE(B3:B5,0,A3:A5,0)');
  2444. }
  2445. function addPieContent(sheet) {
  2446. sheet.addSpan(6, 0, 1, 5);
  2447. sheet.getCell(6, 0).value("My Assets").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2448. sheet.addSpan(7, 2, 1, 2);
  2449. sheet.addSpan(8, 2, 3, 2);
  2450. sheet.setValue(7, 0, "Asset Type");
  2451. sheet.setValue(7, 1, "Amount");
  2452. sheet.setValue(7, 2, "Diagram");
  2453. sheet.setValue(7, 4, "Note");
  2454. sheet.setValue(8, 0, "Savings");
  2455. sheet.getRange(7, 0, 1, 5).backColor("Accent 4").foreColor("white");
  2456. sheet.getCell(8, 1).value(25000).formatter("$#,##0");
  2457. sheet.setValue(9, 0, "401k");
  2458. sheet.getCell(9, 1).value(55000).formatter("$#,##0");
  2459. sheet.setValue(10, 0, "Stocks");
  2460. sheet.getCell(10, 1).value(15000).formatter("$#,##0");
  2461. sheet.setFormula(8, 2, '=PIESPARKLINE(B9:B11,"#919F81","#D7913E","CEA722")');
  2462. sheet.getCell(8, 4).backColor("#919F81").formula("=B9/SUM(B9:B11)").formatter("0.00%");
  2463. sheet.getCell(9, 4).backColor("#D7913E").formula("=B10/SUM(B9:B11)").formatter("0.00%");
  2464. sheet.getCell(10, 4).backColor("#CEA722").formula("=B11/SUM(B9:B11)").formatter("0.00%");
  2465. }
  2466. function addAreaContent(sheet) {
  2467. sheet.addSpan(12, 0, 1, 5);
  2468. sheet.getCell(12, 0).value("Sales by State").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2469. sheet.addSpan(13, 2, 1, 3);
  2470. sheet.addSpan(14, 2, 4, 3);
  2471. sheet.setValue(13, 0, "State");
  2472. sheet.setValue(13, 1, "Sales");
  2473. sheet.setValue(13, 2, "Diagram");
  2474. sheet.setValue(14, 0, "Idaho");
  2475. sheet.getRange(13, 0, 1, 3).backColor("Accent 4").foreColor("white");
  2476. sheet.getCell(14, 1).value(3500).formatter("$#,##0");
  2477. sheet.setValue(15, 0, "Montana");
  2478. sheet.getCell(15, 1).value(7000).formatter("$#,##0");
  2479. sheet.setValue(16, 0, "Oregon");
  2480. sheet.getCell(16, 1).value(2000).formatter("$#,##0");
  2481. sheet.setValue(17, 0, "Washington");
  2482. sheet.getCell(17, 1).value(5000).formatter("$#,##0");
  2483. sheet.setFormula(14, 2, '=AREASPARKLINE(B15:B18,,,0,6000,"yellowgreen","red")');
  2484. }
  2485. function addScatterContent(sheet) {
  2486. sheet.addSpan(19, 0, 1, 5);
  2487. sheet.getCell(19, 0).value("Particulate Levels in Rainfall").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2488. sheet.addSpan(20, 2, 1, 3);
  2489. sheet.addSpan(21, 2, 4, 3);
  2490. sheet.setValue(20, 0, "Daily rainfall");
  2491. sheet.setValue(20, 1, "Particulate level");
  2492. sheet.setValue(20, 2, "Diagram");
  2493. sheet.getRange(20, 0, 1, 3).backColor("Accent 4").foreColor("white");
  2494. sheet.setValue(21, 0, 2.0);
  2495. sheet.setValue(21, 1, 100);
  2496. sheet.setValue(22, 0, 3.0);
  2497. sheet.setValue(22, 1, 130);
  2498. sheet.setValue(23, 0, 4.0);
  2499. sheet.setValue(23, 1, 110);
  2500. sheet.setValue(24, 0, 5.0);
  2501. sheet.setValue(24, 1, 135);
  2502. sheet.setFormula(21, 2, '=SCATTERSPARKLINE(A22:B25,,MIN(A22:A25),MAX(A22:A25),MIN(B22:B25),MAX(B22:B25),AVERAGE(B22:B25),AVERAGE(A22:A25),,,,,TRUE,TRUE,TRUE,"green",,TRUE)');
  2503. }
  2504. function addStackedContent(sheet) {
  2505. sheet.addSpan(26, 0, 1, 5);
  2506. sheet.getCell(26, 0).value("Sales by State").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2507. sheet.getRange(27, 0, 1, 6).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2508. sheet.addSpan(27, 4, 1, 3);
  2509. sheet.addSpan(28, 4, 1, 3);
  2510. sheet.setRowHeight(28, 30);
  2511. sheet.setValue(27, 0, "State");
  2512. sheet.setValue(27, 1, "Product 1");
  2513. sheet.setValue(27, 2, "Product 2");
  2514. sheet.setValue(27, 3, "Product 3");
  2515. sheet.setValue(27, 4, "Diagram");
  2516. sheet.setValue(28, 0, "Idaho");
  2517. sheet.getCell(28, 1).value(10000).formatter("$#,##0");
  2518. sheet.getCell(28, 2).value(12000).formatter("$#,##0");
  2519. sheet.getCell(28, 3).value(15000).formatter("$#,##0");
  2520. sheet.setValue(29, 1, "orange");
  2521. sheet.setValue(29, 2, "purple");
  2522. sheet.setValue(29, 3, "yellowgreen");
  2523. sheet.setFormula(28, 4, '=STACKEDSPARKLINE(B29:D29,B30:D30,B28:D28,40000)');
  2524. }
  2525. function addBulletContent(sheet) {
  2526. sheet.addSpan(31, 0, 1, 5);
  2527. sheet.getCell(31, 0).value("Employee KPI").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2528. sheet.getRange(32, 0, 1, 4).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.HorizontalAlign.center);
  2529. sheet.addSpan(32, 3, 1, 2);
  2530. sheet.addSpan(33, 3, 1, 2);
  2531. sheet.addSpan(34, 3, 1, 2);
  2532. sheet.addSpan(35, 3, 1, 2);
  2533. sheet.setValue(32, 0, "Name");
  2534. sheet.setValue(32, 1, "Forecast");
  2535. sheet.setValue(32, 2, "Actuality");
  2536. sheet.setValue(32, 3, "Diagram");
  2537. sheet.setValue(33, 0, "Employee 1");
  2538. sheet.setValue(33, 1, 6);
  2539. sheet.setValue(33, 2, 6);
  2540. sheet.setValue(34, 0, "Employee 2");
  2541. sheet.setValue(34, 1, 8);
  2542. sheet.setValue(34, 2, 7);
  2543. sheet.setValue(35, 0, "Employee 3");
  2544. sheet.setValue(35, 1, 6);
  2545. sheet.setValue(35, 2, 4);
  2546. sheet.addSpan(38, 6, 1, 3);
  2547. sheet.setValue(38, 6, "BULLETSPARKLINE Settings:");
  2548. sheet.setValue(39, 6, "target");
  2549. sheet.setValue(39, 7, 7);
  2550. sheet.setValue(40, 6, "maxi");
  2551. sheet.setValue(40, 7, 10);
  2552. sheet.setValue(41, 6, "good");
  2553. sheet.setValue(41, 7, 8);
  2554. sheet.setValue(42, 6, "bad");
  2555. sheet.setValue(42, 7, 5);
  2556. sheet.setValue(43, 6, "color scheme");
  2557. sheet.setValue(43, 7, "gray");
  2558. sheet.setFormula(33, 3, '=BULLETSPARKLINE(C34,H40,H41,H42,H43,H34,1,H44)');
  2559. sheet.setFormula(34, 3, '=BULLETSPARKLINE(C35,H40,H41,H42,H43,H34,1,H44)');
  2560. sheet.setFormula(35, 3, '=BULLETSPARKLINE(C36,H40,H41,H42,H43,H34,1,H44)');
  2561. sheet.setRowHeight(33, 28);
  2562. sheet.setRowHeight(34, 28);
  2563. sheet.setRowHeight(35, 28);
  2564. }
  2565. function addBoxPlotContent(sheet) {
  2566. sheet.addSpan(31, 6, 1, 8);
  2567. sheet.getCell(31, 6).value("The Company Sales in 2014 (Month)").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2568. sheet.addSpan(32, 12, 1, 2);
  2569. sheet.addSpan(33, 12, 1, 2);
  2570. sheet.addSpan(34, 12, 1, 2);
  2571. sheet.addSpan(35, 12, 1, 2);
  2572. sheet.setValue(32, 7, 1);
  2573. sheet.setValue(32, 8, 2);
  2574. sheet.setValue(32, 9, 3);
  2575. sheet.setValue(32, 10, 4);
  2576. sheet.setValue(32, 11, 5);
  2577. sheet.setValue(32, 12, "Actual Sales");
  2578. sheet.getRange(32, 7, 1, 7).hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center).wordWrap(true);
  2579. sheet.setValue(32, 6, "Region");
  2580. sheet.setValue(33, 6, "Alabama");
  2581. sheet.setValue(34, 6, "Alaska");
  2582. sheet.setValue(35, 6, "Arizona");
  2583. var data = [[5268, 6281, 8921, 1069, 1239],
  2584. [2837, 5739, 993, 4247, 9514],
  2585. [6661, 4172, 9777, 1282, 9535]];
  2586. sheet.setArray(33, 7, data);
  2587. sheet.addSpan(38, 10, 1, 4);
  2588. sheet.setValue(38, 10, "BOXPLOTSPARKLINE Settings:");
  2589. sheet.setValue(39, 10, "Start scope of the sale:");
  2590. sheet.setValue(40, 10, "End scope of the sale:");
  2591. sheet.setValue(41, 10, "Start scope of expected sale:");
  2592. sheet.setValue(42, 10, "End scope of expected sale:");
  2593. sheet.addSpan(39, 10, 1, 3);
  2594. sheet.addSpan(40, 10, 1, 3);
  2595. sheet.addSpan(41, 10, 1, 3);
  2596. sheet.addSpan(42, 10, 1, 3);
  2597. sheet.setValue(39, 13, 0);
  2598. sheet.setValue(40, 13, 10000);
  2599. sheet.setValue(41, 13, 1000);
  2600. sheet.setValue(42, 13, 8000);
  2601. sheet.getRange(32, 6, 1, 7).backColor("Accent 4").foreColor("white");
  2602. sheet.setFormula(33, 12, '=BOXPLOTSPARKLINE(H34:L34,"5ns",true,N40,N41,N42,N43,"#00FF7F",0,false)');
  2603. sheet.setFormula(34, 12, '=BOXPLOTSPARKLINE(H35:L35,"5ns",true,N40,N41,N42,N43,"#00FF7F",0,false)');
  2604. sheet.setFormula(35, 12, '=BOXPLOTSPARKLINE(H36:L36,"5ns",true,N40,N41,N42,N43,"#00FF7F",0,false)');
  2605. }
  2606. function addVariContent(sheet) {
  2607. sheet.addSpan(0, 9, 1, 5);
  2608. sheet.getCell(0, 9).value("Mobile Phone Contrast").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2609. sheet.getRange(1, 9, 1, 5).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center)
  2610. .vAlign(spreadNS.VerticalAlign.center).wordWrap(true);
  2611. sheet.addSpan(1, 12, 1, 2);
  2612. sheet.addSpan(2, 12, 1, 2);
  2613. sheet.addSpan(3, 12, 1, 2);
  2614. sheet.addSpan(4, 12, 1, 2);
  2615. sheet.setValue(1, 10, "Phone I");
  2616. sheet.setValue(1, 11, "Phone II");
  2617. sheet.setValue(1, 12, "Diagram");
  2618. var data = [["Size(inch)", 5, 4.7],
  2619. ["RAM(G)", 3, 1],
  2620. ["Weight(g)", 149, 129]];
  2621. sheet.setArray(2, 9, data);
  2622. sheet.setFormula(2, 12, '=VARISPARKLINE(ROUND((K3-L3)/K3,2),0,,,,,TRUE)');
  2623. sheet.setFormula(3, 12, '=VARISPARKLINE(ROUND((K4-L4)/K4,2),0,,,,,TRUE)');
  2624. sheet.setFormula(4, 12, '=VARISPARKLINE(ROUND(-1*(K5-L5)/K5,2),0,,,,,TRUE)');
  2625. }
  2626. function addCascadeContent(sheet) {
  2627. sheet.addSpan(6, 6, 1, 8);
  2628. sheet.getCell(6, 6).value("Checkbook Register").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2629. for (var r = 7; r < 12; r++) {
  2630. sheet.addSpan(r, 6, 1, 2);
  2631. sheet.addSpan(r, 11, 1, 3);
  2632. }
  2633. sheet.setArray(7, 6, [
  2634. ["", "", "InitialValue", 815.25, "\u03A3"],
  2635. ["12/11/2012", "", "CVS", -200],
  2636. ["12/12/2012", "", "Bank", 1000.12],
  2637. ["12/13/2012", "", "Starbucks", -500.43],
  2638. ["", "", "FinalValue"]
  2639. ]);
  2640. sheet.getRange(8, 6, 3, 1).formatter("MM/dd/yyyy");
  2641. sheet.getRange(7, 9, 5, 1).formatter("#,###.00");
  2642. sheet.getRange(8, 10, 3, 1).formatter("#,###.00");
  2643. sheet.getCell(7, 10).hAlign(spreadNS.HorizontalAlign.center);
  2644. sheet.getRange(7, 8, 1, 2).font("bold 14px Georgia");
  2645. sheet.getRange(11, 8, 1, 2).font("bold 14px Georgia");
  2646. sheet.setFormula(8, 10, "=J8 + J9");
  2647. for (var r = 10; r <= 11; r++) {
  2648. sheet.setFormula(r - 1, 10, "=J" + r + " + K" + (r - 1));
  2649. }
  2650. sheet.setFormula(11, 9, "=K11");
  2651. sheet.getRange(7, 6, 1, 8).setBorder(new spreadNS.LineBorder("black", spreadNS.LineStyle.thin), {bottom: true});
  2652. sheet.getRange(11, 6, 1, 8).setBorder(new spreadNS.LineBorder("black", spreadNS.LineStyle.medium), {top: true});
  2653. sheet.setFormula(7, 11, '=CASCADESPARKLINE(J8:J12,1,I8:I12,,,"#8CBF64","#D6604D",false)');
  2654. sheet.setFormula(8, 11, '=CASCADESPARKLINE(J8:J12,2,I8:I12,,,"#8CBF64","#D6604D",false)');
  2655. sheet.setFormula(9, 11, '=CASCADESPARKLINE(J8:J12,3,I8:I12,,,"#8CBF64","#D6604D",false)');
  2656. sheet.setFormula(10, 11, '=CASCADESPARKLINE(J8:J12,4,I8:I12,,,"#8CBF64","#D6604D",false)');
  2657. sheet.setFormula(11, 11, '=CASCADESPARKLINE(J8:J12,5,I8:I12,,,"#8CBF64","#D6604D",false)');
  2658. }
  2659. function addSpreadContent(sheet) {
  2660. sheet.addSpan(13, 6, 1, 7);
  2661. sheet.getCell(13, 6).value("Student Grade Statistics").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2662. sheet.getRange(14, 6, 1, 8).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2663. sheet.addSpan(15, 6, 2, 1);
  2664. sheet.addSpan(14, 7, 1, 2);
  2665. sheet.addSpan(14, 9, 1, 2);
  2666. sheet.addSpan(14, 11, 1, 2);
  2667. sheet.addSpan(15, 7, 2, 2);
  2668. sheet.addSpan(15, 9, 2, 2);
  2669. sheet.addSpan(15, 11, 2, 2);
  2670. sheet.addSpan(15, 13, 2, 1);
  2671. for (var r = 17; r <= 21; r++) {
  2672. sheet.addSpan(r, 7, 1, 2);
  2673. sheet.addSpan(r, 9, 1, 2);
  2674. sheet.addSpan(r, 11, 1, 2);
  2675. }
  2676. sheet.setArray(14, 6, [["Name", "Chinese", "", "Math", "", "English", "", "Total"]]);
  2677. sheet.setArray(17, 6, [
  2678. ["Student 1", 70, "", 90, "", 51],
  2679. ["Student 2", 99, "", 59, "", 63],
  2680. ["Student 3", 89, "", 128, "", 74],
  2681. ["Student 4", 93, "", 61, "", 53],
  2682. ["Student 5", 106, "", 82, "", 80]
  2683. ]);
  2684. for (var i = 0; i <= 5; i++) {
  2685. r = 17 + i;
  2686. sheet.setFormula(r - 1, 13, "=Sum(H" + r + ":M" + r + ")");
  2687. }
  2688. sheet.setFormula(15, 7, "=SPREADSPARKLINE(H18:I22,TRUE,,,1,\"green\")");
  2689. sheet.setFormula(15, 9, "=SPREADSPARKLINE(J18:K22,TRUE,,,3,\"green\")");
  2690. sheet.setFormula(15, 11, "=SPREADSPARKLINE(L18:M22,TRUE,,,5,\"green\")");
  2691. sheet.setFormula(15, 13, "=SPREADSPARKLINE(N18:N22,TRUE,,,6,\"green\")");
  2692. }
  2693. function addParetoContent(sheet) {
  2694. sheet.addSpan(23, 8, 1, 6);
  2695. sheet.getCell(23, 8).value("The Reason of Being Late").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2696. sheet.getRange(24, 8, 1, 6).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2697. for (var r = 24; r < 30; r++) {
  2698. sheet.addSpan(r, 11, 1, 3);
  2699. }
  2700. sheet.setArray(24, 8, [
  2701. ["", "Points", "Color", "Diagram"],
  2702. ["Traffic", 20, "#FF1493"],
  2703. ["Child care", 15, "#FFE7BA"],
  2704. ["Weather", 16, "#FFAEB9"],
  2705. ["Overslept", 4, "#FF8C69"],
  2706. ["Emergency", 1, "#FF83FA"]
  2707. ]);
  2708. sheet.addSpan(45, 6, 1, 3);
  2709. sheet.setValue(45, 6, "PARETOSPARKLINE Settings:");
  2710. sheet.setValue(46, 6, "target");
  2711. sheet.setValue(46, 7, 0.5);
  2712. sheet.setValue(47, 6, "target1");
  2713. sheet.setValue(47, 7, 0.8);
  2714. sheet.setFormula(25, 11, '=PARETOSPARKLINE(J26:J30,1,K26:K30,H47,H48,4,2,false)');
  2715. sheet.setFormula(26, 11, '=PARETOSPARKLINE(J26:J30,2,K26:K30,H47,H48,4,2,false)');
  2716. sheet.setFormula(27, 11, '=PARETOSPARKLINE(J26:J30,3,K26:K30,H47,H48,4,2,false)');
  2717. sheet.setFormula(28, 11, '=PARETOSPARKLINE(J26:J30,4,K26:K30,H47,H48,4,2,false)');
  2718. sheet.setFormula(29, 11, '=PARETOSPARKLINE(J26:J30,5,K26:K30,H47,H48,4,2,false)');
  2719. }
  2720. function addHBarContent(sheet) {
  2721. row = 37, col = 0;
  2722. sheet.addSpan(row, col, 1, 6);
  2723. sheet.getCell(row, col).value("SPRINT 4").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2724. sheet.getRange(row + 1, 8, 1, 6).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2725. for (var r = 38; r < 44; r++) {
  2726. sheet.addSpan(r, 2, 1, 3);
  2727. }
  2728. sheet.getCell(++row, col).value("Name");
  2729. sheet.getCell(++row, col).value("Employee1");
  2730. sheet.getCell(++row, col).value("Employee2");
  2731. sheet.getCell(++row, col).value("Employee3");
  2732. sheet.getCell(++row, col).value("Employee4");
  2733. sheet.getCell(++row, col).value("Employee5");
  2734. row = 38, col++;
  2735. sheet.getCell(row, col).value("Progress");
  2736. sheet.getCell(++row, col).value(0.7);
  2737. sheet.getCell(++row, col).value(0.1);
  2738. sheet.getCell(++row, col).value(0.3);
  2739. sheet.getCell(++row, col).value(1.1);
  2740. sheet.getCell(++row, col).value(0.5);
  2741. row = 38, col++;
  2742. sheet.getCell(row, col).value("Diagram");
  2743. sheet.getRange(38, 0, 1, 3).backColor("Accent 4").foreColor("white");
  2744. sheet.setFormula(++row, col, getHBarFormula("B40"));
  2745. sheet.setFormula(++row, col, getHBarFormula("B41"));
  2746. sheet.setFormula(++row, col, getHBarFormula("B42"));
  2747. sheet.setFormula(++row, col, getHBarFormula("B43"));
  2748. sheet.setFormula(++row, col, getHBarFormula("B44"));
  2749. }
  2750. function addVBarContent(sheet) {
  2751. sheet.setColumnWidth(15, 60);
  2752. for (var c = 16; c < 23; c++) {
  2753. sheet.setColumnWidth(c, 30);
  2754. }
  2755. sheet.addSpan(0, 15, 1, 8);
  2756. sheet.getCell(0, 15).value("The Temperature Variation").font("20px Arial").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2757. sheet.getRange(1, 15, 1, 8).foreColor("white").backColor("Accent 4").hAlign(spreadNS.HorizontalAlign.center).vAlign(spreadNS.VerticalAlign.center);
  2758. row = 2;
  2759. sheet.addSpan(row, 15, 3, 1);
  2760. sheet.addSpan(row + 3, 15, 3, 1);
  2761. sheet.addSpan(row + 6, 15, 3, 1);
  2762. sheet.setArray(1, 15, [["City", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"]]);
  2763. var datas = [
  2764. ["Austin", 5, 11, 19, 24, 21, 16, 6],
  2765. ["Buffalo", -8, -3, -1, 3, 14, 6, -4],
  2766. ["Chicago", -9, -2, 2, 18, 12, 5, -6]
  2767. ];
  2768. var colors = ["#0099FF", "#33FFFF", "#9E0142", "#D53E4F", "#F46D43", "#FDAE61", "#FEE08B"];
  2769. sheet.setArray(11, 16, [colors]);
  2770. for (var i = 0; i < datas.length; i++) {
  2771. var row = 2 + 3 * i;
  2772. sheet.setArray(row, 15, [datas[i]]);
  2773. sheet.setArrayFormula(row + 1, 16, 2, 7, getVBarFormula(row + 1));
  2774. sheet.setRowHeight(row + 1, 30);
  2775. sheet.setRowHeight(row + 2, 30);
  2776. }
  2777. }
  2778. function setCommentContent() {
  2779. var sheet = new spreadNS.Worksheet("Comment");
  2780. spread.addSheet(spread.getSheetCount(), sheet);
  2781. sheet.suspendPaint();
  2782. sheet.setColumnCount(50);
  2783. for (var col = 2; col < 9; col++) {
  2784. sheet.setColumnWidth(col, 100);
  2785. }
  2786. var Comment = spreadNS.Comments.Comment;
  2787. var DisplayMode = spreadNS.Comments.DisplayMode;
  2788. var commentText = "Hello, world!";
  2789. var rowCount = 5, colCount = 4;
  2790. var row = 2, col = 2;
  2791. sheet.getCell(row, col).value("HoverShown").font("700 11pt Calibri");
  2792. sheet.comments.add(row, col, commentText);
  2793. sheet.getCell(row, col + colCount).value("AlwaysShown").font("700 11pt Calibri");
  2794. sheet.comments.add(row, col + colCount, commentText)
  2795. .displayMode(DisplayMode.alwaysShown);
  2796. row = row + rowCount;
  2797. sheet.getCell(row, col).value("Size").font("700 11pt Calibri");
  2798. sheet.comments.add(row, col, commentText)
  2799. .displayMode(DisplayMode.alwaysShown)
  2800. .height(80)
  2801. .width(200);
  2802. sheet.getCell(row, col + colCount).value("Shadow").font("700 11pt Calibri");
  2803. sheet.comments.add(row, col + colCount, commentText)
  2804. .displayMode(DisplayMode.alwaysShown)
  2805. .showShadow(true);
  2806. row = row + rowCount;
  2807. sheet.getCell(row, col).value("Font").font("700 11pt Calibri");
  2808. sheet.comments.add(row, col, commentText)
  2809. .displayMode(DisplayMode.alwaysShown)
  2810. .fontFamily("Comic Sans MS")
  2811. .fontSize("10pt")
  2812. .fontStyle("italic")
  2813. .fontWeight("bold");
  2814. sheet.getCell(row, col + colCount).value("Color Opacity").font("700 11pt Calibri");
  2815. sheet.comments.add(row, col + colCount, commentText)
  2816. .displayMode(DisplayMode.alwaysShown)
  2817. .foreColor("green")
  2818. .backColor("yellow")
  2819. .opacity(0.8);
  2820. row = row + rowCount;
  2821. sheet.getCell(row, col).value("Border").font("700 11pt Calibri");
  2822. sheet.comments.add(row, col, commentText)
  2823. .displayMode(DisplayMode.alwaysShown)
  2824. .borderColor("green")
  2825. .borderStyle("dotted")
  2826. .borderWidth(2);
  2827. sheet.getCell(row, col + colCount).value("Text Decoration").font("700 11pt Calibri");
  2828. sheet.comments.add(row, col + colCount, commentText)
  2829. .displayMode(DisplayMode.alwaysShown)
  2830. .textDecoration(1)
  2831. .horizontalAlign(1)
  2832. .padding(new spreadNS.Comments.Padding(2));
  2833. sheet.resumePaint();
  2834. }
  2835. function setPictureContent() {
  2836. var sheet = new spreadNS.Worksheet("Picture");
  2837. spread.addSheet(spread.getSheetCount(), sheet);
  2838. sheet.suspendPaint();
  2839. sheet.setColumnCount(50);
  2840. sheet.setColumnWidth(0, 20);
  2841. var url = "css/images/logo.png";
  2842. var ImageLayout = spreadNS.ImageLayout;
  2843. var row, col, rowCount = 11, colCount = 5,
  2844. colWidth = sheet.getColumnWidth(1), rowHeight = sheet.getRowHeight(1),
  2845. width = colCount * colWidth, height = rowCount * rowHeight,
  2846. x = sheet.getColumnWidth(0) + colWidth, y = 2 * rowHeight,
  2847. xOffset = (colCount + 2) * colWidth, yOffset = (rowCount + 2) * rowHeight;
  2848. row = 1, col = 2;
  2849. sheet.addSpan(row, col, 1, colCount);
  2850. sheet.getCell(row, col).value("Border").font("700 11pt Calibri");
  2851. sheet.pictures.add("border_picture", url, x, y, width, height)
  2852. .backColor("#000000")
  2853. .borderColor("red")
  2854. .borderWidth(4)
  2855. .borderStyle("dotted")
  2856. .borderRadius(5);
  2857. col = col + colCount + 2;
  2858. sheet.addSpan(row, col, 1, colCount);
  2859. sheet.getCell(row, col).value("Fixed Position").font("700 11pt Calibri");
  2860. sheet.pictures.add("fixed_picture", url, x + xOffset, y, width, height)
  2861. .backColor("#000000")
  2862. .fixedPosition(true);
  2863. row = row + rowCount + 2, col = 2;
  2864. y += yOffset;
  2865. sheet.addSpan(row, col, 1, colCount);
  2866. sheet.getCell(row, col).value("Stretch").font("700 11pt Calibri");
  2867. sheet.pictures.add("stretch_picture", url, x, y, width, height)
  2868. .backColor("#000000");
  2869. col = col + colCount + 2;
  2870. sheet.addSpan(row, col, 1, colCount);
  2871. sheet.getCell(row, col).value("Center").font("700 11pt Calibri");
  2872. sheet.pictures.add("center_picture", url, x + xOffset, y, width, height)
  2873. .backColor("#000000")
  2874. .pictureStretch(ImageLayout.center);
  2875. row = row + rowCount + 2, col = 2;
  2876. y += yOffset;
  2877. sheet.addSpan(row, col, 1, colCount);
  2878. sheet.getCell(row, col).value("Zoom").font("700 11pt Calibri");
  2879. sheet.pictures.add("zoom_picture", url, x, y, width, height)
  2880. .backColor("#000000")
  2881. .pictureStretch(ImageLayout.zoom);
  2882. col = col + colCount + 2;
  2883. sheet.addSpan(row, col, 1, colCount);
  2884. sheet.getCell(row, col).value("None").font("700 11pt Calibri");
  2885. sheet.pictures.add("none_picture", url, x + xOffset, y, width, height)
  2886. .backColor("#000000")
  2887. .pictureStretch(ImageLayout.none);
  2888. sheet.resumePaint();
  2889. }
  2890. function setDataContent() {
  2891. var sheet = new spreadNS.Worksheet("Data");
  2892. spread.addSheet(spread.getSheetCount(), sheet);
  2893. sheet.suspendPaint();
  2894. sheet.setColumnCount(50);
  2895. for (var col = 1; col < 6; col = col + 2) {
  2896. for (var row = 2; row < 10; row++) {
  2897. sheet.getCell(row, col).value(getRandomNumber());
  2898. }
  2899. }
  2900. var row = 1, col = 1, rowCount = 8, colCount = 1;
  2901. sheet.getCell(row, col).value("Sort A-Z").font("700 11pt Calibri");
  2902. sheet.sortRange(row + 1, col, rowCount, colCount, true, [{index: col, ascending: true}]);
  2903. col = col + 2;
  2904. sheet.getCell(row, col).value("Sort Z-A").font("700 11pt Calibri");
  2905. sheet.sortRange(row + 1, col, rowCount, colCount, true, [{index: col, ascending: false}]);
  2906. col = col + 2;
  2907. sheet.getCell(row, col).value("Filter").font("700 11pt Calibri");
  2908. sheet.rowFilter(new spreadNS.Filter.HideRowFilter(new spreadNS.Range(row + 1, col, rowCount, colCount)));
  2909. sheet.rowOutlines.group(12, 3);
  2910. sheet.columnOutlines.group(8, 5);
  2911. row = 12, col = 1;
  2912. sheet.addSpan(row, col, 1, 9);
  2913. sheet.getCell(row, col).value("Data Validation").vAlign(spreadNS.VerticalAlign.center).hAlign(spreadNS.HorizontalAlign.center).font("700 11pt Calibri");
  2914. row = 13;
  2915. sheet.getCell(row, col).value("List").font("700 11pt Calibri");
  2916. sheet.getCell(row, col + 2).value("Number").font("700 11pt Calibri");
  2917. sheet.getCell(row, col + 4).value("Date").font("700 11pt Calibri");
  2918. sheet.getCell(row, col + 6).value("Formula").font("700 11pt Calibri");
  2919. sheet.getCell(row, col + 8).value("TextLength").font("700 11pt Calibri");
  2920. row = 14;
  2921. var listValidator = DataValidation.createListValidator("Fruit,Vegetable,Food");
  2922. listValidator.inputTitle("Please choose a category:");
  2923. listValidator.inputMessage("Fruit, Vegetable, Food");
  2924. sheet.getCell(row + 1, col).value("Vegetable");
  2925. sheet.getCell(row + 2, col).value("Home");
  2926. sheet.getCell(row + 3, col).value("Fruit");
  2927. sheet.getCell(row + 4, col).value("Company");
  2928. sheet.getCell(row + 5, col).value("Food");
  2929. for (var r = row + 1; r < row + 6; r++) {
  2930. sheet.setDataValidator(r, col, listValidator);
  2931. }
  2932. col = col + 2;
  2933. var numberValidator = DataValidation.createNumberValidator(ComparisonOperators.between, 0, 100, true);
  2934. numberValidator.inputMessage("Value should Between 0 ~ 100");
  2935. numberValidator.inputTitle("Tip");
  2936. sheet.getCell(row + 1, col).value(-12);
  2937. sheet.getCell(row + 2, col).value(30);
  2938. sheet.getCell(row + 3, col).value(80);
  2939. sheet.getCell(row + 4, col).value(-35);
  2940. sheet.getCell(row + 5, col).value(66);
  2941. for (var r = row + 1; r < row + 6; r++) {
  2942. sheet.setDataValidator(r, col, numberValidator);
  2943. }
  2944. col = col + 2;
  2945. sheet.setColumnWidth(col, 100);
  2946. var currentDate = new Date().toLocaleDateString().replace(/\u200E/g, ''); // this "replace" is just for IE, the date string contains some special characters
  2947. var dateValidator = DataValidation.createDateValidator(ComparisonOperators.lessThan, currentDate, currentDate);
  2948. dateValidator.inputMessage("Enter a date Less than " + currentDate);
  2949. dateValidator.inputTitle("Tip");
  2950. sheet.getCell(row + 1, col).value("2014/08/20");
  2951. sheet.getCell(row + 2, col).value("2050/10/12");
  2952. sheet.getCell(row + 3, col).value("1993/05/23");
  2953. sheet.getCell(row + 4, col).value("2020/01/02");
  2954. sheet.getCell(row + 5, col).value("2015/10/20");
  2955. for (var r = row + 1; r < row + 6; r++) {
  2956. sheet.setDataValidator(r, col, dateValidator);
  2957. }
  2958. col = col + 2;
  2959. var formula = getCellPositionString(sheet, row + 6, col + 1) + "<100";
  2960. var formulaValidator = DataValidation.createFormulaValidator(formula);
  2961. formulaValidator.inputTitle("Tip");
  2962. sheet.getCell(row + 1, col).value(20);
  2963. sheet.getCell(row + 2, col).value(300);
  2964. sheet.getCell(row + 3, col).value(2);
  2965. sheet.getCell(row + 4, col).value(-35);
  2966. var sumFormula = "=SUM(" + getCellPositionString(sheet, row + 2, col + 1)
  2967. + ":" + getCellPositionString(sheet, row + 5, col + 1) + ")";
  2968. sheet.getCell(row + 5, col).formula(sumFormula);
  2969. formulaValidator.inputMessage("Be sure " + sumFormula.substr(1) + " less than 100");
  2970. sheet.setDataValidator(row + 5, col, formulaValidator);
  2971. col = col + 2;
  2972. sheet.setColumnWidth(col, 120);
  2973. var textLengthValidator = DataValidation.createTextLengthValidator(ComparisonOperators.lessThan, 6, 6);
  2974. textLengthValidator.inputMessage("Text length should Less than 6");
  2975. textLengthValidator.inputTitle("Tip");
  2976. sheet.getCell(row + 1, col).value("Hello, SpreadJS");
  2977. sheet.getCell(row + 2, col).value("God");
  2978. sheet.getCell(row + 3, col).value("Word");
  2979. sheet.getCell(row + 4, col).value("Warning");
  2980. sheet.getCell(row + 5, col).value("Boy");
  2981. for (var r = row + 1; r < row + 6; r++) {
  2982. sheet.setDataValidator(r, col, textLengthValidator);
  2983. }
  2984. spread.options.highlightInvalidData = true;
  2985. sheet.resumePaint();
  2986. }
  2987. function setSlicerContent() {
  2988. var sheet = new spreadNS.Worksheet("Slicer");
  2989. spread.addSheet(spread.getSheetCount(), sheet);
  2990. sheet.suspendPaint();
  2991. sheet.setColumnCount(50);
  2992. var tableName = "slicerTable";
  2993. var dataColumns = ["Name", "Age", "Sex", "Address", "Weight", "Height"];
  2994. var data = [
  2995. ["bob", "36", "man", "Beijing", "80", "180"],
  2996. ["Betty", "28", "woman", "Xi'an", "52", "168"],
  2997. ["Gary", "23", "man", "NewYork", "63", "175"],
  2998. ["Hunk", "45", "man", "Beijing", "80", "171"],
  2999. ["Cherry", "37", "woman", "Shanghai", "58", "161"],
  3000. ["Eva", "30", "woman", "NewYork", "63", "180"]];
  3001. sheet.tables.addFromDataSource(tableName, 6, 3, data);
  3002. var table = sheet.tables.findByName(tableName);
  3003. table.setColumnName(0, dataColumns[0]);
  3004. table.setColumnName(1, dataColumns[1]);
  3005. table.setColumnName(2, dataColumns[2]);
  3006. table.setColumnName(3, dataColumns[3]);
  3007. table.setColumnName(4, dataColumns[4]);
  3008. table.setColumnName(5, dataColumns[5]);
  3009. var slicer0 = sheet.slicers.add("slicer1", tableName, "Name");
  3010. slicer0.position(new spreadNS.Point(50, 300));
  3011. var slicer1 = sheet.slicers.add("slicer2", tableName, "Sex");
  3012. slicer1.position(new spreadNS.Point(275, 300));
  3013. var slicer2 = sheet.slicers.add("slicer3", tableName, "Height");
  3014. slicer2.position(new spreadNS.Point(500, 300));
  3015. sheet.resumePaint();
  3016. }
  3017. // Sample Content related items (end)
  3018. function getCellInfo(sheet, row, column) {
  3019. var result = {type: ""}, object;
  3020. if ((object = sheet.comments.get(row, column))) {
  3021. result.type = "comment";
  3022. } else if ((object = sheet.tables.find(row, column))) {
  3023. result.type = "table";
  3024. }
  3025. result.object = object;
  3026. return result;
  3027. }
  3028. var specialTabNames = ["table", "picture", "comment", "sparklineEx", "slicer"];
  3029. var specialTabRefs = specialTabNames.map(function (name) {
  3030. return "#" + name + "Tab";
  3031. });
  3032. function isSpecialTabSelected() {
  3033. var href = $(".insp-container ul.nav-tabs li.active a").attr("href");
  3034. return specialTabRefs.indexOf(href) !== -1;
  3035. }
  3036. function getTabItem(tabName) {
  3037. return $(".insp-container ul.nav-tabs a[href='#" + tabName + "Tab']").parent();
  3038. }
  3039. function setActiveTab(tabName) {
  3040. // show / hide tabs
  3041. var $target = getTabItem(tabName),
  3042. $spreadTab = getTabItem("spread");
  3043. if (specialTabNames.indexOf(tabName) >= 0) {
  3044. if ($target.hasClass("hidden")) {
  3045. hideSpecialTabs(false);
  3046. $target.removeClass("hidden");
  3047. $spreadTab.addClass("hidden");
  3048. $("a", $target).tab("show");
  3049. }
  3050. } else {
  3051. if ($spreadTab.hasClass("hidden")) {
  3052. $spreadTab.removeClass("hidden");
  3053. hideSpecialTabs(true);
  3054. }
  3055. if (!$target.hasClass("active")) {
  3056. // do not switch from Data to Cell tab
  3057. if (!(tabName === "cell" && getTabItem("data").hasClass("active"))) {
  3058. $("a", $target).tab("show");
  3059. }
  3060. }
  3061. }
  3062. }
  3063. function hideSpecialTabs(clearCache) {
  3064. specialTabNames.forEach(function (name) {
  3065. getTabItem(name).addClass("hidden");
  3066. });
  3067. if (clearCache) {
  3068. clearCachedItems();
  3069. }
  3070. }
  3071. function getActualRange(range, maxRowCount, maxColCount) {
  3072. var row = range.row < 0 ? 0 : range.row;
  3073. var col = range.col < 0 ? 0 : range.col;
  3074. var rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount;
  3075. var colCount = range.colCount < 0 ? maxColCount : range.colCount;
  3076. return new spreadNS.Range(row, col, rowCount, colCount);
  3077. }
  3078. function getActualCellRange(sheet, cellRange, rowCount, columnCount) {
  3079. if (cellRange.row === -1 && cellRange.col === -1) {
  3080. return new spreadNS.CellRange(sheet, 0, 0, rowCount, columnCount);
  3081. }
  3082. else if (cellRange.row === -1) {
  3083. return new spreadNS.CellRange(sheet, 0, cellRange.col, rowCount, cellRange.colCount);
  3084. }
  3085. else if (cellRange.col === -1) {
  3086. return new spreadNS.CellRange(sheet, cellRange.row, 0, cellRange.rowCount, columnCount);
  3087. }
  3088. return new spreadNS.CellRange(sheet, cellRange.row, cellRange.col, cellRange.rowCount, cellRange.colCount);
  3089. }
  3090. function setStyleFont(sheet, prop, isLabelStyle, optionValue1, optionValue2) {
  3091. var styleEle = document.getElementById("setfontstyle"),
  3092. selections = sheet.getSelections(),
  3093. rowCount = sheet.getRowCount(),
  3094. columnCount = sheet.getColumnCount(),
  3095. defaultStyle = sheet.getDefaultStyle();
  3096. function updateStyleFont(style) {
  3097. if (!style.font) {
  3098. style.font = defaultStyle.font || "11pt Calibri";
  3099. }
  3100. styleEle.style.font = style.font;
  3101. var styleFont = $(styleEle).css(prop);
  3102. if (styleFont === optionValue1[0] || styleFont === optionValue1[1]) {
  3103. if (defaultStyle.font) {
  3104. styleEle.style.font = defaultStyle.font;
  3105. var defaultFontProp = $(styleEle).css(prop);
  3106. styleEle.style.font = style.font;
  3107. $(styleEle).css(prop, defaultFontProp);
  3108. }
  3109. else {
  3110. $(styleEle).css(prop, optionValue2);
  3111. }
  3112. } else {
  3113. $(styleEle).css(prop, optionValue1[0]);
  3114. }
  3115. style.font = styleEle.style.font;
  3116. }
  3117. sheet.suspendPaint();
  3118. for (var n = 0; n < selections.length; n++) {
  3119. var sel = getActualCellRange(sheet, selections[n], rowCount, columnCount);
  3120. for (var r = sel.row; r < sel.row + sel.rowCount; r++) {
  3121. for (var c = sel.col; c < sel.col + sel.colCount; c++) {
  3122. var style = sheet.getStyle(r, c);
  3123. if (!style) {
  3124. style = new spreadNS.Style();
  3125. }
  3126. // reset themeFont to make sure font be used
  3127. style.themeFont = undefined;
  3128. if (isLabelStyle) {
  3129. if (!style.labelOptions) {
  3130. style.labelOptions = {};
  3131. }
  3132. updateStyleFont(style.labelOptions);
  3133. } else {
  3134. updateStyleFont(style)
  3135. }
  3136. sheet.setStyle(r, c, style);
  3137. }
  3138. }
  3139. }
  3140. sheet.resumePaint();
  3141. }
  3142. function attachEvents() {
  3143. attachToolbarItemEvents();
  3144. attachSpreadEvents();
  3145. attachConditionalFormatEvents();
  3146. attachDataValidationEvents();
  3147. attachOtherEvents();
  3148. attachCellTypeEvents();
  3149. attachLockCellsEvent();
  3150. attachBorderTypeClickEvents();
  3151. attachSparklineSettingEvents();
  3152. }
  3153. // Border Type related items
  3154. function syncDisabledBorderType() {
  3155. var sheet = spread.getActiveSheet();
  3156. var selections = sheet.getSelections(), selectionsLength = selections.length;
  3157. var isDisabledInsideBorder = true;
  3158. var isDisabledHorizontalBorder = true;
  3159. var isDisabledVerticalBorder = true;
  3160. for (var i = 0; i < selectionsLength; i++) {
  3161. var selection = selections[i];
  3162. var col = selection.col, row = selection.row,
  3163. rowCount = selection.rowCount, colCount = selection.colCount;
  3164. if (isDisabledHorizontalBorder) {
  3165. isDisabledHorizontalBorder = rowCount === 1;
  3166. }
  3167. if (isDisabledVerticalBorder) {
  3168. isDisabledVerticalBorder = colCount === 1;
  3169. }
  3170. if (isDisabledInsideBorder) {
  3171. isDisabledInsideBorder = rowCount === 1 || colCount === 1;
  3172. }
  3173. }
  3174. [isDisabledInsideBorder, isDisabledVerticalBorder, isDisabledHorizontalBorder].forEach(function (value, index) {
  3175. var $item = $("div.group-item:eq(" + (index * 3 + 1) + ")");
  3176. if (value) {
  3177. $item.addClass("disable");
  3178. } else {
  3179. $item.removeClass("disable");
  3180. }
  3181. });
  3182. }
  3183. function getBorderSettings(borderType, borderStyle) {
  3184. var result = [];
  3185. switch (borderType) {
  3186. case "outside":
  3187. result.push({lineStyle: borderStyle, options: {outline: true}});
  3188. break;
  3189. case "inside":
  3190. result.push({lineStyle: borderStyle, options: {innerHorizontal: true}});
  3191. result.push({lineStyle: borderStyle, options: {innerVertical: true}});
  3192. break;
  3193. case "all":
  3194. case "none":
  3195. result.push({lineStyle: borderStyle, options: {all: true}});
  3196. break;
  3197. case "left":
  3198. result.push({lineStyle: borderStyle, options: {left: true}});
  3199. break;
  3200. case "innerVertical":
  3201. result.push({lineStyle: borderStyle, options: {innerVertical: true}});
  3202. break;
  3203. case "right":
  3204. result.push({lineStyle: borderStyle, options: {right: true}});
  3205. break;
  3206. case "top":
  3207. result.push({lineStyle: borderStyle, options: {top: true}});
  3208. break;
  3209. case "innerHorizontal":
  3210. result.push({lineStyle: borderStyle, options: {innerHorizontal: true}});
  3211. break;
  3212. case "bottom":
  3213. result.push({lineStyle: borderStyle, options: {bottom: true}});
  3214. break;
  3215. }
  3216. return result;
  3217. }
  3218. function setBorderlines(sheet, borderType, borderStyle, borderColor) {
  3219. function setSheetBorder(setting) {
  3220. var lineBorder = new spreadNS.LineBorder(borderColor, setting.lineStyle);
  3221. sel.setBorder(lineBorder, setting.options);
  3222. setRangeBorder(sheet, sel, setting.options);
  3223. }
  3224. var settings = getBorderSettings(borderType, borderStyle);
  3225. var rowCount = sheet.getRowCount(),
  3226. columnCount = sheet.getColumnCount();
  3227. sheet.suspendPaint();
  3228. var sels = sheet.getSelections();
  3229. for (var n = 0; n < sels.length; n++) {
  3230. var sel = getActualCellRange(sheet, sels[n], rowCount, columnCount);
  3231. settings.forEach(setSheetBorder);
  3232. }
  3233. sheet.resumePaint();
  3234. }
  3235. function attachBorderTypeClickEvents() {
  3236. var $groupItems = $(".group-item>div");
  3237. $groupItems.bind("mousedown", function () {
  3238. if ($(this).parent().hasClass("disable")) {
  3239. return;
  3240. }
  3241. var name = $(this).data("name").split("Border")[0];
  3242. applyBorderSetting(name);
  3243. });
  3244. }
  3245. function applyBorderSetting(name) {
  3246. var sheet = spread.getActiveSheet();
  3247. var borderLine = getBorderLineType($("#border-line-type").attr("class"));
  3248. var borderColor = getBackgroundColor("borderColor");
  3249. setBorderlines(sheet, name, borderLine, borderColor);
  3250. }
  3251. function getBorderLineType(className) {
  3252. switch (className) {
  3253. case "no-border":
  3254. return spreadNS.LineStyle.empty;
  3255. case "line-style-hair":
  3256. return spreadNS.LineStyle.hair;
  3257. case "line-style-dotted":
  3258. return spreadNS.LineStyle.dotted;
  3259. case "line-style-dash-dot-dot":
  3260. return spreadNS.LineStyle.dashDotDot;
  3261. case "line-style-dash-dot":
  3262. return spreadNS.LineStyle.dashDot;
  3263. case "line-style-dashed":
  3264. return spreadNS.LineStyle.dashed;
  3265. case "line-style-thin":
  3266. return spreadNS.LineStyle.thin;
  3267. case "line-style-medium-dash-dot-dot":
  3268. return spreadNS.LineStyle.mediumDashDotDot;
  3269. case "line-style-slanted-dash-dot":
  3270. return spreadNS.LineStyle.slantedDashDot;
  3271. case "line-style-medium-dash-dot":
  3272. return spreadNS.LineStyle.mediumDashDot;
  3273. case "line-style-medium-dashed":
  3274. return spreadNS.LineStyle.mediumDashed;
  3275. case "line-style-medium":
  3276. return spreadNS.LineStyle.medium;
  3277. case "line-style-thick":
  3278. return spreadNS.LineStyle.thick;
  3279. case "line-style-double":
  3280. return spreadNS.LineStyle.double;
  3281. }
  3282. }
  3283. function processBorderLineSetting(name) {
  3284. var $borderLineType = $('#border-line-type');
  3285. $borderLineType.text("");
  3286. $borderLineType.removeClass();
  3287. switch (name) {
  3288. case "none":
  3289. $('#border-line-type').text(getResource("cellTab.border.noBorder"));
  3290. $('#border-line-type').addClass("no-border");
  3291. return;
  3292. case "hair":
  3293. $('#border-line-type').addClass("line-style-hair");
  3294. break;
  3295. case "dotted":
  3296. $('#border-line-type').addClass("line-style-dotted");
  3297. break;
  3298. case "dash-dot-dot":
  3299. $('#border-line-type').addClass("line-style-dash-dot-dot");
  3300. break;
  3301. case "dash-dot":
  3302. $('#border-line-type').addClass("line-style-dash-dot");
  3303. break;
  3304. case "dashed":
  3305. $('#border-line-type').addClass("line-style-dashed");
  3306. break;
  3307. case "thin":
  3308. $('#border-line-type').addClass("line-style-thin");
  3309. break;
  3310. case "medium-dash-dot-dot":
  3311. $('#border-line-type').addClass("line-style-medium-dash-dot-dot");
  3312. break;
  3313. case "slanted-dash-dot":
  3314. $('#border-line-type').addClass("line-style-slanted-dash-dot");
  3315. break;
  3316. case "medium-dash-dot":
  3317. $('#border-line-type').addClass("line-style-medium-dash-dot");
  3318. break;
  3319. case "medium-dashed":
  3320. $('#border-line-type').addClass("line-style-medium-dashed");
  3321. break;
  3322. case "medium":
  3323. $('#border-line-type').addClass("line-style-medium");
  3324. break;
  3325. case "thick":
  3326. $('#border-line-type').addClass("line-style-thick");
  3327. break;
  3328. case "double":
  3329. $('#border-line-type').addClass("line-style-double");
  3330. break;
  3331. default:
  3332. console.log("processBorderLineSetting not add for ", name);
  3333. break;
  3334. }
  3335. }
  3336. function setRangeBorder(sheet, range, options) {
  3337. var outline = options.all || options.outline,
  3338. rowCount = sheet.getRowCount(),
  3339. columnCount = sheet.getColumnCount(),
  3340. startRow = range.row, endRow = startRow + range.rowCount - 1,
  3341. startCol = range.col, endCol = startCol + range.colCount - 1;
  3342. // update related borders for all cells arround the range
  3343. // left side
  3344. if ((startCol > 0) && (outline || options.left)) {
  3345. sheet.getRange(startRow, startCol - 1, range.rowCount, 1).borderRight(undefined);
  3346. }
  3347. // top side
  3348. if ((startRow > 0) && (outline || options.top)) {
  3349. sheet.getRange(startRow - 1, startCol, 1, range.colCount).borderBottom(undefined);
  3350. }
  3351. // right side
  3352. if ((endCol < columnCount - 1) && (outline || options.right)) {
  3353. sheet.getRange(startRow, endCol + 1, range.rowCount, 1).borderLeft(undefined);
  3354. }
  3355. // bottom side
  3356. if ((endRow < rowCount - 1) && (outline || options.bottom)) {
  3357. sheet.getRange(endRow + 1, startCol, 1, range.colCount).borderTop(undefined);
  3358. }
  3359. }
  3360. // Border Type related items (end)
  3361. function attachOtherEvents() {
  3362. $("div.table-format-item").click(changeTableStyle);
  3363. $("div.slicer-format-item").click(changeSlicerStyle);
  3364. $("#spreadContextMenu a").click(processContextMenuClicked);
  3365. $("#fileSelector").change(processFileSelected);
  3366. $("#sparklineextypes button").click(processAddSparklineEx);
  3367. }
  3368. function processFileSelected() {
  3369. var file = this.files[0],
  3370. action = $(this).data("action");
  3371. if (!file) return false;
  3372. // clear to make sure change event occures even when same file selected again
  3373. $("#fileSelector").val("");
  3374. if (action === "doImport") {
  3375. return importFile(file);
  3376. }
  3377. if (!/image\/\w+/.test(file.type)) {
  3378. alert(getResource("messages.imageFileRequired"));
  3379. return false;
  3380. }
  3381. var reader = new FileReader();
  3382. reader.onload = function () {
  3383. switch (action) {
  3384. case "addpicture":
  3385. addPicture(this.result);
  3386. break;
  3387. }
  3388. };
  3389. reader.readAsDataURL(file);
  3390. }
  3391. var PICTURE_ROWCOUNT = 16, PICTURE_COLUMNCOUNT = 10;
  3392. function addPicture(pictureUrl) {
  3393. var sheet = spread.getActiveSheet();
  3394. var defaults = sheet.defaults, rowHeight = defaults.rowHeight, colWidth = defaults.colWidth;
  3395. var sel = sheet.getSelections()[0];
  3396. if (pictureUrl !== "" && sel) {
  3397. sheet.suspendPaint();
  3398. var cr = getActualRange(sel, sheet.getRowCount(), sheet.getColumnCount());
  3399. var name = "Picture" + pictureIndex;
  3400. pictureIndex++;
  3401. // prepare and adjust the range for add picture
  3402. var row = cr.row, col = cr.col,
  3403. endRow = row + PICTURE_ROWCOUNT,
  3404. endColumn = col + PICTURE_COLUMNCOUNT,
  3405. rowCount = sheet.getRowCount(),
  3406. columnCount = sheet.getColumnCount();
  3407. if (endRow > rowCount) {
  3408. endRow = rowCount - 1;
  3409. row = endRow - PICTURE_ROWCOUNT;
  3410. }
  3411. if (endColumn > columnCount) {
  3412. endColumn = columnCount - 1;
  3413. col = endColumn - PICTURE_COLUMNCOUNT;
  3414. }
  3415. var picture = sheet.pictures.add(name, pictureUrl, col * colWidth, row * rowHeight, (endColumn - col) * colWidth, (endRow - row) * rowHeight)
  3416. .backColor("#FFFFFF").borderColor("#000000")
  3417. .borderStyle("solid").borderWidth(1).borderRadius(3);
  3418. sheet.resumePaint();
  3419. spread.focus();
  3420. picture.isSelected(true);
  3421. }
  3422. }
  3423. function updatePositionBox(sheet) {
  3424. var selection = sheet.getSelections().slice(-1)[0];
  3425. if (selection) {
  3426. var position;
  3427. if (!isShiftKey) {
  3428. position = getCellPositionString(sheet,
  3429. sheet.getActiveRowIndex() + 1,
  3430. sheet.getActiveColumnIndex() + 1, selection);
  3431. }
  3432. else {
  3433. position = getSelectedRangeString(sheet, selection);
  3434. }
  3435. $("#positionbox").val(position);
  3436. }
  3437. }
  3438. function syncCellRelatedItems() {
  3439. updateMergeButtonsState();
  3440. syncDisabledLockCells();
  3441. syncDisabledBorderType();
  3442. // reset conditional format setting
  3443. var item = setDropDownValueByIndex($("#conditionalFormatType"), -1);
  3444. processConditionalFormatDetailSetting(item.value, true);
  3445. // sync cell type related information
  3446. syncCellTypeInfo();
  3447. }
  3448. function syncCellTypeInfo() {
  3449. function updateButtonCellTypeInfo(cellType) {
  3450. setNumberValue("buttonCellTypeMarginTop", cellType.marginTop());
  3451. setNumberValue("buttonCellTypeMarginRight", cellType.marginRight());
  3452. setNumberValue("buttonCellTypeMarginBottom", cellType.marginBottom());
  3453. setNumberValue("buttonCellTypeMarginLeft", cellType.marginLeft());
  3454. setTextValue("buttonCellTypeText", cellType.text());
  3455. setColorValue("buttonCellTypeBackColor", cellType.buttonBackColor());
  3456. }
  3457. function updateCheckBoxCellTypeInfo(cellType) {
  3458. setTextValue("checkboxCellTypeCaption", cellType.caption());
  3459. setTextValue("checkboxCellTypeTextTrue", cellType.textTrue());
  3460. setTextValue("checkboxCellTypeTextIndeterminate", cellType.textIndeterminate());
  3461. setTextValue("checkboxCellTypeTextFalse", cellType.textFalse());
  3462. setDropDownValue("checkboxCellTypeTextAlign", cellType.textAlign());
  3463. setCheckValue("checkboxCellTypeIsThreeState", cellType.isThreeState());
  3464. }
  3465. function updateComboBoxCellTypeInfo(cellType) {
  3466. setDropDownValue("comboboxCellTypeEditorValueType", cellType.editorValueType());
  3467. var items = cellType.items(),
  3468. texts = items.map(function (item) {
  3469. return item.text || item;
  3470. }).join(","),
  3471. values = items.map(function (item) {
  3472. return item.value || item;
  3473. }).join(",");
  3474. setTextValue("comboboxCellTypeItemsText", texts);
  3475. setTextValue("comboboxCellTypeItemsValue", values);
  3476. }
  3477. function updateHyperLinkCellTypeInfo(cellType) {
  3478. setColorValue("hyperlinkCellTypeLinkColor", cellType.linkColor());
  3479. setColorValue("hyperlinkCellTypeVisitedLinkColor", cellType.visitedLinkColor());
  3480. setTextValue("hyperlinkCellTypeText", cellType.text());
  3481. setTextValue("hyperlinkCellTypeLinkToolTip", cellType.linkToolTip());
  3482. }
  3483. var sheet = spread.getActiveSheet(),
  3484. index,
  3485. cellType = sheet.getCell(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()).cellType();
  3486. if (cellType instanceof spreadNS.CellTypes.Button) {
  3487. index = 0;
  3488. updateButtonCellTypeInfo(cellType);
  3489. } else if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  3490. index = 1;
  3491. updateCheckBoxCellTypeInfo(cellType);
  3492. } else if (cellType instanceof spreadNS.CellTypes.ComboBox) {
  3493. index = 2;
  3494. updateComboBoxCellTypeInfo(cellType);
  3495. } else if (cellType instanceof spreadNS.CellTypes.HyperLink) {
  3496. index = 3;
  3497. updateHyperLinkCellTypeInfo(cellType);
  3498. } else {
  3499. index = -1;
  3500. }
  3501. var cellTypeItem = setDropDownValueByIndex($("#cellTypes"), index);
  3502. processCellTypeSetting(cellTypeItem.value, true);
  3503. if (index >= 0) {
  3504. var $group = $("#groupCellType");
  3505. if ($group.find(".group-state").hasClass("fa-caret-right")) {
  3506. $group.click();
  3507. }
  3508. }
  3509. }
  3510. function onCellSelected() {
  3511. $("#addslicer").addClass("hidden");
  3512. var sheet = spread.getActiveSheet(),
  3513. row = sheet.getActiveRowIndex(),
  3514. column = sheet.getActiveColumnIndex();
  3515. if (showSparklineSetting(row, column)) {
  3516. setActiveTab("sparklineEx");
  3517. return;
  3518. }
  3519. var cellInfo = getCellInfo(sheet, row, column),
  3520. cellType = cellInfo.type;
  3521. syncCellRelatedItems();
  3522. updatePositionBox(sheet);
  3523. updateCellStyleState(sheet, row, column);
  3524. var tabType = "cell";
  3525. clearCachedItems();
  3526. // add map from cell type to tab type here
  3527. if (cellType === "table") {
  3528. tabType = "table";
  3529. syncTablePropertyValues(sheet, cellInfo.object);
  3530. $("#addslicer").removeClass("hidden");
  3531. } else if (cellType === "comment") {
  3532. tabType = "comment";
  3533. syncCommentPropertyValues(sheet, cellInfo.object);
  3534. }
  3535. setActiveTab(tabType);
  3536. }
  3537. var _activeComment;
  3538. function syncCommentPropertyValues(sheet, comment) {
  3539. _activeComment = comment;
  3540. // General
  3541. setCheckValue("commentDynamicSize", comment.dynamicSize());
  3542. setCheckValue("commentDynamicMove", comment.dynamicMove());
  3543. setCheckValue("commentLockText", comment.lockText());
  3544. setCheckValue("commentShowShadow", comment.showShadow());
  3545. // Font
  3546. setDropDownText($("#commentTab div.insp-dropdown-list[data-name='commentFontFamily']"), comment.fontFamily());
  3547. setDropDownText($("#commentTab div.insp-dropdown-list[data-name='commentFontSize']"), parseFloat(comment.fontSize()));
  3548. setDropDownText($("#commentTab div.insp-dropdown-list[data-name='commentFontStyle']"), comment.fontStyle());
  3549. setDropDownText($("#commentTab div.insp-dropdown-list[data-name='commentFontWeight']"), comment.fontWeight());
  3550. var textDecoration = comment.textDecoration();
  3551. var TextDecorationType = spreadNS.TextDecorationType;
  3552. setFontStyleButtonActive("comment-underline", (textDecoration & TextDecorationType.underline) === TextDecorationType.underline);
  3553. setFontStyleButtonActive("comment-overline", (textDecoration & TextDecorationType.overline) === TextDecorationType.overline);
  3554. setFontStyleButtonActive("comment-strikethrough", (textDecoration & TextDecorationType.lineThrough) === TextDecorationType.lineThrough);
  3555. // Border
  3556. setNumberValue("commentBorderWidth", comment.borderWidth());
  3557. setDropDownText($("#commentTab div.insp-dropdown-list[data-name='commentBorderStyle']"), comment.borderStyle());
  3558. setColorValue("commentBorderColor", comment.borderColor());
  3559. // Appearance
  3560. setDropDownValue($("#commentTab div.insp-dropdown-list[data-name='commentHorizontalAlign']"), comment.horizontalAlign());
  3561. setDropDownValue($("#commentTab div.insp-dropdown-list[data-name='commentDisplayMode']"), comment.displayMode());
  3562. setColorValue("commentForeColor", comment.foreColor());
  3563. setColorValue("commentBackColor", comment.backColor());
  3564. setTextValue("commentPadding", getPaddingString(comment.padding()));
  3565. setNumberValue("commentOpacity", comment.opacity() * 100);
  3566. }
  3567. function getPaddingString(padding) {
  3568. if (!padding) return "";
  3569. return [padding.top, padding.right, padding.bottom, padding.left].join(", ");
  3570. }
  3571. function clearCachedItems() {
  3572. _activePicture = null;
  3573. _activeComment = null;
  3574. _activeTable = null;
  3575. }
  3576. var _activeTable;
  3577. function syncTablePropertyValues(sheet, table) {
  3578. _activeTable = table;
  3579. setCheckValue("tableFilterButton", table.filterButtonVisible());
  3580. setCheckValue("tableHeaderRow", table.showHeader());
  3581. setCheckValue("tableTotalRow", table.showFooter());
  3582. setCheckValue("tableFirstColumn", table.highlightFirstColumn());
  3583. setCheckValue("tableLastColumn", table.highlightLastColumn());
  3584. setCheckValue("tableBandedRows", table.bandRows());
  3585. setCheckValue("tableBandedColumns", table.bandColumns());
  3586. var tableStyle = table.style(),
  3587. styleName = tableStyle && table.style().name();
  3588. $("#tableStyles .table-format-item").removeClass("table-format-item-selected");
  3589. if (styleName) {
  3590. $("#tableStyles .table-format-item div[data-name='" + styleName.toLowerCase() + "']").parent().addClass("table-format-item-selected");
  3591. }
  3592. setTextValue("tableName", table.name());
  3593. }
  3594. function changeTableStyle() {
  3595. if (_activeTable) {
  3596. spread.suspendPaint();
  3597. var styleName = $(">div", this).data("name");
  3598. _activeTable.style(spreadNS.Tables.TableThemes[styleName]);
  3599. $("#tableStyles .table-format-item").removeClass("table-format-item-selected");
  3600. $(this).addClass("table-format-item-selected");
  3601. spread.resumePaint();
  3602. }
  3603. }
  3604. var _activePicture;
  3605. function syncPicturePropertyValues(sheet, picture) {
  3606. _activePicture = picture;
  3607. // General
  3608. if (picture.dynamicMove()) {
  3609. if (picture.dynamicSize()) {
  3610. setRadioItemChecked("pictureMoveAndSize", "picture-move-size");
  3611. }
  3612. else {
  3613. setRadioItemChecked("pictureMoveAndSize", "picture-move-nosize");
  3614. }
  3615. }
  3616. else {
  3617. setRadioItemChecked("pictureMoveAndSize", "picture-nomove-size");
  3618. }
  3619. setCheckValue("pictureFixedPosition", picture.fixedPosition());
  3620. // Border
  3621. setNumberValue("pictureBorderWidth", picture.borderWidth());
  3622. setNumberValue("pictureBorderRadius", picture.borderRadius());
  3623. setDropDownText($("#pictureTab div.insp-dropdown-list[data-name='pictureBorderStyle']"), picture.borderStyle());
  3624. setColorValue("pictureBorderColor", picture.borderColor());
  3625. // Appearance
  3626. setDropDownValue($("#pictureTab div.insp-dropdown-list[data-name='pictureStretch']"), picture.pictureStretch());
  3627. setColorValue("pictureBackColor", picture.backColor());
  3628. $("#positionbox").val(picture.name());
  3629. }
  3630. var _floatInspector = false;
  3631. function adjustInspectorDisplay() {
  3632. var $inspectorContainer = $(".insp-container"),
  3633. $contentContainer = $("#inner-content-container"),
  3634. toggleInspectorClasses;
  3635. if (_floatInspector) {
  3636. $inspectorContainer.draggable("enable");
  3637. $inspectorContainer.addClass("float-inspector");
  3638. $contentContainer.addClass("float-inspector");
  3639. toggleInspectorClasses = ["fa-angle-down", "fa-angle-up"];
  3640. $("#inner-content-container").css({right: 0});
  3641. } else {
  3642. $inspectorContainer.draggable("disable");
  3643. $inspectorContainer.removeClass("float-inspector");
  3644. $inspectorContainer.css({left: "auto", top: 0});
  3645. $contentContainer.removeClass("float-inspector");
  3646. toggleInspectorClasses = ["fa-angle-left", "fa-angle-right"];
  3647. }
  3648. // update toggleInspector
  3649. var classIndex = ($(".insp-container:visible").length > 0) ? 1 : 0;
  3650. $("#toggleInspector > span")
  3651. .removeClass("fa-angle-left fa-angle-right fa-angle-up fa-angle-down")
  3652. .addClass(toggleInspectorClasses[classIndex]);
  3653. }
  3654. function processMediaQueryResponse(mql) {
  3655. if (mql.matches) {
  3656. if (!_floatInspector) {
  3657. _floatInspector = true;
  3658. adjustInspectorDisplay();
  3659. }
  3660. } else {
  3661. if (_floatInspector) {
  3662. _floatInspector = false;
  3663. adjustInspectorDisplay();
  3664. }
  3665. }
  3666. }
  3667. function checkMediaSize() {
  3668. var mql = window.matchMedia("screen and (max-width: 768px)");
  3669. processMediaQueryResponse(mql);
  3670. adjustInspectorDisplay();
  3671. mql.addListener(processMediaQueryResponse);
  3672. }
  3673. function toggleInspector() {
  3674. if ($(".insp-container:visible").length > 0) {
  3675. $(".insp-container").hide();
  3676. if (!_floatInspector) {
  3677. $("#inner-content-container").css({right: 0});
  3678. $("span", this).removeClass("fa-angle-right fa-angle-up fa-angle-down").addClass("fa-angle-left");
  3679. } else {
  3680. $("#inner-content-container").css({right: 0});
  3681. $("span", this).removeClass("fa-angle-right fa-angle-left fa-angle-up").addClass("fa-angle-down");
  3682. }
  3683. $(this).attr("title", uiResource.toolBar.showInspector);
  3684. } else {
  3685. $(".insp-container").show();
  3686. if (!_floatInspector) {
  3687. $("#inner-content-container").css({right: "301px"});
  3688. $("span", this).removeClass("fa-angle-left fa-angle-up fa-angle-down").addClass("fa-angle-right");
  3689. } else {
  3690. $("#inner-content-container").css({right: 0});
  3691. $("span", this).removeClass("fa-angle-right fa-angle-left fa-angle-down").addClass("fa-angle-up");
  3692. }
  3693. $(this).attr("title", uiResource.toolBar.hideInspector);
  3694. }
  3695. spread.refresh();
  3696. }
  3697. function attachToolbarItemEvents() {
  3698. $("#addtable").click(function () {
  3699. var sheet = spread.getActiveSheet(),
  3700. row = sheet.getActiveRowIndex(),
  3701. column = sheet.getActiveColumnIndex(),
  3702. name = "Table" + tableIndex,
  3703. rowCount = 1,
  3704. colCount = 1;
  3705. tableIndex++;
  3706. var selections = sheet.getSelections();
  3707. if (selections.length > 0) {
  3708. var range = selections[0],
  3709. r = range.row,
  3710. c = range.col;
  3711. rowCount = range.rowCount,
  3712. colCount = range.colCount;
  3713. // update row / column for whole column / row was selected
  3714. if (r >= 0) {
  3715. row = r;
  3716. }
  3717. if (c >= 0) {
  3718. column = c;
  3719. }
  3720. }
  3721. sheet.suspendPaint();
  3722. try {
  3723. // handle exception if the specified range intersect with other table etc.
  3724. sheet.tables.add(name, row, column, rowCount, colCount, spreadNS.Tables.TableThemes.light2);
  3725. } catch (e) {
  3726. alert(e.message);
  3727. }
  3728. sheet.resumePaint();
  3729. spread.focus();
  3730. onCellSelected();
  3731. });
  3732. $("#addcomment").click(function () {
  3733. var sheet = spread.getActiveSheet(),
  3734. row = sheet.getActiveRowIndex(),
  3735. column = sheet.getActiveColumnIndex(),
  3736. comment;
  3737. sheet.suspendPaint();
  3738. comment = sheet.comments.add(row, column, new Date().toLocaleString());
  3739. sheet.resumePaint();
  3740. comment.commentState(spreadNS.Comments.CommentState.edit);
  3741. });
  3742. $("#addpicture, #doImport").click(function () {
  3743. $("#fileSelector").data("action", this.id);
  3744. $("#fileSelector").click();
  3745. });
  3746. $("#toggleInspector").click(toggleInspector);
  3747. $("#doClear").click(function () {
  3748. var $dropdown = $("#clearActionList"),
  3749. $this = $(this),
  3750. offset = $this.offset();
  3751. $dropdown.css({left: offset.left, top: offset.top + $this.outerHeight()});
  3752. $dropdown.show();
  3753. processEventListenerHandleClosePopup(true);
  3754. });
  3755. $("#doExport").click(function () {
  3756. var $dropdown = $("#exportActionList"),
  3757. $this = $(this),
  3758. offset = $this.offset();
  3759. $dropdown.css({left: offset.left, top: offset.top + $this.outerHeight()});
  3760. $dropdown.show();
  3761. processEventListenerHandleClosePopup(true);
  3762. });
  3763. $("#addslicer").click(processAddSlicer);
  3764. }
  3765. // Protect Sheet related items
  3766. function getCurrentSheetProtectionOption(sheet) {
  3767. var options = sheet.options.protectionOptions;
  3768. if (options.allowSelectLockedCells || options.allowSelectLockedCells === undefined) {
  3769. setCheckValue("checkboxSelectLockedCells", true);
  3770. }
  3771. else {
  3772. setCheckValue("checkboxSelectLockedCells", false);
  3773. }
  3774. if (options.allowSelectUnlockedCells || options.allowSelectUnlockedCells === undefined) {
  3775. setCheckValue("checkboxSelectUnlockedCells", true);
  3776. }
  3777. else {
  3778. setCheckValue("checkboxSelectUnlockedCells", false);
  3779. }
  3780. if (options.allowSort) {
  3781. setCheckValue("checkboxSort", true);
  3782. }
  3783. else {
  3784. setCheckValue("checkboxSort", false);
  3785. }
  3786. if (options.allowFilter) {
  3787. setCheckValue("checkboxUseAutoFilter", true);
  3788. }
  3789. else {
  3790. setCheckValue("checkboxUseAutoFilter", false);
  3791. }
  3792. if (options.allowResizeRows) {
  3793. setCheckValue("checkboxResizeRows", true);
  3794. }
  3795. else {
  3796. setCheckValue("checkboxResizeRows", false);
  3797. }
  3798. if (options.allowResizeColumns) {
  3799. setCheckValue("checkboxResizeColumns", true);
  3800. }
  3801. else {
  3802. setCheckValue("checkboxResizeColumns", false);
  3803. }
  3804. if (options.allowEditObjects) {
  3805. setCheckValue("checkboxEditObjects", true);
  3806. }
  3807. else {
  3808. setCheckValue("checkboxEditObjects", false);
  3809. }
  3810. }
  3811. function setProtectionOption(sheet, optionItem, value) {
  3812. var options = sheet.options.protectionOptions;
  3813. switch (optionItem) {
  3814. case "allowSelectLockedCells":
  3815. options.allowSelectLockedCells = value;
  3816. break;
  3817. case "allowSelectUnlockedCells":
  3818. options.allowSelectUnlockedCells = value;
  3819. break;
  3820. case "allowSort":
  3821. options.allowSort = value;
  3822. break;
  3823. case "allowFilter":
  3824. options.allowFilter = value;
  3825. break;
  3826. case "allowResizeRows":
  3827. options.allowResizeRows = value;
  3828. break;
  3829. case "allowResizeColumns":
  3830. options.allowResizeColumns = value;
  3831. break;
  3832. case "allowEditObjects":
  3833. options.allowEditObjects = value;
  3834. break;
  3835. default:
  3836. console.log("There is no protection option:", optionItem);
  3837. break;
  3838. }
  3839. setActiveTab("sheet");
  3840. }
  3841. function syncSheetProtectionText(isProtected) {
  3842. var $protectSheetText = $("#protectSheetText");
  3843. if (isProtected) {
  3844. $protectSheetText.text(uiResource.cellTab.protection.sheetIsProtected);
  3845. }
  3846. else {
  3847. $protectSheetText.text(uiResource.cellTab.protection.sheetIsUnprotected);
  3848. }
  3849. }
  3850. function syncProtectSheetRelatedItems(sheet, value) {
  3851. sheet.options.isProtected = value;
  3852. syncSheetProtectionText(value);
  3853. if (isAllSelectedSlicersLocked(sheet)) {
  3854. setActiveTab("sheet");
  3855. }
  3856. }
  3857. function isAllSelectedSlicersLocked(sheet) {
  3858. var selectedSlicers = getSelectedSlicers(sheet);
  3859. if (!selectedSlicers || selectedSlicers.length === 0) {
  3860. return null;
  3861. }
  3862. var allLocked = true;
  3863. for (var item in selectedSlicers) {
  3864. allLocked = allLocked && selectedSlicers[item].isLocked();
  3865. if (!allLocked) {
  3866. break;
  3867. }
  3868. }
  3869. return allLocked;
  3870. }
  3871. // Protect Sheet related items (end)
  3872. // Lock Cell related items
  3873. function getCellsLockedState() {
  3874. var isLocked = false;
  3875. var sheet = spread.getActiveSheet();
  3876. var selections = sheet.getSelections(), selectionsLength = selections.length;
  3877. var cell;
  3878. var row, col, rowCount, colCount;
  3879. if (selectionsLength > 0) {
  3880. for (var i = 0; i < selectionsLength; i++) {
  3881. var range = selections[i];
  3882. row = range.row;
  3883. rowCount = range.rowCount;
  3884. colCount = range.colCount;
  3885. if (row < 0) {
  3886. row = 0;
  3887. }
  3888. for (row; row < range.row + rowCount; row++) {
  3889. col = range.col;
  3890. if (col < 0) {
  3891. col = 0;
  3892. }
  3893. for (col; col < range.col + colCount; col++) {
  3894. cell = sheet.getCell(row, col);
  3895. isLocked = isLocked || cell.locked();
  3896. if (isLocked) {
  3897. return isLocked;
  3898. }
  3899. }
  3900. }
  3901. }
  3902. return false;
  3903. } else {
  3904. return sheet.getCell(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()).locked();
  3905. }
  3906. }
  3907. function syncDisabledLockCells() {
  3908. var cellsLockedState = getCellsLockedState();
  3909. setCheckValue("checkboxLockCell", cellsLockedState);
  3910. }
  3911. function attachLockCellsEvent() {
  3912. $("#lockCells").click(function () {
  3913. var value = getCheckValue("checkboxLockCell");
  3914. setSelectedCellsLock(value);
  3915. });
  3916. }
  3917. function setSelectedCellsLock(value) {
  3918. var sheet = spread.getActiveSheet();
  3919. var selections = sheet.getSelections();
  3920. var row, col, rowCount, colCount;
  3921. for (var i = 0; i < selections.length; i++) {
  3922. var range = selections[i];
  3923. row = range.row;
  3924. col = range.col;
  3925. rowCount = range.rowCount;
  3926. colCount = range.colCount;
  3927. if (row < 0 && col < 0) {
  3928. sheet.getDefaultStyle().locked = value;
  3929. }
  3930. else if (row < 0) {
  3931. sheet.getRange(-1, col, -1, colCount).locked(value);
  3932. }
  3933. else if (col < 0) {
  3934. sheet.getRange(row, -1, rowCount, -1).locked(value);
  3935. }
  3936. else {
  3937. sheet.getRange(row, col, rowCount, colCount).locked(value);
  3938. }
  3939. }
  3940. }
  3941. // Lock Cell related items (end)
  3942. function attachSpreadEvents(rebind) {
  3943. spread.bind(spreadNS.Events.EnterCell, onCellSelected);
  3944. spread.bind(spreadNS.Events.ValueChanged, function (sender, args) {
  3945. var row = args.row, col = args.col, sheet = args.sheet;
  3946. if (sheet.getCell(row, col).wordWrap()) {
  3947. sheet.autoFitRow(row);
  3948. }
  3949. });
  3950. function shouldAutofitRow(sheet, row, col, colCount) {
  3951. for (var c = 0; c < colCount; c++) {
  3952. if (sheet.getCell(row, col++).wordWrap()) {
  3953. return true;
  3954. }
  3955. }
  3956. return false;
  3957. }
  3958. spread.bind(spreadNS.Events.RangeChanged, function (sender, args) {
  3959. var sheet = args.sheet, row = args.row, rowCount = args.rowCount;
  3960. if (args.action === spreadNS.RangeChangedAction.paste) {
  3961. var col = args.col, colCount = args.colCount;
  3962. for (var i = 0; i < rowCount; i++) {
  3963. if (shouldAutofitRow(sheet, row, col, colCount)) {
  3964. sheet.autoFitRow(row);
  3965. }
  3966. row++;
  3967. }
  3968. }
  3969. });
  3970. spread.bind(spreadNS.Events.ActiveSheetChanged, function () {
  3971. setActiveTab("sheet");
  3972. syncSheetPropertyValues();
  3973. syncCellRelatedItems();
  3974. hideSpreadContextMenu();
  3975. var sheet = spread.getActiveSheet(),
  3976. picture;
  3977. var slicers = sheet.slicers.all();
  3978. for (var item in slicers) {
  3979. slicers[item].isSelected(false);
  3980. }
  3981. if (sheet.getSelections().length === 0) {
  3982. sheet.pictures.all().forEach(function (pic) {
  3983. if (!picture && pic.isSelected()) {
  3984. picture = pic;
  3985. }
  3986. });
  3987. // fix bug, make sure selection was shown after unselect slicer
  3988. if (!picture) {
  3989. sheet.setSelection(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), 1, 1);
  3990. }
  3991. }
  3992. if (picture) {
  3993. syncPicturePropertyValues(sheet, picture);
  3994. setActiveTab("picture");
  3995. } else {
  3996. onCellSelected();
  3997. }
  3998. var value = $("div.button", $("div[data-name='allowOverflow']")).hasClass("checked");
  3999. if (sheet.options.allowCellOverflow !== value) {
  4000. sheet.options.allowCellOverflow = value;
  4001. }
  4002. });
  4003. spread.bind(spreadNS.Events.SelectionChanging, function () {
  4004. var sheet = spread.getActiveSheet();
  4005. var selection = sheet.getSelections().slice(-1)[0];
  4006. if (selection) {
  4007. var position = getSelectedRangeString(sheet, selection);
  4008. $("#positionbox").val(position);
  4009. }
  4010. syncDisabledBorderType();
  4011. });
  4012. spread.bind(spreadNS.Events.SelectionChanged, function () {
  4013. syncCellRelatedItems();
  4014. updatePositionBox(spread.getActiveSheet());
  4015. });
  4016. spread.bind(spreadNS.Events.PictureSelectionChanged, function (event, args) {
  4017. var sheet = args.sheet, picture = args.picture;
  4018. if (picture && picture.isSelected()) {
  4019. syncPicturePropertyValues(sheet, picture);
  4020. setActiveTab("picture");
  4021. }
  4022. });
  4023. spread.bind(spreadNS.Events.CommentChanged, function (event, args) {
  4024. var sheet = args.sheet, comment = args.comment, propertyName = args.propertyName;
  4025. if (propertyName === "commentState" && comment) {
  4026. if (comment.commentState() === spreadNS.Comments.CommentState.edit) {
  4027. syncCommentPropertyValues(sheet, comment);
  4028. setActiveTab("comment");
  4029. }
  4030. }
  4031. });
  4032. spread.bind(spreadNS.Events.ValidationError, function (event, data) {
  4033. var dv = data.validator;
  4034. if (dv) {
  4035. alert(dv.errorMessage() || dv.inputMessage());
  4036. }
  4037. });
  4038. spread.bind(spreadNS.Events.SlicerChanged, function (event, args) {
  4039. bindSlicerEvents(args.sheet, args.slicer, args.propertyName);
  4040. });
  4041. $(document).bind("keydown", function (event) {
  4042. if (event.shiftKey) {
  4043. isShiftKey = true;
  4044. }
  4045. });
  4046. $(document).bind("keyup", function (event) {
  4047. if (!event.shiftKey) {
  4048. isShiftKey = false;
  4049. var sheet = spread.getActiveSheet(),
  4050. position = getCellPositionString(sheet, sheet.getActiveRowIndex() + 1, sheet.getActiveColumnIndex() + 1);
  4051. $("#positionbox").val(position);
  4052. }
  4053. });
  4054. if (!rebind) {
  4055. $("#ss").bind("contextmenu", processSpreadContextMenu);
  4056. $("#ss").mouseup(function (e) {
  4057. // hide context menu when the mouse down on SpreadJS
  4058. if (e.button !== 2) {
  4059. hideSpreadContextMenu();
  4060. }
  4061. });
  4062. }
  4063. }
  4064. function setConditionalFormatSettingGroupVisible(groupName) {
  4065. var $groupItems = $("#conditionalFormatSettingContainer .settingGroup .groupitem");
  4066. $groupItems.hide();
  4067. $groupItems.filter("[data-group='" + groupName + "']").show();
  4068. }
  4069. function processConditionalFormatSetting(groupName, listRef, rule) {
  4070. $("#conditionalFormatSettingContainer div.details").show();
  4071. setConditionalFormatSettingGroupVisible(groupName);
  4072. var $ruleType = $("#highlightCellsRule"),
  4073. $setButton = $("#setConditionalFormat");
  4074. if (listRef) {
  4075. $ruleType.data("list-ref", listRef);
  4076. $setButton.data("rule-type", rule);
  4077. var item = setDropDownValueByIndex($ruleType, 0);
  4078. updateEnumTypeOfCF(item.value);
  4079. } else {
  4080. $setButton.data("rule-type", groupName);
  4081. }
  4082. }
  4083. function processConditionalFormatDetailSetting(name, noAction) {
  4084. switch (name) {
  4085. case "highlight-cells-rules":
  4086. $("#formatSetting").show();
  4087. processConditionalFormatSetting("normal", "highlightCellsRulesList", 0);
  4088. break;
  4089. case "top-bottom-rules":
  4090. $("#formatSetting").show();
  4091. processConditionalFormatSetting("normal", "topBottomRulesList", 4);
  4092. break;
  4093. case "color-scales":
  4094. $("#formatSetting").hide();
  4095. processConditionalFormatSetting("normal", "colorScaleList", 8);
  4096. break;
  4097. case "data-bars":
  4098. processConditionalFormatSetting("databar");
  4099. break;
  4100. case "icon-sets":
  4101. processConditionalFormatSetting("iconset");
  4102. updateIconCriteriaItems(0);
  4103. break;
  4104. case "remove-conditional-formats":
  4105. $("#conditionalFormatSettingContainer div.details").hide();
  4106. if (!noAction) {
  4107. removeConditionFormats();
  4108. }
  4109. break;
  4110. default:
  4111. console.log("processConditionalFormatSetting not add for ", name);
  4112. break;
  4113. }
  4114. }
  4115. function getBackgroundColor(name) {
  4116. return $("div.insp-color-picker[data-name='" + name + "'] div.color-view").css("background-color");
  4117. }
  4118. function addCondionalFormaterRule(rule) {
  4119. var sheet = spread.getActiveSheet();
  4120. var sels = sheet.getSelections();
  4121. var style = new spreadNS.Style();
  4122. if (getCheckValue("useFormatBackColor")) {
  4123. style.backColor = getBackgroundColor("formatBackColor");
  4124. }
  4125. if (getCheckValue("useFormatForeColor")) {
  4126. style.foreColor = getBackgroundColor("formatForeColor");
  4127. }
  4128. if (getCheckValue("useFormatBorder")) {
  4129. var lineBorder = new spreadNS.LineBorder(getBackgroundColor("formatBorderColor"), spreadNS.LineStyle.thin);
  4130. style.borderTop = style.borderRight = style.borderBottom = style.borderLeft = lineBorder;
  4131. }
  4132. var value1 = $("#value1").val();
  4133. var value2 = $("#value2").val();
  4134. var cfs = sheet.conditionalFormats;
  4135. var operator = +getDropDownValue("comparisonOperator");
  4136. var minType = +getDropDownValue("minType");
  4137. var midType = +getDropDownValue("midType");
  4138. var maxType = +getDropDownValue("maxType");
  4139. var midColor = getBackgroundColor("midColor");
  4140. var minColor = getBackgroundColor("minColor");
  4141. var maxColor = getBackgroundColor("maxColor");
  4142. var midValue = getNumberValue("midValue");
  4143. var maxValue = getNumberValue("maxValue");
  4144. var minValue = getNumberValue("minValue");
  4145. switch (rule) {
  4146. case "0":
  4147. var doubleValue1 = parseFloat(value1);
  4148. var doubleValue2 = parseFloat(value2);
  4149. cfs.addCellValueRule(operator, isNaN(doubleValue1) ? value1 : doubleValue1, isNaN(doubleValue2) ? value2 : doubleValue2, style, sels);
  4150. break;
  4151. case "1":
  4152. cfs.addSpecificTextRule(operator, value1, style, sels);
  4153. break;
  4154. case "2":
  4155. cfs.addDateOccurringRule(operator, style, sels);
  4156. break;
  4157. case "4":
  4158. cfs.addTop10Rule(operator, parseInt(value1, 10), style, sels);
  4159. break;
  4160. case "5":
  4161. cfs.addUniqueRule(style, sels);
  4162. break;
  4163. case "6":
  4164. cfs.addDuplicateRule(style, sels);
  4165. break;
  4166. case "7":
  4167. cfs.addAverageRule(operator, style, sels);
  4168. break;
  4169. case "8":
  4170. cfs.add2ScaleRule(minType, minValue, minColor, maxType, maxValue, maxColor, sels);
  4171. break;
  4172. case "9":
  4173. cfs.add3ScaleRule(minType, minValue, minColor, midType, midValue, midColor, maxType, maxValue, maxColor, sels);
  4174. break;
  4175. default:
  4176. var doubleValue1 = parseFloat(value1);
  4177. var doubleValue2 = parseFloat(value2);
  4178. cfs.addCellValueRule(operator, isNaN(doubleValue1) ? value1 : doubleValue1, isNaN(doubleValue2) ? value2 : doubleValue2, style, sels);
  4179. break;
  4180. }
  4181. sheet.repaint();
  4182. }
  4183. function addDataBarRule() {
  4184. var sheet = spread.getActiveSheet();
  4185. sheet.suspendPaint();
  4186. var selections = sheet.getSelections();
  4187. if (selections.length > 0) {
  4188. var ranges = [];
  4189. $.each(selections, function (i, v) {
  4190. ranges.push(new spreadNS.Range(v.row, v.col, v.rowCount, v.colCount));
  4191. });
  4192. var cfs = sheet.conditionalFormats;
  4193. var dataBarRule = new ConditionalFormatting.DataBarRule();
  4194. dataBarRule.ranges(ranges);
  4195. dataBarRule.minType(+getDropDownValue("minimumType"));
  4196. dataBarRule.minValue(getNumberValue("minimumValue"));
  4197. dataBarRule.maxType(+getDropDownValue("maximumType"));
  4198. dataBarRule.maxValue(getNumberValue("maximumValue"));
  4199. dataBarRule.gradient(getCheckValue("gradient"));
  4200. dataBarRule.color(getBackgroundColor("gradientColor"));
  4201. dataBarRule.showBorder(getCheckValue("showBorder"));
  4202. dataBarRule.borderColor(getBackgroundColor("barBorderColor"));
  4203. dataBarRule.dataBarDirection(+getDropDownValue("dataBarDirection"));
  4204. dataBarRule.negativeFillColor(getBackgroundColor("negativeFillColor"));
  4205. dataBarRule.useNegativeFillColor(getCheckValue("useNegativeFillColor"));
  4206. dataBarRule.negativeBorderColor(getBackgroundColor("negativeBorderColor"));
  4207. dataBarRule.useNegativeBorderColor(getCheckValue("useNegativeBorderColor"));
  4208. dataBarRule.axisPosition(+getDropDownValue("axisPosition"));
  4209. dataBarRule.axisColor(getBackgroundColor("barAxisColor"));
  4210. dataBarRule.showBarOnly(getCheckValue("showBarOnly"));
  4211. cfs.addRule(dataBarRule);
  4212. }
  4213. sheet.resumePaint();
  4214. }
  4215. function addIconSetRule() {
  4216. var sheet = spread.getActiveSheet();
  4217. sheet.suspendPaint();
  4218. var selections = sheet.getSelections();
  4219. if (selections.length > 0) {
  4220. var ranges = [];
  4221. $.each(selections, function (i, v) {
  4222. ranges.push(new spreadNS.Range(v.row, v.col, v.rowCount, v.colCount));
  4223. });
  4224. var cfs = sheet.conditionalFormats;
  4225. var iconSetRule = new ConditionalFormatting.IconSetRule();
  4226. iconSetRule.ranges(ranges);
  4227. iconSetRule.iconSetType(+getDropDownValue("iconSetType"));
  4228. var $divs = $("#iconCriteriaSetting .settinggroup:visible");
  4229. var iconCriteria = iconSetRule.iconCriteria();
  4230. $.each($divs, function (i, v) {
  4231. var suffix = i + 1,
  4232. isGreaterThanOrEqualTo = +getDropDownValue("iconSetCriteriaOperator" + suffix, this) === 1,
  4233. iconValueType = +getDropDownValue("iconSetCriteriaType" + suffix, this),
  4234. iconValue = $("input.editor", this).val();
  4235. if (iconValueType !== ConditionalFormatting.IconValueType.formula) {
  4236. iconValue = +iconValue;
  4237. }
  4238. iconCriteria[i] = new ConditionalFormatting.IconCriterion(isGreaterThanOrEqualTo, iconValueType, iconValue);
  4239. });
  4240. iconSetRule.reverseIconOrder(getCheckValue("reverseIconOrder"));
  4241. iconSetRule.showIconOnly(getCheckValue("showIconOnly"));
  4242. cfs.addRule(iconSetRule);
  4243. }
  4244. sheet.resumePaint();
  4245. }
  4246. function removeConditionFormats() {
  4247. var sheet = spread.getActiveSheet();
  4248. var cfs = sheet.conditionalFormats;
  4249. var row = sheet.getActiveRowIndex(), col = sheet.getActiveColumnIndex();
  4250. var rules = cfs.getRules(row, col);
  4251. sheet.suspendPaint();
  4252. $.each(rules, function (i, v) {
  4253. cfs.removeRule(v);
  4254. });
  4255. sheet.resumePaint();
  4256. }
  4257. // Cell Type related items
  4258. function attachCellTypeEvents() {
  4259. $("#setCellTypeBtn").click(function () {
  4260. var currentCellType = getDropDownValue("cellTypes");
  4261. applyCellType(currentCellType);
  4262. });
  4263. }
  4264. function processCellTypeSetting(name, noAction) {
  4265. $("#cellTypeSettingContainer").show();
  4266. switch (name) {
  4267. case "button-celltype":
  4268. $("#celltype-button").show();
  4269. $("#celltype-checkbox").hide();
  4270. $("#celltype-combobox").hide();
  4271. $("#celltype-hyperlink").hide();
  4272. break;
  4273. case "checkbox-celltype":
  4274. $("#celltype-button").hide();
  4275. $("#celltype-checkbox").show();
  4276. $("#celltype-combobox").hide();
  4277. $("#celltype-hyperlink").hide();
  4278. break;
  4279. case "combobox-celltype":
  4280. $("#celltype-button").hide();
  4281. $("#celltype-checkbox").hide();
  4282. $("#celltype-combobox").show();
  4283. $("#celltype-hyperlink").hide();
  4284. break;
  4285. case "hyperlink-celltype":
  4286. $("#celltype-button").hide();
  4287. $("#celltype-checkbox").hide();
  4288. $("#celltype-combobox").hide();
  4289. $("#celltype-hyperlink").show();
  4290. break;
  4291. case "clear-celltype":
  4292. if (!noAction) {
  4293. clearCellType();
  4294. }
  4295. $("#cellTypeSettingContainer").hide();
  4296. return;
  4297. default:
  4298. console.log("processCellTypeSetting not process with ", name);
  4299. return;
  4300. }
  4301. }
  4302. function applyCellType(name) {
  4303. var sheet = spread.getActiveSheet();
  4304. var cellType;
  4305. switch (name) {
  4306. case "button-celltype":
  4307. cellType = new spreadNS.CellTypes.Button();
  4308. cellType.marginTop(getNumberValue("buttonCellTypeMarginTop"));
  4309. cellType.marginRight(getNumberValue("buttonCellTypeMarginRight"));
  4310. cellType.marginBottom(getNumberValue("buttonCellTypeMarginBottom"));
  4311. cellType.marginLeft(getNumberValue("buttonCellTypeMarginLeft"));
  4312. cellType.text(getTextValue("buttonCellTypeText"));
  4313. cellType.buttonBackColor(getBackgroundColor("buttonCellTypeBackColor"));
  4314. break;
  4315. case "checkbox-celltype":
  4316. cellType = new spreadNS.CellTypes.CheckBox();
  4317. cellType.caption(getTextValue("checkboxCellTypeCaption"));
  4318. cellType.textTrue(getTextValue("checkboxCellTypeTextTrue"));
  4319. cellType.textIndeterminate(getTextValue("checkboxCellTypeTextIndeterminate"));
  4320. cellType.textFalse(getTextValue("checkboxCellTypeTextFalse"));
  4321. cellType.textAlign(getDropDownValue("checkboxCellTypeTextAlign"));
  4322. cellType.isThreeState(getCheckValue("checkboxCellTypeIsThreeState"));
  4323. break;
  4324. case "combobox-celltype":
  4325. cellType = new spreadNS.CellTypes.ComboBox();
  4326. cellType.editorValueType(getDropDownValue("comboboxCellTypeEditorValueType"));
  4327. var comboboxItemsText = getTextValue("comboboxCellTypeItemsText");
  4328. var comboboxItemsValue = getTextValue("comboboxCellTypeItemsValue");
  4329. var itemsText = comboboxItemsText.split(",");
  4330. var itemsValue = comboboxItemsValue.split(",");
  4331. var itemsLength = itemsText.length > itemsValue.length ? itemsText.length : itemsValue.length;
  4332. var items = [];
  4333. for (var count = 0; count < itemsLength; count++) {
  4334. var t = itemsText.length > count && itemsText[0] !== "" ? itemsText[count] : undefined;
  4335. var v = itemsValue.length > count && itemsValue[0] !== "" ? itemsValue[count] : undefined;
  4336. if (t !== undefined && v !== undefined) {
  4337. items[count] = {text: t, value: v};
  4338. }
  4339. else if (t !== undefined) {
  4340. items[count] = {text: t};
  4341. } else if (v !== undefined) {
  4342. items[count] = {value: v};
  4343. }
  4344. }
  4345. cellType.items(items);
  4346. break;
  4347. case "hyperlink-celltype":
  4348. cellType = new spreadNS.CellTypes.HyperLink();
  4349. cellType.linkColor(getBackgroundColor("hyperlinkCellTypeLinkColor"));
  4350. cellType.visitedLinkColor(getBackgroundColor("hyperlinkCellTypeVisitedLinkColor"));
  4351. cellType.text(getTextValue("hyperlinkCellTypeText"));
  4352. cellType.linkToolTip(getTextValue("hyperlinkCellTypeLinkToolTip"));
  4353. break;
  4354. }
  4355. sheet.suspendPaint();
  4356. sheet.suspendEvent();
  4357. var sels = sheet.getSelections();
  4358. var rowCount = sheet.getRowCount(),
  4359. columnCount = sheet.getColumnCount();
  4360. for (var i = 0; i < sels.length; i++) {
  4361. var sel = getActualCellRange(sheet, sels[i], rowCount, columnCount);
  4362. for (var r = 0; r < sel.rowCount; r++) {
  4363. for (var c = 0; c < sel.colCount; c++) {
  4364. sheet.setCellType(sel.row + r, sel.col + c, cellType, spreadNS.SheetArea.viewport);
  4365. }
  4366. }
  4367. }
  4368. sheet.resumeEvent();
  4369. sheet.resumePaint();
  4370. }
  4371. function clearCellType() {
  4372. var sheet = spread.getActiveSheet();
  4373. var sels = sheet.getSelections();
  4374. var rowCount = sheet.getRowCount(),
  4375. columnCount = sheet.getColumnCount();
  4376. sheet.suspendPaint();
  4377. for (var i = 0; i < sels.length; i++) {
  4378. var sel = getActualCellRange(sheet, sels[i], rowCount, columnCount);
  4379. sheet.clear(sel.row, sel.col, sel.rowCount, sel.colCount, spreadNS.SheetArea.viewport, spreadNS.StorageType.style);
  4380. }
  4381. sheet.resumePaint();
  4382. }
  4383. // Cell Type related items (end)
  4384. function processComparisonOperator(value) {
  4385. if ($("#ComparisonOperator").data("list-ref") === "cellValueOperatorList") {
  4386. // between (6) and not between ( 7) with two values
  4387. if (value === 6 || value === 7) {
  4388. $("#andtext").show();
  4389. $("#value2").show();
  4390. }
  4391. }
  4392. }
  4393. function updateEnumTypeOfCF(itemType) {
  4394. var $operator = $("#ComparisonOperator"),
  4395. $setButton = $("#setConditionalFormat");
  4396. $setButton.data("rule-type", itemType);
  4397. switch ("" + itemType) {
  4398. case "0":
  4399. $("#ruletext").text(conditionalFormatTexts.cells);
  4400. $("#andtext").hide();
  4401. $("#formattext").hide();
  4402. $("#value1").show();
  4403. $("#value1").val("");
  4404. $("#value2").hide();
  4405. $("#colorScale").hide();
  4406. $operator.show();
  4407. $operator.data("list-ref", "cellValueOperatorList");
  4408. setDropDownValueByIndex($operator, 0);
  4409. break;
  4410. case "1":
  4411. $("#ruletext").text(conditionalFormatTexts.cells);
  4412. $("#andtext").hide();
  4413. $("#formattext").hide();
  4414. $("#value1").show();
  4415. $("#value1").val("");
  4416. $("#value2").hide();
  4417. $("#colorScale").hide();
  4418. $operator.show();
  4419. $operator.data("list-ref", "specificTextOperatorList");
  4420. setDropDownValueByIndex($operator, 0);
  4421. break;
  4422. case "2":
  4423. $("#ruletext").text(conditionalFormatTexts.cells);
  4424. $("#andtext").hide();
  4425. $("#formattext").hide();
  4426. $("#value1").hide();
  4427. $("#value2").hide();
  4428. $("#colorScale").hide();
  4429. $operator.show();
  4430. $operator.data("list-ref", "dateOccurringOperatorList");
  4431. setDropDownValueByIndex($operator, 0);
  4432. break;
  4433. case "4":
  4434. $("#ruletext").text(conditionalFormatTexts.rankIn);
  4435. $("#andtext").hide();
  4436. $("#formattext").hide();
  4437. $("#value1").show();
  4438. $("#value1").val("10");
  4439. $("#value2").hide();
  4440. $("#colorScale").hide();
  4441. $operator.show();
  4442. $operator.data("list-ref", "top10OperatorList");
  4443. setDropDownValueByIndex($operator, 0);
  4444. break;
  4445. case "5":
  4446. case "6":
  4447. $("#ruletext").text(conditionalFormatTexts.all);
  4448. $("#andtext").hide();
  4449. $("#formattext").show();
  4450. $("#formattext").text(conditionalFormatTexts.inRange);
  4451. $("#value1").hide();
  4452. $("#value2").hide();
  4453. $("#colorScale").hide();
  4454. $operator.hide();
  4455. break;
  4456. case "7":
  4457. $("#ruletext").text(conditionalFormatTexts.values);
  4458. $("#andtext").hide();
  4459. $("#formattext").show();
  4460. $("#formattext").text(conditionalFormatTexts.average);
  4461. $("#value1").hide();
  4462. $("#value2").hide();
  4463. $("#colorScale").hide();
  4464. $operator.show();
  4465. $operator.data("list-ref", "averageOperatorList");
  4466. setDropDownValueByIndex($operator, 0);
  4467. break;
  4468. case "8":
  4469. $("#ruletext").text(conditionalFormatTexts.allValuesBased);
  4470. $("#andtext").hide();
  4471. $("#formattext").hide();
  4472. $("#value1").hide();
  4473. $("#value2").hide();
  4474. $("#colorScale").show();
  4475. $("#midpoint").hide();
  4476. $("#minType").val("1");
  4477. $("#maxType").val("2");
  4478. $("#minValue").val("");
  4479. $("#maxValue").val("");
  4480. $("#minColor").css("background", "#F8696B");
  4481. $("#maxColor").css("background", "#63BE7B");
  4482. $operator.hide();
  4483. break;
  4484. case "9":
  4485. $("#ruletext").text(conditionalFormatTexts.allValuesBased);
  4486. $("#andtext").hide();
  4487. $("#formattext").hide();
  4488. $("#value1").hide();
  4489. $("#value2").hide();
  4490. $("#colorScale").show();
  4491. $("#midpoint").show();
  4492. $("#minType").val("1");
  4493. $("#midType").val("4");
  4494. $("#maxType").val("2");
  4495. $("#minValue").val("");
  4496. $("#midValue").val("50");
  4497. $("#maxValue").val("");
  4498. $("#minColor").css("background-color", "#F8696B");
  4499. $("#midColor").css("background-color", "#FFEB84");
  4500. $("#maxColor").css("background-color", "#63BE7B");
  4501. $operator.hide();
  4502. break;
  4503. default:
  4504. break;
  4505. }
  4506. }
  4507. function attachConditionalFormatEvents() {
  4508. $("#setConditionalFormat").click(function () {
  4509. var ruleType = $(this).data("rule-type");
  4510. switch (ruleType) {
  4511. case "databar":
  4512. addDataBarRule();
  4513. break;
  4514. case "iconset":
  4515. addIconSetRule();
  4516. break;
  4517. default:
  4518. addCondionalFormaterRule("" + ruleType);
  4519. break;
  4520. }
  4521. });
  4522. }
  4523. // Data Validation related items
  4524. function processDataValidationSetting(name, title) {
  4525. $("#dataValidationErrorAlertMessage").val("");
  4526. $("#dataValidationErrorAlertTitle").val("");
  4527. $("#dataValidationInputTitle").val("");
  4528. $("#dataValidationInputMessage").val("");
  4529. switch (name) {
  4530. case "anyvalue-validator":
  4531. $("#validatorNumberType").hide();
  4532. $("#validatorListType").hide();
  4533. $("#validatorFormulaListType").hide();
  4534. $("#validatorDateType").hide();
  4535. $("#validatorTextLengthType").hide();
  4536. break;
  4537. case "number-validator":
  4538. $("#validatorNumberType").show();
  4539. $("#validatorListType").hide();
  4540. $("#validatorFormulaListType").hide();
  4541. $("#validatorDateType").hide();
  4542. $("#validatorTextLengthType").hide();
  4543. processNumberValidatorComparisonOperatorSetting(getDropDownValue("numberValidatorComparisonOperator"));
  4544. setTextValue("numberMinimum", 0);
  4545. setTextValue("numberMaximum", 0);
  4546. setTextValue("numberValue", 0);
  4547. break;
  4548. case "list-validator":
  4549. $("#validatorNumberType").hide();
  4550. $("#validatorListType").show();
  4551. $("#validatorFormulaListType").hide();
  4552. $("#validatorDateType").hide();
  4553. $("#validatorTextLengthType").hide();
  4554. setTextValue("listSource", "1,2,3");
  4555. break;
  4556. case "formulalist-validator":
  4557. $("#validatorNumberType").hide();
  4558. $("#validatorListType").hide();
  4559. $("#validatorFormulaListType").show();
  4560. $("#validatorDateType").hide();
  4561. $("#validatorTextLengthType").hide();
  4562. setTextValue("formulaListFormula", "E5:I5");
  4563. break;
  4564. case "date-validator":
  4565. $("#validatorNumberType").hide();
  4566. $("#validatorListType").hide();
  4567. $("#validatorFormulaListType").hide();
  4568. $("#validatorDateType").show();
  4569. $("#validatorTextLengthType").hide();
  4570. processDateValidatorComparisonOperatorSetting(getDropDownValue("dateValidatorComparisonOperator"));
  4571. var date = getCurrentTime();
  4572. setTextValue("startDate", date);
  4573. setTextValue("endDate", date);
  4574. setTextValue("dateValue", date);
  4575. break;
  4576. case "textlength-validator":
  4577. $("#validatorNumberType").hide();
  4578. $("#validatorListType").hide();
  4579. $("#validatorFormulaListType").hide();
  4580. $("#validatorDateType").hide();
  4581. $("#validatorTextLengthType").show();
  4582. processTextLengthValidatorComparisonOperatorSetting(getDropDownValue("textLengthValidatorComparisonOperator"));
  4583. setNumberValue("textLengthMinimum", 0);
  4584. setNumberValue("textLengthMaximum", 0);
  4585. setNumberValue("textLengthValue", 0);
  4586. break;
  4587. case "formula-validator":
  4588. $("#validatorNumberType").hide();
  4589. $("#validatorListType").hide();
  4590. $("#validatorFormulaListType").show();
  4591. $("#validatorDateType").hide();
  4592. $("#validatorTextLengthType").hide();
  4593. setTextValue("formulaListFormula", "=ISERROR(FIND(\" \",A1))");
  4594. break;
  4595. default:
  4596. console.log("processDataValidationSetting not process with ", name, title);
  4597. break;
  4598. }
  4599. }
  4600. function processNumberValidatorComparisonOperatorSetting(value) {
  4601. if (value === ComparisonOperators.between || value === ComparisonOperators.notBetween) {
  4602. $("#numberValue").hide();
  4603. $("#numberBetweenOperator").show();
  4604. }
  4605. else {
  4606. $("#numberBetweenOperator").hide();
  4607. $("#numberValue").show();
  4608. }
  4609. }
  4610. function processDateValidatorComparisonOperatorSetting(value) {
  4611. if (value === ComparisonOperators.between || value === ComparisonOperators.notBetween) {
  4612. $("#dateValue").hide();
  4613. $("#dateBetweenOperator").show();
  4614. }
  4615. else {
  4616. $("#dateBetweenOperator").hide();
  4617. $("#dateValue").show();
  4618. }
  4619. }
  4620. function processTextLengthValidatorComparisonOperatorSetting(value) {
  4621. if (value === ComparisonOperators.between || value === ComparisonOperators.notBetween) {
  4622. $("#textLengthValue").hide();
  4623. $("#textLengthBetweenOperator").show();
  4624. }
  4625. else {
  4626. $("#textLengthBetweenOperator").hide();
  4627. $("#textLengthValue").show();
  4628. }
  4629. }
  4630. function setDataValidator() {
  4631. var validatorType = getDropDownValue("validatorType");
  4632. var currentDataValidator = null;
  4633. var dropDownValue;
  4634. var formulaListFormula = getTextValue("formulaListFormula");
  4635. switch (validatorType) {
  4636. case "anyvalue-validator":
  4637. currentDataValidator = new spreadNS.DataValidation.DefaultDataValidator();
  4638. break;
  4639. case "number-validator":
  4640. var numberMinimum = getTextValue("numberMinimum");
  4641. var numberMaximum = getTextValue("numberMaximum");
  4642. var numberValue = getTextValue("numberValue");
  4643. var isInteger = getCheckValue("isInteger");
  4644. dropDownValue = getDropDownValue("numberValidatorComparisonOperator");
  4645. if (dropDownValue !== ComparisonOperators.between && dropDownValue !== ComparisonOperators.notBetween) {
  4646. numberMinimum = numberValue;
  4647. }
  4648. if (isInteger) {
  4649. currentDataValidator = DataValidation.createNumberValidator(dropDownValue,
  4650. isNaN(numberMinimum) ? numberMinimum : parseInt(numberMinimum, 10),
  4651. isNaN(numberMaximum) ? numberMaximum : parseInt(numberMaximum, 10),
  4652. true);
  4653. } else {
  4654. currentDataValidator = DataValidation.createNumberValidator(dropDownValue,
  4655. isNaN(numberMinimum) ? numberMinimum : parseFloat(numberMinimum, 10),
  4656. isNaN(numberMaximum) ? numberMaximum : parseFloat(numberMaximum, 10),
  4657. false);
  4658. }
  4659. break;
  4660. case "list-validator":
  4661. var listSource = getTextValue("listSource");
  4662. currentDataValidator = DataValidation.createListValidator(listSource);
  4663. break;
  4664. case "formulalist-validator":
  4665. currentDataValidator = DataValidation.createFormulaListValidator(formulaListFormula);
  4666. break;
  4667. case "date-validator":
  4668. var startDate = getTextValue("startDate");
  4669. var endDate = getTextValue("endDate");
  4670. var dateValue = getTextValue("dateValue");
  4671. var isTime = getCheckValue("isTime");
  4672. dropDownValue = getDropDownValue("dateValidatorComparisonOperator");
  4673. if (dropDownValue !== ComparisonOperators.between && dropDownValue !== ComparisonOperators.notBetween) {
  4674. startDate = dateValue;
  4675. }
  4676. if (isTime) {
  4677. currentDataValidator = DataValidation.createDateValidator(dropDownValue,
  4678. isNaN(startDate) ? startDate : new Date(startDate),
  4679. isNaN(endDate) ? endDate : new Date(endDate),
  4680. true);
  4681. } else {
  4682. currentDataValidator = DataValidation.createDateValidator(dropDownValue,
  4683. isNaN(startDate) ? startDate : new Date(startDate),
  4684. isNaN(endDate) ? endDate : new Date(endDate),
  4685. false);
  4686. }
  4687. break;
  4688. case "textlength-validator":
  4689. var textLengthMinimum = getNumberValue("textLengthMinimum");
  4690. var textLengthMaximum = getNumberValue("textLengthMaximum");
  4691. var textLengthValue = getNumberValue("textLengthValue");
  4692. dropDownValue = getDropDownValue("textLengthValidatorComparisonOperator");
  4693. if (dropDownValue !== ComparisonOperators.between && dropDownValue !== ComparisonOperators.notBetween) {
  4694. textLengthMinimum = textLengthValue;
  4695. }
  4696. currentDataValidator = DataValidation.createTextLengthValidator(dropDownValue, textLengthMinimum, textLengthMaximum);
  4697. break;
  4698. case "formula-validator":
  4699. currentDataValidator = DataValidation.createFormulaValidator(formulaListFormula);
  4700. break;
  4701. }
  4702. if (currentDataValidator) {
  4703. currentDataValidator.errorMessage($("#dataValidationErrorAlertMessage").val());
  4704. currentDataValidator.errorStyle(getDropDownValue("errorAlert"));
  4705. currentDataValidator.errorTitle($("#dataValidationErrorAlertTitle").val());
  4706. currentDataValidator.showErrorMessage(getCheckValue("showErrorAlert"));
  4707. currentDataValidator.ignoreBlank(getCheckValue("ignoreBlank"));
  4708. var showInputMessage = getCheckValue("showInputMessage");
  4709. if (showInputMessage) {
  4710. currentDataValidator.inputTitle($("#dataValidationInputTitle").val());
  4711. currentDataValidator.inputMessage($("#dataValidationInputMessage").val());
  4712. }
  4713. setDataValidatorInRange(currentDataValidator);
  4714. }
  4715. }
  4716. function setDataValidatorInRange(dataValidator) {
  4717. var sheet = spread.getActiveSheet();
  4718. sheet.suspendPaint();
  4719. var sels = sheet.getSelections();
  4720. var rowCount = sheet.getRowCount(),
  4721. columnCount = sheet.getColumnCount();
  4722. for (var i = 0; i < sels.length; i++) {
  4723. var sel = getActualCellRange(sheet, sels[i], rowCount, columnCount);
  4724. for (var r = 0; r < sel.rowCount; r++) {
  4725. for (var c = 0; c < sel.colCount; c++) {
  4726. sheet.setDataValidator(sel.row + r, sel.col + c, dataValidator);
  4727. }
  4728. }
  4729. }
  4730. sheet.resumePaint();
  4731. }
  4732. function getCurrentTime() {
  4733. var date = new Date();
  4734. var year = date.getFullYear();
  4735. var month = date.getMonth() + 1;
  4736. var day = date.getDate();
  4737. var strDate = year + "-";
  4738. if (month < 10)
  4739. strDate += "0";
  4740. strDate += month + "-";
  4741. if (day < 10)
  4742. strDate += "0";
  4743. strDate += day;
  4744. return strDate;
  4745. }
  4746. function attachDataValidationEvents() {
  4747. $("#setDataValidator").click(function () {
  4748. var currentValidatorType = getDropDownValue("validatorType");
  4749. setDataValidator(currentValidatorType);
  4750. });
  4751. $("#clearDataValidatorSettings").click(function () {
  4752. // reset to default
  4753. var validationTypeItem = setDropDownValueByIndex($("#validatorType"), 0);
  4754. processDataValidationSetting(validationTypeItem.value);
  4755. setDropDownValue("errorAlert", 0);
  4756. setCheckValue("showInputMessage", true);
  4757. setCheckValue("showErrorAlert", true);
  4758. });
  4759. }
  4760. // Data Validation related items (end)
  4761. function updateIconCriteriaItems(iconStyleType) {
  4762. var IconSetType = ConditionalFormatting.IconSetType,
  4763. items = $("#iconCriteriaSetting .settinggroup"),
  4764. values;
  4765. if (iconStyleType <= IconSetType.threeSymbolsUncircled) {
  4766. values = [33, 67];
  4767. } else if (iconStyleType <= IconSetType.fourTrafficLights) {
  4768. values = [25, 50, 75];
  4769. } else {
  4770. values = [20, 40, 60, 80];
  4771. }
  4772. items.each(function (index) {
  4773. var value = values[index], $item = $(this), suffix = index + 1;
  4774. if (value) {
  4775. $item.show();
  4776. setDropDownValue("iconSetCriteriaOperator" + suffix, 1, this);
  4777. setDropDownValue("iconSetCriteriaType" + suffix, 4, this);
  4778. $("input.editor", this).val(value);
  4779. } else {
  4780. $item.hide();
  4781. }
  4782. });
  4783. }
  4784. function processMinItems(type, name) {
  4785. var value = "";
  4786. switch (type) {
  4787. case 0: // Number
  4788. case 3: // Percent
  4789. value = "0";
  4790. break;
  4791. case 4: // Percentile
  4792. value = "10";
  4793. break;
  4794. default:
  4795. value = "";
  4796. break;
  4797. }
  4798. setTextValue(name, value);
  4799. }
  4800. function processMidItems(type, name) {
  4801. var value = "";
  4802. switch (type) {
  4803. case 0: // Number
  4804. value = "0";
  4805. break;
  4806. case 3: // Percent
  4807. case 4: // Percentile
  4808. value = "50";
  4809. break;
  4810. default:
  4811. value = "";
  4812. break;
  4813. }
  4814. setTextValue(name, value);
  4815. }
  4816. function processMaxItems(type, name) {
  4817. var value = "";
  4818. switch (type) {
  4819. case 0: // Number
  4820. value = "0";
  4821. break;
  4822. case 3: // Percent
  4823. value = "100";
  4824. break;
  4825. case 4: // Percentile
  4826. value = "90";
  4827. break;
  4828. default:
  4829. value = "";
  4830. break;
  4831. }
  4832. setTextValue(name, value);
  4833. }
  4834. // Sparkline related items
  4835. function processAddSparklineEx() {
  4836. var sheet = spread.getActiveSheet();
  4837. var selection = sheet.getSelections()[0];
  4838. if (!selection) {
  4839. return;
  4840. }
  4841. var id = this.id,
  4842. sparklineType = id.toUpperCase();
  4843. var $typeInfo = $(".menu-item>div.text[data-value='" + sparklineType + "']");
  4844. if ($typeInfo.length > 0) {
  4845. setDropDownValue("sparklineExType", sparklineType);
  4846. processSparklineSetting(sparklineType);
  4847. }
  4848. else {
  4849. processSparklineSetting(getDropDownValue("sparklineExType"));
  4850. }
  4851. setTextValue("txtLineDataRange", parseRangeToExpString(selection));
  4852. setTextValue("txtLineLocationRange", "");
  4853. var SPARKLINE_DIALOG_WIDTH = 360; // sprakline dialog width
  4854. showModal(uiResource.sparklineDialog.title, SPARKLINE_DIALOG_WIDTH, $("#sparklineexdialog").children(), addSparklineEvent);
  4855. }
  4856. function unParseFormula(expr, row, col) {
  4857. if (!expr) {
  4858. return "";
  4859. }
  4860. var sheet = spread.getActiveSheet();
  4861. if (!sheet) {
  4862. return null;
  4863. }
  4864. var calcService = sheet.getCalcService();
  4865. return calcService.unparse(null, expr, row, col);
  4866. }
  4867. function processSparklineSetting(name, title) {
  4868. //Show only when data range is illegal.
  4869. $("#dataRangeError").hide();
  4870. $("#singleDataRangeError").hide();
  4871. //Show only when location range is illegal.
  4872. $("#locationRangeError").hide();
  4873. switch (name) {
  4874. case "LINESPARKLINE":
  4875. case "COLUMNSPARKLINE":
  4876. case "WINLOSSSPARKLINE":
  4877. case "PIESPARKLINE":
  4878. case "AREASPARKLINE":
  4879. case "SCATTERSPARKLINE":
  4880. case "SPREADSPARKLINE":
  4881. case "STACKEDSPARKLINE":
  4882. case "BOXPLOTSPARKLINE":
  4883. case "CASCADESPARKLINE":
  4884. case "PARETOSPARKLINE":
  4885. $("#lineContainer").show();
  4886. $("#bulletContainer").hide();
  4887. $("#monthContainer").hide();
  4888. $("#hbarContainer").hide();
  4889. $("#yearContainer").hide();
  4890. $("#varianceContainer").hide();
  4891. break;
  4892. case "BULLETSPARKLINE":
  4893. $("#lineContainer").hide();
  4894. $("#monthContainer").hide();
  4895. $("#bulletContainer").show();
  4896. $("#hbarContainer").hide();
  4897. $("#yearContainer").hide();
  4898. $("#varianceContainer").hide();
  4899. setTextValue("txtBulletMeasure", "");
  4900. setTextValue("txtBulletTarget", "");
  4901. setTextValue("txtBulletMaxi", "");
  4902. setTextValue("txtBulletGood", "");
  4903. setTextValue("txtBulletBad", "");
  4904. setTextValue("txtBulletForecast", "");
  4905. setTextValue("txtBulletTickunit", "");
  4906. setCheckValue("checkboxBulletVertial", false);
  4907. break;
  4908. case "HBARSPARKLINE":
  4909. case "VBARSPARKLINE":
  4910. $("#lineContainer").hide();
  4911. $("#bulletContainer").hide();
  4912. $("#monthContainer").hide();
  4913. $("#hbarContainer").show();
  4914. $("#yearContainer").hide();
  4915. $("#varianceContainer").hide();
  4916. setTextValue("txtHbarValue", "");
  4917. break;
  4918. case "VARISPARKLINE":
  4919. $("#lineContainer").hide();
  4920. $("#bulletContainer").hide();
  4921. $("#hbarContainer").hide();
  4922. $("#monthContainer").hide();
  4923. $("#yearContainer").hide();
  4924. $("#varianceContainer").show();
  4925. setTextValue("txtVariance", "");
  4926. setTextValue("txtVarianceReference", "");
  4927. setTextValue("txtVarianceMini", "");
  4928. setTextValue("txtVarianceMaxi", "");
  4929. setTextValue("txtVarianceMark", "");
  4930. setTextValue("txtVarianceTickUnit", "");
  4931. setCheckValue("checkboxVarianceLegend", false);
  4932. setCheckValue("checkboxVarianceVertical", false);
  4933. break;
  4934. case "MONTHSPARKLINE":
  4935. $("#lineContainer").show();
  4936. $("#bulletContainer").hide();
  4937. $("#hbarContainer").hide();
  4938. $("#varianceContainer").hide();
  4939. $("#yearContainer").show();
  4940. $("#monthContainer").show();
  4941. setTextValue("txtYearValue", "");
  4942. setTextValue("txtMonthValue", "");
  4943. setTextValue("txtEmptyColorValue", "");
  4944. setTextValue("txtStartColorValue", "");
  4945. setTextValue("txtMiddleColorValue", "");
  4946. setTextValue("txtEndColorValue", "");
  4947. setTextValue("txtColorRangeValue", "");
  4948. break;
  4949. case "YEARSPARKLINE":
  4950. $("#lineContainer").show();
  4951. $("#bulletContainer").hide();
  4952. $("#hbarContainer").hide();
  4953. $("#varianceContainer").hide();
  4954. $("#monthContainer").hide();
  4955. $("#yearContainer").show();
  4956. setTextValue("txtYearValue", "");
  4957. setTextValue("txtEmptyColorValue", "");
  4958. setTextValue("txtStartColorValue", "");
  4959. setTextValue("txtMiddleColorValue", "");
  4960. setTextValue("txtEndColorValue", "");
  4961. setTextValue("txtColorRangeValue", "");
  4962. break;
  4963. default:
  4964. console.log("processSparklineSetting not process with ", name, title);
  4965. break;
  4966. }
  4967. }
  4968. function addSparklineEvent() {
  4969. var sheet = spread.getActiveSheet(),
  4970. selection = sheet.getSelections()[0],
  4971. isValid = true;
  4972. var sparklineExType = getDropDownValue("sparklineExType");
  4973. if (selection) {
  4974. var range = getActualRange(selection, sheet.getRowCount(), sheet.getColumnCount());
  4975. var formulaStr = '', row = range.row, col = range.col, direction = 0;
  4976. switch (sparklineExType) {
  4977. case "BULLETSPARKLINE":
  4978. var measure = getTextValue("txtBulletMeasure"),
  4979. target = getTextValue("txtBulletTarget"),
  4980. maxi = getTextValue("txtBulletMaxi"),
  4981. good = getTextValue("txtBulletGood"),
  4982. bad = getTextValue("txtBulletBad"),
  4983. forecast = getTextValue("txtBulletForecast"),
  4984. tickunit = getTextValue("txtBulletTickunit"),
  4985. colorScheme = getBackgroundColor("colorBulletColorScheme"),
  4986. vertical = getCheckValue("checkboxBulletVertial");
  4987. formulaStr = '=' + sparklineExType + '(' + measure + ',' + target + ',' + maxi + ',' + good + ',' + bad + ',' + forecast + ',' + tickunit + ',' + '"' + colorScheme + '"' + ',' + vertical + ')';
  4988. sheet.setFormula(row, col, formulaStr);
  4989. break;
  4990. case "HBARSPARKLINE":
  4991. var value = getTextValue("txtHbarValue"),
  4992. colorScheme = getBackgroundColor("colorHbarColorScheme");
  4993. formulaStr = '=' + sparklineExType + '(' + value + ',' + '"' + colorScheme + '"' + ')';
  4994. sheet.setFormula(row, col, formulaStr);
  4995. break;
  4996. case "VBARSPARKLINE":
  4997. var value = getTextValue("txtHbarValue"),
  4998. colorScheme = getBackgroundColor("colorHbarColorScheme");
  4999. formulaStr = '=' + sparklineExType + '(' + value + ',' + '"' + colorScheme + '"' + ')';
  5000. sheet.setFormula(row, col, formulaStr);
  5001. break;
  5002. case "VARISPARKLINE":
  5003. var variance = getTextValue("txtVariance"),
  5004. reference = getTextValue("txtVarianceReference"),
  5005. mini = getTextValue("txtVarianceMini"),
  5006. maxi = getTextValue("txtVarianceMaxi"),
  5007. mark = getTextValue("txtVarianceMark"),
  5008. tickunit = getTextValue("txtVarianceTickUnit"),
  5009. colorPositive = getBackgroundColor("colorVariancePositive"),
  5010. colorNegative = getBackgroundColor("colorVarianceNegative"),
  5011. legend = getCheckValue("checkboxVarianceLegend"),
  5012. vertical = getCheckValue("checkboxVarianceVertical");
  5013. formulaStr = '=' + sparklineExType + '(' + variance + ',' + reference + ',' + mini + ',' + maxi + ',' + mark + ',' + tickunit + ',' + legend + ',' + '"' + colorPositive + '"' + ',' + '"' + colorNegative + '"' + ',' + vertical + ')';
  5014. sheet.setFormula(row, col, formulaStr);
  5015. break;
  5016. case "CASCADESPARKLINE":
  5017. case "PARETOSPARKLINE":
  5018. var dataRangeStr = getTextValue("txtLineDataRange"),
  5019. locationRangeStr = getTextValue("txtLineLocationRange"),
  5020. dataRangeObj = parseStringToExternalRanges(dataRangeStr, sheet),
  5021. locationRangeObj = parseStringToExternalRanges(locationRangeStr, sheet),
  5022. vertical = false,
  5023. dataRange, locationRange;
  5024. if (dataRangeObj && dataRangeObj.length > 0 && dataRangeObj[0].range) {
  5025. dataRange = dataRangeObj[0].range;
  5026. }
  5027. if (locationRangeObj && locationRangeObj.length > 0 && locationRangeObj[0].range) {
  5028. locationRange = locationRangeObj[0].range;
  5029. }
  5030. if (locationRange && locationRange.rowCount < locationRange.colCount) {
  5031. vertical = true;
  5032. }
  5033. if (!dataRange) {
  5034. isValid = false;
  5035. $("#dataRangeError").show();
  5036. }
  5037. if (!locationRange) {
  5038. isValid = false;
  5039. $("#locationRangeError").show();
  5040. }
  5041. if (isValid) {
  5042. var pointCount = dataRange.rowCount * dataRange.colCount,
  5043. i = 1;
  5044. for (var r = locationRange.row; r < locationRange.row + locationRange.rowCount; r++) {
  5045. for (var c = locationRange.col; c < locationRange.col + locationRange.colCount; c++) {
  5046. if (i <= pointCount) {
  5047. formulaStr = '=' + sparklineExType + '(' + dataRangeStr + ',' + i + ',,,,,,' + vertical + ')';
  5048. sheet.setFormula(r, c, formulaStr);
  5049. sheet.setActiveCell(r, c);
  5050. i++;
  5051. }
  5052. }
  5053. }
  5054. }
  5055. break;
  5056. case "MONTHSPARKLINE":
  5057. var year = getTextValue("txtYearValue"),
  5058. month = getTextValue("txtMonthValue"),
  5059. emptyColor = getBackgroundColor("emptyColorValue"),
  5060. startColor = getBackgroundColor("startColorValue"),
  5061. middleColor = getBackgroundColor("middleColorValue"),
  5062. endColor = getBackgroundColor("endColorValue"),
  5063. dataRangeStr = getTextValue("txtLineDataRange"),
  5064. locationRangeStr = getTextValue("txtLineLocationRange"),
  5065. colorRangeStr = getTextValue("txtColorRangeValue"),
  5066. dataRangeObj = parseStringToExternalRanges(dataRangeStr, sheet),
  5067. locationRangeObj = parseStringToExternalRanges(locationRangeStr, sheet),
  5068. dataRange, locationRange;
  5069. if (dataRangeObj && dataRangeObj.length > 0 && dataRangeObj[0].range) {
  5070. dataRange = dataRangeObj[0].range;
  5071. }
  5072. if (locationRangeObj && locationRangeObj.length > 0 && locationRangeObj[0].range) {
  5073. locationRange = locationRangeObj[0].range;
  5074. }
  5075. if (!dataRange) {
  5076. isValid = false;
  5077. $("#dataRangeError").show();
  5078. }
  5079. if (!locationRange) {
  5080. isValid = false;
  5081. $("#locationRangeError").show();
  5082. }
  5083. var row = locationRange.row, col = locationRange.col;
  5084. if (isValid) {
  5085. if (!colorRangeStr) {
  5086. formulaStr = "=" + sparklineExType + "(" + year + "," + month + "," + dataRangeStr + "," + parseSparklineColorOptions(emptyColor) + "," + parseSparklineColorOptions(startColor) + "," + parseSparklineColorOptions(middleColor) + "," + parseSparklineColorOptions(endColor) + ")";
  5087. } else {
  5088. formulaStr = "=" + sparklineExType + "(" + year + "," + month + "," + dataRangeStr + "," + colorRangeStr + ")";
  5089. }
  5090. sheet.setFormula(row, col, formulaStr);
  5091. }
  5092. break;
  5093. case "YEARSPARKLINE":
  5094. var year = getTextValue("txtYearValue"),
  5095. emptyColor = getBackgroundColor("emptyColorValue"),
  5096. startColor = getBackgroundColor("startColorValue"),
  5097. middleColor = getBackgroundColor("middleColorValue"),
  5098. endColor = getBackgroundColor("endColorValue"),
  5099. dataRangeStr = getTextValue("txtLineDataRange"),
  5100. locationRangeStr = getTextValue("txtLineLocationRange"),
  5101. colorRangeStr = getTextValue("txtColorRangeValue"),
  5102. dataRangeObj = parseStringToExternalRanges(dataRangeStr, sheet),
  5103. locationRangeObj = parseStringToExternalRanges(locationRangeStr, sheet),
  5104. dataRange, locationRange;
  5105. if (dataRangeObj && dataRangeObj.length > 0 && dataRangeObj[0].range) {
  5106. dataRange = dataRangeObj[0].range;
  5107. }
  5108. if (locationRangeObj && locationRangeObj.length > 0 && locationRangeObj[0].range) {
  5109. locationRange = locationRangeObj[0].range;
  5110. }
  5111. if (!dataRange) {
  5112. isValid = false;
  5113. $("#dataRangeError").show();
  5114. }
  5115. if (!locationRange) {
  5116. isValid = false;
  5117. $("#locationRangeError").show();
  5118. }
  5119. var row = locationRange.row, col = locationRange.col;
  5120. if (isValid) {
  5121. if (!colorRangeStr) {
  5122. formulaStr = "=" + sparklineExType + "(" + year + "," + dataRangeStr + "," + parseSparklineColorOptions(emptyColor) + "," + parseSparklineColorOptions(startColor) + "," + parseSparklineColorOptions(middleColor) + "," + parseSparklineColorOptions(endColor) + ")";
  5123. } else {
  5124. formulaStr = "=" + sparklineExType + "(" + year + "," + dataRangeStr + "," + colorRangeStr + ")";
  5125. }
  5126. sheet.setFormula(row, col, formulaStr);
  5127. }
  5128. break;
  5129. default:
  5130. var dataRangeStr = getTextValue("txtLineDataRange"),
  5131. locationRangeStr = getTextValue("txtLineLocationRange"),
  5132. dataRangeObj = parseStringToExternalRanges(dataRangeStr, sheet),
  5133. locationRangeObj = parseStringToExternalRanges(locationRangeStr, sheet),
  5134. dataRange, locationRange;
  5135. if (dataRangeObj && dataRangeObj.length > 0 && dataRangeObj[0].range) {
  5136. dataRange = dataRangeObj[0].range;
  5137. }
  5138. if (locationRangeObj && locationRangeObj.length > 0 && locationRangeObj[0].range) {
  5139. locationRange = locationRangeObj[0].range;
  5140. }
  5141. if (!dataRange) {
  5142. isValid = false;
  5143. $("#dataRangeError").show();
  5144. }
  5145. if (!locationRange) {
  5146. isValid = false;
  5147. $("#locationRangeError").show();
  5148. }
  5149. if (isValid) {
  5150. if (["LINESPARKLINE", "COLUMNSPARKLINE", "WINLOSSSPARKLINE"].indexOf(sparklineExType) >= 0) {
  5151. if (dataRange.rowCount === 1) {
  5152. direction = 1;
  5153. }
  5154. else if (dataRange.colCount === 1) {
  5155. direction = 0;
  5156. }
  5157. else {
  5158. $("#singleDataRangeError").show();
  5159. isValid = false;
  5160. }
  5161. if (isValid) {
  5162. formulaStr = '=' + sparklineExType + '(' + dataRangeStr + ',' + direction + ')';
  5163. }
  5164. }
  5165. else {
  5166. formulaStr = '=' + sparklineExType + '(' + dataRangeStr + ')';
  5167. }
  5168. if (isValid) {
  5169. row = locationRange.row;
  5170. col = locationRange.col;
  5171. sheet.setFormula(row, col, formulaStr);
  5172. sheet.setActiveCell(row, col);
  5173. }
  5174. }
  5175. break;
  5176. }
  5177. }
  5178. if (!isValid) {
  5179. return {canceled: true};
  5180. }
  5181. else {
  5182. if (showSparklineSetting(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex())) {
  5183. updateFormulaBar();
  5184. setActiveTab("sparklineEx");
  5185. return;
  5186. }
  5187. console.log("Added sparkline", sparklineExType);
  5188. }
  5189. }
  5190. function parseSparklineColorOptions(str) {
  5191. return '"' + str + '"';
  5192. }
  5193. function parseRangeToExpString(range) {
  5194. return SheetsCalc.rangeToFormula(range, 0, 0, SheetsCalc.RangeReferenceRelative.allRelative);
  5195. }
  5196. function parseStringToExternalRanges(expString, sheet) {
  5197. var results = [];
  5198. var exps = expString.split(",");
  5199. try {
  5200. for (var i = 0; i < exps.length; i++) {
  5201. var range = SheetsCalc.formulaToRange(sheet, exps[i]);
  5202. results.push({"range": range});
  5203. }
  5204. }
  5205. catch (e) {
  5206. return null;
  5207. }
  5208. return results;
  5209. }
  5210. function parseFormulaSparkline(row, col) {
  5211. var sheet = spread.getActiveSheet();
  5212. if (!sheet) {
  5213. return null;
  5214. }
  5215. var formula = sheet.getFormula(row, col);
  5216. if (!formula) {
  5217. return null;
  5218. }
  5219. var calcService = sheet.getCalcService();
  5220. try {
  5221. var expr = calcService.parse(null, formula, row, col);
  5222. if (expr.type === ExpressionType.function) {
  5223. var fnName = expr.functionName;
  5224. if (fnName && spread.getSparklineEx(fnName)) {
  5225. return expr;
  5226. }
  5227. }
  5228. }
  5229. catch (ex) {
  5230. console.log("parse failed:", ex);
  5231. }
  5232. return null;
  5233. }
  5234. function parseColorExpression(colorExpression, row, col) {
  5235. if (!colorExpression) {
  5236. return null;
  5237. }
  5238. var sheet = spread.getActiveSheet();
  5239. if (colorExpression.type === ExpressionType.string) {
  5240. return colorExpression.value;
  5241. }
  5242. else if (colorExpression.type === ExpressionType.missingArgument) {
  5243. return null;
  5244. }
  5245. else {
  5246. var formula = null;
  5247. try {
  5248. formula = unParseFormula(colorExpression, row, col);
  5249. }
  5250. catch (ex) {
  5251. }
  5252. return SheetsCalc.evaluateFormula(sheet, formula, row, col);
  5253. }
  5254. }
  5255. function getAreaSparklineSetting(formulaArgs, row, col) {
  5256. var defaultValue = {colorPositive: "#787878", colorNegative: "#CB0000"};
  5257. if (formulaArgs[0]) {
  5258. setTextValue("areaSparklinePoints", unParseFormula(formulaArgs[0], row, col));
  5259. }
  5260. else {
  5261. setTextValue("areaSparklinePoints", "");
  5262. }
  5263. var inputList = ["areaSparklineMinimumValue", "areaSparklineMaximumValue", "areaSparklineLine1", "areaSparklineLine2"];
  5264. var len = inputList.length;
  5265. for (var i = 1; i <= len; i++) {
  5266. if (formulaArgs[i]) {
  5267. setNumberValue(inputList[i - 1], unParseFormula(formulaArgs[i], row, col));
  5268. }
  5269. else {
  5270. setNumberValue(inputList[i - 1], "");
  5271. }
  5272. }
  5273. var positiveColor = parseColorExpression(formulaArgs[5], row, col);
  5274. if (positiveColor) {
  5275. setColorValue("areaSparklinePositiveColor", positiveColor);
  5276. }
  5277. else {
  5278. setColorValue("areaSparklinePositiveColor", defaultValue.colorPositive);
  5279. }
  5280. var negativeColor = parseColorExpression(formulaArgs[6], row, col);
  5281. if (negativeColor) {
  5282. setColorValue("areaSparklineNegativeColor", negativeColor);
  5283. }
  5284. else {
  5285. setColorValue("areaSparklineNegativeColor", defaultValue.colorNegative);
  5286. }
  5287. }
  5288. function getBoxPlotSparklineSetting(formulaArgs, row, col) {
  5289. var defaultValue = {boxplotClass: "5ns", style: 0, colorScheme: "#D2D2D2", vertical: false, showAverage: false};
  5290. if (formulaArgs && formulaArgs.length > 0) {
  5291. var pointsValue = unParseFormula(formulaArgs[0], row, col);
  5292. var boxPlotClassValue = formulaArgs[1] && (formulaArgs[1].type === ExpressionType.string ? formulaArgs[1].value : null);
  5293. var showAverageValue = formulaArgs[2] && (formulaArgs[2].type === ExpressionType.boolean ? formulaArgs[2].value : null);
  5294. var scaleStartValue = unParseFormula(formulaArgs[3], row, col);
  5295. var scaleEndValue = unParseFormula(formulaArgs[4], row, col);
  5296. var acceptableStartValue = unParseFormula(formulaArgs[5], row, col);
  5297. var acceptableEndValue = unParseFormula(formulaArgs[6], row, col);
  5298. var colorValue = parseColorExpression(formulaArgs[7], row, col);
  5299. var styleValue = formulaArgs[8] ? unParseFormula(formulaArgs[8], row, col) : null;
  5300. var verticalValue = formulaArgs[9] && (formulaArgs[9].type === ExpressionType.boolean ? formulaArgs[9].value : null);
  5301. setTextValue("boxplotSparklinePoints", pointsValue);
  5302. setDropDownValue("boxplotClassType", boxPlotClassValue === null ? defaultValue.boxplotClass : boxPlotClassValue);
  5303. setTextValue("boxplotSparklineScaleStart", scaleStartValue);
  5304. setTextValue("boxplotSparklineScaleEnd", scaleEndValue);
  5305. setTextValue("boxplotSparklineAcceptableStart", acceptableStartValue);
  5306. setTextValue("boxplotSparklineAcceptableEnd", acceptableEndValue);
  5307. setColorValue("boxplotSparklineColorScheme", colorValue === null ? defaultValue.colorScheme : colorValue);
  5308. setDropDownValue("boxplotSparklineStyleType", styleValue === null ? defaultValue.style : styleValue);
  5309. setCheckValue("boxplotSparklineShowAverage", showAverageValue === null ? defaultValue.showAverage : showAverageValue);
  5310. setCheckValue("boxplotSparklineVertical", verticalValue === null ? defaultValue.vertical : verticalValue);
  5311. }
  5312. else {
  5313. setTextValue("boxplotSparklinePoints", "");
  5314. setDropDownValue("boxplotClassType", defaultValue.boxplotClass);
  5315. setTextValue("boxplotSparklineScaleStart", "");
  5316. setTextValue("boxplotSparklineScaleEnd", "");
  5317. setTextValue("boxplotSparklineAcceptableStart", "");
  5318. setTextValue("boxplotSparklineAcceptableEnd", "");
  5319. setColorValue("boxplotSparklineColorScheme", defaultValue.colorScheme);
  5320. setDropDownValue("boxplotSparklineStyleType", defaultValue.style);
  5321. setCheckValue("boxplotSparklineShowAverage", defaultValue.showAverage);
  5322. setCheckValue("boxplotSparklineVertical", defaultValue.vertical);
  5323. }
  5324. }
  5325. function getBulletSparklineSetting(formulaArgs, row, col) {
  5326. var defaultValue = {vertical: false, colorScheme: "#A0A0A0"};
  5327. if (formulaArgs && formulaArgs.length > 0) {
  5328. var measureValue = unParseFormula(formulaArgs[0], row, col);
  5329. var targetValue = unParseFormula(formulaArgs[1], row, col);
  5330. var maxiValue = unParseFormula(formulaArgs[2], row, col);
  5331. var goodValue = unParseFormula(formulaArgs[3], row, col);
  5332. var badValue = unParseFormula(formulaArgs[4], row, col);
  5333. var forecastValue = unParseFormula(formulaArgs[5], row, col);
  5334. var tickunitValue = unParseFormula(formulaArgs[6], row, col);
  5335. var colorSchemeValue = parseColorExpression(formulaArgs[7], row, col);
  5336. var verticalValue = formulaArgs[8] && (formulaArgs[8].type === ExpressionType.boolean ? formulaArgs[8].value : null);
  5337. setTextValue("bulletSparklineMeasure", measureValue);
  5338. setTextValue("bulletSparklineTarget", targetValue);
  5339. setTextValue("bulletSparklineMaxi", maxiValue);
  5340. setTextValue("bulletSparklineForecast", forecastValue);
  5341. setTextValue("bulletSparklineGood", goodValue);
  5342. setTextValue("bulletSparklineBad", badValue);
  5343. setTextValue("bulletSparklineTickUnit", tickunitValue);
  5344. setColorValue("bulletSparklineColorScheme", colorSchemeValue ? colorSchemeValue : defaultValue.colorScheme);
  5345. setCheckValue("bulletSparklineVertical", verticalValue ? verticalValue : defaultValue.vertical);
  5346. }
  5347. else {
  5348. setTextValue("bulletSparklineMeasure", "");
  5349. setTextValue("bulletSparklineTarget", "");
  5350. setTextValue("bulletSparklineMaxi", "");
  5351. setTextValue("bulletSparklineForecast", "");
  5352. setTextValue("bulletSparklineGood", "");
  5353. setTextValue("bulletSparklineBad", "");
  5354. setTextValue("bulletSparklineTickUnit", "");
  5355. setColorValue("bulletSparklineColorScheme", defaultValue.colorScheme);
  5356. setCheckValue("bulletSparklineVertical", defaultValue.vertical);
  5357. }
  5358. }
  5359. function getCascadeSparklineSetting(formulaArgs, row, col) {
  5360. var defaultValue = {colorPositive: "#8CBF64", colorNegative: "#D6604D", vertical: false};
  5361. if (formulaArgs && formulaArgs.length > 0) {
  5362. var pointsRangeValue = unParseFormula(formulaArgs[0], row, col);
  5363. var pointIndexValue = unParseFormula(formulaArgs[1], row, col);
  5364. var labelsRangeValue = unParseFormula(formulaArgs[2], row, col);
  5365. var minimumValue = unParseFormula(formulaArgs[3], row, col);
  5366. var maximumValue = unParseFormula(formulaArgs[4], row, col);
  5367. var colorPositiveValue = parseColorExpression(formulaArgs[5], row, col);
  5368. var colorNegativeValue = parseColorExpression(formulaArgs[6], row, col);
  5369. var verticalValue = formulaArgs[7] && (formulaArgs[7].type === ExpressionType.boolean ? formulaArgs[7].value : null);
  5370. setTextValue("cascadeSparklinePointsRange", pointsRangeValue);
  5371. setTextValue("cascadeSparklinePointIndex", pointIndexValue);
  5372. setTextValue("cascadeSparklineLabelsRange", labelsRangeValue);
  5373. setTextValue("cascadeSparklineMinimum", minimumValue);
  5374. setTextValue("cascadeSparklineMaximum", maximumValue);
  5375. setColorValue("cascadeSparklinePositiveColor", colorPositiveValue ? colorPositiveValue : defaultValue.colorPositive);
  5376. setColorValue("cascadeSparklineNegativeColor", colorNegativeValue ? colorNegativeValue : defaultValue.colorNegative);
  5377. setCheckValue("cascadeSparklineVertical", verticalValue ? verticalValue : defaultValue.vertical);
  5378. }
  5379. else {
  5380. setTextValue("cascadeSparklinePointsRange", "");
  5381. setTextValue("cascadeSparklinePointIndex", "");
  5382. setTextValue("cascadeSparklineLabelsRange", "");
  5383. setTextValue("cascadeSparklineMinimum", "");
  5384. setTextValue("cascadeSparklineMaximum", "");
  5385. setColorValue("cascadeSparklinePositiveColor", defaultValue.colorPositive);
  5386. setColorValue("cascadeSparklineNegativeColor", defaultValue.colorNegative);
  5387. setCheckValue("cascadeSparklineVertical", defaultValue.vertical);
  5388. }
  5389. }
  5390. function parseSetting(jsonSetting) {
  5391. var setting = {}, inBracket = false, inProperty = true, property = "", value = "";
  5392. if (jsonSetting) {
  5393. jsonSetting = jsonSetting.substr(1, jsonSetting.length - 2);
  5394. for (var i = 0, len = jsonSetting.length; i < len; i++) {
  5395. var char = jsonSetting.charAt(i);
  5396. if (char === ":") {
  5397. inProperty = false;
  5398. }
  5399. else if (char === "," && !inBracket) {
  5400. setting[property] = value;
  5401. property = "";
  5402. value = "";
  5403. inProperty = true;
  5404. }
  5405. else if (char === "\'" || char === "\"") {
  5406. // discard
  5407. }
  5408. else {
  5409. if (char === "(") {
  5410. inBracket = true;
  5411. }
  5412. else if (char === ")") {
  5413. inBracket = false;
  5414. }
  5415. if (inProperty) {
  5416. property += char;
  5417. }
  5418. else {
  5419. value += char;
  5420. }
  5421. }
  5422. }
  5423. if (property) {
  5424. setting[property] = value;
  5425. }
  5426. for (var p in setting) {
  5427. var v = setting[p];
  5428. if (v !== null && typeof (v) !== "undefined") {
  5429. if (v.toUpperCase() === "TRUE") {
  5430. setting[p] = true;
  5431. } else if (v.toUpperCase() === "FALSE") {
  5432. setting[p] = false;
  5433. } else if (!isNaN(v) && isFinite(v)) {
  5434. setting[p] = parseFloat(v);
  5435. }
  5436. }
  5437. }
  5438. }
  5439. return setting;
  5440. }
  5441. function updateManual(type, inputDataName) {
  5442. var $manualDiv = $("div.insp-text[data-name='" + inputDataName + "']");
  5443. var $manualInput = $manualDiv.find("input");
  5444. if (type !== "custom") {
  5445. $manualInput.attr("disabled", "disabled");
  5446. $manualDiv.addClass("manual-disable");
  5447. }
  5448. else {
  5449. $manualInput.removeAttr("disabled");
  5450. $manualDiv.removeClass("manual-disable");
  5451. }
  5452. }
  5453. function updateStyleSetting(settings) {
  5454. var defaultValue = {
  5455. negativePoints: "#A52A2A", markers: "#244062", highPoint: "#0000FF",
  5456. lowPoint: "#0000FF", firstPoint: "#95B3D7", lastPoint: "#95B3D7",
  5457. series: "#244062", axis: "#000000"
  5458. };
  5459. setColorValue("compatibleSparklineNegativeColor", settings.negativeColor ? settings.negativeColor : defaultValue.negativePoints);
  5460. setColorValue("compatibleSparklineMarkersColor", settings.markersColor ? settings.markersColor : defaultValue.markers);
  5461. setColorValue("compatibleSparklineAxisColor", settings.axisColor ? settings.axisColor : defaultValue.axis);
  5462. setColorValue("compatibleSparklineSeriesColor", settings.seriesColor ? settings.seriesColor : defaultValue.series);
  5463. setColorValue("compatibleSparklineHighMarkerColor", settings.highMarkerColor ? settings.highMarkerColor : defaultValue.highPoint);
  5464. setColorValue("compatibleSparklineLowMarkerColor", settings.lowMarkerColor ? settings.lowMarkerColor : defaultValue.lowPoint);
  5465. setColorValue("compatibleSparklineFirstMarkerColor", settings.firstMarkerColor ? settings.firstMarkerColor : defaultValue.firstPoint);
  5466. setColorValue("compatibleSparklineLastMarkerColor", settings.lastMarkerColor ? settings.lastMarkerColor : defaultValue.lastPoint);
  5467. setTextValue("compatibleSparklineLastLineWeight", settings.lineWeight || settings.lw);
  5468. }
  5469. function updateSparklineSetting(setting) {
  5470. if (!setting) {
  5471. return;
  5472. }
  5473. var defaultSetting = {
  5474. rightToLeft: false,
  5475. displayHidden: false,
  5476. displayXAxis: false,
  5477. showFirst: false,
  5478. showHigh: false,
  5479. showLast: false,
  5480. showLow: false,
  5481. showNegative: false,
  5482. showMarkers: false
  5483. };
  5484. setDropDownValue("emptyCellDisplayType", setting.displayEmptyCellsAs ? setting.displayEmptyCellsAs : -1);
  5485. setCheckValue("showDataInHiddenRowOrColumn", setting.displayHidden ? setting.displayHidden : defaultSetting.displayHidden);
  5486. setCheckValue("compatibleSparklineShowFirst", setting.showFirst ? setting.showFirst : defaultSetting.showFirst);
  5487. setCheckValue("compatibleSparklineShowLast", setting.showLast ? setting.showLast : defaultSetting.showLast);
  5488. setCheckValue("compatibleSparklineShowHigh", setting.showHigh ? setting.showHigh : defaultSetting.showHigh);
  5489. setCheckValue("compatibleSparklineShowLow", setting.showLow ? setting.showLow : defaultSetting.showLow);
  5490. setCheckValue("compatibleSparklineShowNegative", setting.showNegative ? setting.showNegative : defaultSetting.showNegative);
  5491. setCheckValue("compatibleSparklineShowMarkers", setting.showMarkers ? setting.showMarkers : defaultSetting.showMarkers);
  5492. var minAxisType = Sparklines.SparklineAxisMinMax[setting.minAxisType];
  5493. setDropDownValue("minAxisType", minAxisType ? minAxisType : -1);
  5494. setTextValue("manualMin", setting.manualMin ? setting.manualMin : "");
  5495. var maxAxisType = Sparklines.SparklineAxisMinMax[setting.maxAxisType];
  5496. setDropDownValue("maxAxisType", maxAxisType ? maxAxisType : -1);
  5497. setTextValue("manualMax", setting.manualMax ? setting.manualMax : "");
  5498. setCheckValue("rightToLeft", setting.rightToLeft ? setting.rightToLeft : defaultSetting.rightToLeft);
  5499. setCheckValue("displayXAxis", setting.displayXAxis ? setting.displayXAxis : defaultSetting.displayXAxis);
  5500. var type = getDropDownValue("minAxisType");
  5501. updateManual(type, "manualMin");
  5502. type = getDropDownValue("maxAxisType");
  5503. updateManual(type, "manualMax");
  5504. }
  5505. function getCompatibleSparklineSetting(formulaArgs, row, col) {
  5506. var sparklineSetting = {};
  5507. setTextValue("compatibleSparklineData", unParseFormula(formulaArgs[0], row, col));
  5508. setDropDownValue("dataOrientationType", formulaArgs[1].value);
  5509. if (formulaArgs[2]) {
  5510. setTextValue("compatibleSparklineDateAxisData", unParseFormula(formulaArgs[2], row, col));
  5511. }
  5512. else {
  5513. setTextValue("compatibleSparklineDateAxisData", "");
  5514. }
  5515. if (formulaArgs[3]) {
  5516. setDropDownValue("dateAxisOrientationType", formulaArgs[3].value);
  5517. }
  5518. else {
  5519. setDropDownValue("dateAxisOrientationType", -1);
  5520. }
  5521. var colorExpression = parseColorExpression(formulaArgs[4], row, col);
  5522. if (colorExpression) {
  5523. sparklineSetting = parseSetting(colorExpression);
  5524. }
  5525. updateSparklineSetting(sparklineSetting);
  5526. updateStyleSetting(sparklineSetting);
  5527. }
  5528. function getScatterSparklineSetting(formulaArgs, row, col) {
  5529. var defaultValue = {
  5530. tags: false,
  5531. drawSymbol: true,
  5532. drawLines: false,
  5533. dash: false,
  5534. color1: "#969696",
  5535. color2: "#CB0000"
  5536. };
  5537. var inputList = ["scatterSparklinePoints1", "scatterSparklinePoints2", "scatterSparklineMinX", "scatterSparklineMaxX",
  5538. "scatterSparklineMinY", "scatterSparklineMaxY", "scatterSparklineHLine", "scatterSparklineVLine",
  5539. "scatterSparklineXMinZone", "scatterSparklineXMaxZone", "scatterSparklineYMinZone", "scatterSparklineYMaxZone"];
  5540. for (var i = 0; i < inputList.length; i++) {
  5541. var formula = "";
  5542. if (formulaArgs[i]) {
  5543. formula = unParseFormula(formulaArgs[i], row, col);
  5544. }
  5545. setTextValue(inputList[i], formula);
  5546. }
  5547. var color1 = parseColorExpression(formulaArgs[15], row, col);
  5548. var color2 = parseColorExpression(formulaArgs[16], row, col);
  5549. var tags = formulaArgs[12] && (formulaArgs[12].type === ExpressionType.boolean ? formulaArgs[12].value : null);
  5550. var drawSymbol = formulaArgs[13] && (formulaArgs[13].type === ExpressionType.boolean ? formulaArgs[13].value : null);
  5551. var drawLines = formulaArgs[14] && (formulaArgs[14].type === ExpressionType.boolean ? formulaArgs[14].value : null);
  5552. var dashLine = formulaArgs[17] && (formulaArgs[17].type === ExpressionType.boolean ? formulaArgs[17].value : null);
  5553. setColorValue("scatterSparklineColor1", (color1 !== null) ? color1 : defaultValue.color1);
  5554. setColorValue("scatterSparklineColor2", (color2 !== null) ? color2 : defaultValue.color2);
  5555. setCheckValue("scatterSparklineTags", tags !== null ? tags : defaultValue.tags);
  5556. setCheckValue("scatterSparklineDrawSymbol", drawSymbol !== null ? drawSymbol : defaultValue.drawSymbol);
  5557. setCheckValue("scatterSparklineDrawLines", drawLines !== null ? drawLines : defaultValue.drawLines);
  5558. setCheckValue("scatterSparklineDashLine", dashLine !== null ? dashLine : defaultValue.dash);
  5559. }
  5560. function getHBarSparklineSetting(formulaArgs, row, col) {
  5561. var defaultValue = {colorScheme: "#969696"};
  5562. var value = unParseFormula(formulaArgs[0], row, col);
  5563. var colorScheme = parseColorExpression(formulaArgs[1], row, col);
  5564. setTextValue("hbarSparklineValue", value);
  5565. setColorValue("hbarSparklineColorScheme", (colorScheme !== null) ? colorScheme : defaultValue.colorScheme);
  5566. }
  5567. function getVBarSparklineSetting(formulaArgs, row, col) {
  5568. var defaultValue = {colorScheme: "#969696"};
  5569. var value = unParseFormula(formulaArgs[0], row, col);
  5570. var colorScheme = parseColorExpression(formulaArgs[1], row, col);
  5571. setTextValue("vbarSparklineValue", value);
  5572. setColorValue("vbarSparklineColorScheme", (colorScheme !== null) ? colorScheme : defaultValue.colorScheme);
  5573. }
  5574. function getParetoSparklineSetting(formulaArgs, row, col) {
  5575. var defaultValue = {label: 0, vertical: false};
  5576. if (formulaArgs && formulaArgs.length > 0) {
  5577. var pointsRangeValue = unParseFormula(formulaArgs[0], row, col);
  5578. var pointIndexValue = unParseFormula(formulaArgs[1], row, col);
  5579. var colorRangeValue = unParseFormula(formulaArgs[2], row, col);
  5580. var targetValue = unParseFormula(formulaArgs[3], row, col);
  5581. var target2Value = unParseFormula(formulaArgs[4], row, col);
  5582. var highlightPositionValue = unParseFormula(formulaArgs[5], row, col);
  5583. var labelValue = formulaArgs[6] && (formulaArgs[6].type === ExpressionType.number ? formulaArgs[6].value : null);
  5584. var verticalValue = formulaArgs[7] && (formulaArgs[7].type === ExpressionType.boolean ? formulaArgs[7].value : null);
  5585. setTextValue("paretoSparklinePoints", pointsRangeValue);
  5586. setTextValue("paretoSparklinePointIndex", pointIndexValue);
  5587. setTextValue("paretoSparklineColorRange", colorRangeValue);
  5588. setTextValue("paretoSparklineHighlightPosition", highlightPositionValue);
  5589. setTextValue("paretoSparklineTarget", targetValue);
  5590. setTextValue("paretoSparklineTarget2", target2Value);
  5591. setDropDownValue("paretoLabelType", labelValue === null ? defaultValue.label : labelValue);
  5592. setCheckValue("paretoSparklineVertical", verticalValue === null ? defaultValue.vertical : verticalValue);
  5593. }
  5594. else {
  5595. setTextValue("paretoSparklinePoints", "");
  5596. setTextValue("paretoSparklinePointIndex", "");
  5597. setTextValue("paretoSparklineColorRange", "");
  5598. setTextValue("paretoSparklineHighlightPosition", "");
  5599. setTextValue("paretoSparklineTarget", "");
  5600. setTextValue("paretoSparklineTarget2", "");
  5601. setDropDownValue("paretoLabelType", defaultValue.label);
  5602. setCheckValue("paretoSparklineVertical", defaultValue.vertical);
  5603. }
  5604. }
  5605. function getSpreadSparklineSetting(formulaArgs, row, col) {
  5606. var defaultValue = {showAverage: false, style: 4, colorScheme: "#646464", vertical: false};
  5607. if (formulaArgs && formulaArgs.length > 0) {
  5608. var pointsValue = unParseFormula(formulaArgs[0], row, col);
  5609. var showAverageValue = formulaArgs[1] && (formulaArgs[1].type === ExpressionType.boolean ? formulaArgs[1].value : null);
  5610. var scaleStartValue = unParseFormula(formulaArgs[2], row, col);
  5611. var scaleEndValue = unParseFormula(formulaArgs[3], row, col);
  5612. var styleValue = formulaArgs[4] ? unParseFormula(formulaArgs[4], row, col) : null;
  5613. var colorSchemeValue = parseColorExpression(formulaArgs[5], row, col);
  5614. var verticalValue = formulaArgs[6] && (formulaArgs[6].type === ExpressionType.boolean ? formulaArgs[6].value : null);
  5615. setTextValue("spreadSparklinePoints", pointsValue);
  5616. setCheckValue("spreadSparklineShowAverage", showAverageValue ? showAverageValue : defaultValue.showAverage);
  5617. setTextValue("spreadSparklineScaleStart", scaleStartValue);
  5618. setTextValue("spreadSparklineScaleEnd", scaleEndValue);
  5619. setDropDownValue("spreadSparklineStyleType", styleValue ? styleValue : defaultValue.style);
  5620. setColorValue("spreadSparklineColorScheme", colorSchemeValue ? colorSchemeValue : defaultValue.colorScheme);
  5621. setCheckValue("spreadSparklineVertical", verticalValue ? verticalValue : defaultValue.vertical);
  5622. }
  5623. else {
  5624. setTextValue("spreadSparklinePoints", "");
  5625. setCheckValue("spreadSparklineShowAverage", defaultValue.showAverage);
  5626. setTextValue("spreadSparklineScaleStart", "");
  5627. setTextValue("spreadSparklineScaleEnd", "");
  5628. setDropDownValue("spreadSparklineStyleType", defaultValue.style);
  5629. setColorValue("spreadSparklineColorScheme", defaultValue.colorScheme);
  5630. setCheckValue("spreadSparklineVertical", defaultValue.vertical);
  5631. }
  5632. }
  5633. function getStackedSparklineSetting(formulaArgs, row, col) {
  5634. var defaultValue = {color: "#646464", vertical: false, textOrientation: 0};
  5635. if (formulaArgs && formulaArgs.length > 0) {
  5636. var pointsValue = unParseFormula(formulaArgs[0], row, col);
  5637. var colorRangeValue = unParseFormula(formulaArgs[1], row, col);
  5638. var labelRangeValue = unParseFormula(formulaArgs[2], row, col);
  5639. var maximumValue = unParseFormula(formulaArgs[3], row, col);
  5640. var targetRedValue = unParseFormula(formulaArgs[4], row, col);
  5641. var targetGreenValue = unParseFormula(formulaArgs[5], row, col);
  5642. var targetBlueValue = unParseFormula(formulaArgs[6], row, col);
  5643. var targetYellowValue = unParseFormula(formulaArgs[7], row, col);
  5644. var colorValue = parseColorExpression(formulaArgs[8], row, col);
  5645. var highlightPositionValue = unParseFormula(formulaArgs[9], row, col);
  5646. var verticalValue = formulaArgs[10] && (formulaArgs[10].type === ExpressionType.boolean ? formulaArgs[10].value : null);
  5647. var textOrientationValue = unParseFormula(formulaArgs[11], row, col);
  5648. var textSizeValue = unParseFormula(formulaArgs[12], row, col);
  5649. setTextValue("stackedSparklinePoints", pointsValue);
  5650. setTextValue("stackedSparklineColorRange", colorRangeValue);
  5651. setTextValue("stackedSparklineLabelRange", labelRangeValue);
  5652. setNumberValue("stackedSparklineMaximum", maximumValue);
  5653. setNumberValue("stackedSparklineTargetRed", targetRedValue);
  5654. setNumberValue("stackedSparklineTargetGreen", targetGreenValue);
  5655. setNumberValue("stackedSparklineTargetBlue", targetBlueValue);
  5656. setNumberValue("stackedSparklineTargetYellow", targetYellowValue);
  5657. setColorValue("stackedSparklineColor", "stacked-color-span", colorValue ? colorValue : defaultValue.color);
  5658. setNumberValue("stackedSparklineHighlightPosition", highlightPositionValue);
  5659. setCheckValue("stackedSparklineVertical", verticalValue ? verticalValue : defaultValue.vertical);
  5660. setDropDownValue("stackedSparklineTextOrientation", textOrientationValue ? textOrientationValue : defaultValue.textOrientation);
  5661. setNumberValue("stackedSparklineTextSize", textSizeValue);
  5662. }
  5663. else {
  5664. setTextValue("stackedSparklinePoints", "");
  5665. setTextValue("stackedSparklineColorRange", "");
  5666. setTextValue("stackedSparklineLabelRange", "");
  5667. setNumberValue("stackedSparklineMaximum", "");
  5668. setNumberValue("stackedSparklineTargetRed", "");
  5669. setNumberValue("stackedSparklineTargetGreen", "");
  5670. setNumberValue("stackedSparklineTargetBlue", "");
  5671. setNumberValue("stackedSparklineTargetYellow", "");
  5672. setColorValue("stackedSparklineColor", "stacked-color-span", defaultValue.color);
  5673. setNumberValue("stackedSparklineHighlightPosition", "");
  5674. setCheckValue("stackedSparklineVertical", defaultValue.vertical);
  5675. setDropDownValue("stackedSparklineTextOrientation", defaultValue.textOrientation);
  5676. setNumberValue("stackedSparklineTextSize", "");
  5677. }
  5678. }
  5679. function getVariSparklineSetting(formulaArgs, row, col) {
  5680. var defaultValue = {legend: false, colorPositive: "green", colorNegative: "red", vertical: false};
  5681. if (formulaArgs && formulaArgs.length > 0) {
  5682. var varianceValue = unParseFormula(formulaArgs[0], row, col);
  5683. var referenceValue = unParseFormula(formulaArgs[1], row, col);
  5684. var miniValue = unParseFormula(formulaArgs[2], row, col);
  5685. var maxiValue = unParseFormula(formulaArgs[3], row, col);
  5686. var markValue = unParseFormula(formulaArgs[4], row, col);
  5687. var tickunitValue = unParseFormula(formulaArgs[5], row, col);
  5688. var legendValue = formulaArgs[6] && (formulaArgs[6].type === ExpressionType.boolean ? formulaArgs[6].value : null);
  5689. var colorPositiveValue = parseColorExpression(formulaArgs[7], row, col);
  5690. var colorNegativeValue = parseColorExpression(formulaArgs[8], row, col);
  5691. var verticalValue = formulaArgs[9] && (formulaArgs[9].type === ExpressionType.boolean ? formulaArgs[9].value : null);
  5692. setTextValue("variSparklineVariance", varianceValue);
  5693. setTextValue("variSparklineReference", referenceValue);
  5694. setTextValue("variSparklineMini", miniValue);
  5695. setTextValue("variSparklineMaxi", maxiValue);
  5696. setTextValue("variSparklineMark", markValue);
  5697. setTextValue("variSparklineTickUnit", tickunitValue);
  5698. setColorValue("variSparklineColorPositive", colorPositiveValue ? colorPositiveValue : defaultValue.colorPositive);
  5699. setColorValue("variSparklineColorNegative", colorNegativeValue ? colorNegativeValue : defaultValue.colorNegative);
  5700. setCheckValue("variSparklineLegend", legendValue);
  5701. setCheckValue("variSparklineVertical", verticalValue);
  5702. }
  5703. else {
  5704. setTextValue("variSparklineVariance", "");
  5705. setTextValue("variSparklineReference", "");
  5706. setTextValue("variSparklineMini", "");
  5707. setTextValue("variSparklineMaxi", "");
  5708. setTextValue("variSparklineMark", "");
  5709. setTextValue("variSparklineTickUnit", "");
  5710. setColorValue("variSparklineColorPositive", defaultValue.colorPositive);
  5711. setColorValue("variSparklineColorNegative", defaultValue.colorNegative);
  5712. setCheckValue("variSparklineLegend", defaultValue.legend);
  5713. setCheckValue("variSparklineVertical", defaultValue.vertical);
  5714. }
  5715. }
  5716. function getMonthSparklineSetting(formulaArgs, row, col) {
  5717. var year = "", month = "", dataRangeStr = "", emptyColor = "lightgray", startColor = "lightgreen", middleColor = "green", endColor = "darkgreen", colorRangeStr = "";
  5718. if (formulaArgs) {
  5719. if (formulaArgs.length === 7) {
  5720. year = unParseFormula(formulaArgs[0], row, col);
  5721. month = unParseFormula(formulaArgs[1], row, col);
  5722. dataRangestr = unParseFormula(formulaArgs[2], row, col);
  5723. emptyColor = parseColorExpression(formulaArgs[3], row, col);
  5724. startColor = parseColorExpression(formulaArgs[4], row, col);
  5725. middleColor = parseColorExpression(formulaArgs[5], row, col);
  5726. endColor = parseColorExpression(formulaArgs[6], row, col);
  5727. setTextValue("monthSparklineYear", year);
  5728. setTextValue("monthSparklineMonth", month);
  5729. setTextValue("monthSparklineData", dataRangestr);
  5730. setColorValue("monthSparklineEmptyColor", emptyColor);
  5731. setColorValue("monthSparklineStartColor", startColor);
  5732. setColorValue("monthSparklineMiddleColor", middleColor);
  5733. setColorValue("monthSparklineEndColor", endColor);
  5734. setTextValue("monthSparklineColorRange", "");
  5735. } else {
  5736. year = unParseFormula(formulaArgs[0], row, col);
  5737. month = unParseFormula(formulaArgs[1], row, col);
  5738. dataRangestr = unParseFormula(formulaArgs[2], row, col);
  5739. colorRangeStr = unParseFormula(formulaArgs[3], row, col);
  5740. setTextValue("monthSparklineYear", year);
  5741. setTextValue("monthSparklineMonth", month);
  5742. setTextValue("monthSparklineData", dataRangestr);
  5743. setColorValue("monthSparklineEmptyColor", emptyColor);
  5744. setColorValue("monthSparklineStartColor", startColor);
  5745. setColorValue("monthSparklineMiddleColor", middleColor);
  5746. setColorValue("monthSparklineEndColor", endColor);
  5747. setTextValue("monthSparklineColorRange", colorRangeStr);
  5748. }
  5749. } else {
  5750. setTextValue("monthSparklineYear", year);
  5751. setTextValue("monthSparklineMonth", month);
  5752. setTextValue("monthSparklineData", dataRangestr);
  5753. setColorValue("monthSparklineEmptyColor", emptyColor);
  5754. setColorValue("monthSparklineStartColor", startColor);
  5755. setColorValue("monthSparklineMiddleColor", middleColor);
  5756. setColorValue("monthSparklineEndColor", endColor);
  5757. setTextValue("monthSparklineColorRange", colorRangeStr);
  5758. }
  5759. }
  5760. function getYearSparklineSetting(formulaArgs, row, col) {
  5761. var year = "", month = "", dataRangeStr = "", emptyColor = "lightgray", startColor = "lightgreen", middleColor = "green", endColor = "darkgreen", colorRangeStr = "";
  5762. if (formulaArgs) {
  5763. if (formulaArgs.length === 6) {
  5764. year = unParseFormula(formulaArgs[0], row, col);
  5765. dataRangestr = unParseFormula(formulaArgs[1], row, col);
  5766. emptyColor = parseColorExpression(formulaArgs[2], row, col);
  5767. startColor = parseColorExpression(formulaArgs[3], row, col);
  5768. middleColor = parseColorExpression(formulaArgs[4], row, col);
  5769. endColor = parseColorExpression(formulaArgs[5], row, col);
  5770. setTextValue("yearSparklineYear", year);
  5771. setTextValue("yearSparklineData", dataRangestr);
  5772. setColorValue("yearSparklineEmptyColor", emptyColor);
  5773. setColorValue("yearSparklineStartColor", startColor);
  5774. setColorValue("yearSparklineMiddleColor", middleColor);
  5775. setColorValue("yearSparklineEndColor", endColor);
  5776. setTextValue("yearSparklineColorRange", "");
  5777. } else {
  5778. year = unParseFormula(formulaArgs[0], row, col);
  5779. dataRangestr = unParseFormula(formulaArgs[1], row, col);
  5780. colorRangeStr = unParseFormula(formulaArgs[2], row, col);
  5781. setTextValue("yearSparklineYear", year);
  5782. setTextValue("yearSparklineData", dataRangestr);
  5783. setColorValue("yearSparklineEmptyColor", emptyColor);
  5784. setColorValue("yearSparklineStartColor", startColor);
  5785. setColorValue("yearSparklineMiddleColor", middleColor);
  5786. setColorValue("yearSparklineEndColor", endColor);
  5787. setTextValue("yearSparklineColorRange", colorRangeStr);
  5788. }
  5789. } else {
  5790. setTextValue("yearSparklineYear", year);
  5791. setTextValue("yearSparklineData", dataRangestr);
  5792. setColorValue("yearSparklineEmptyColor", emptyColor);
  5793. setColorValue("yearSparklineStartColor", startColor);
  5794. setColorValue("yearSparklineMiddleColor", middleColor);
  5795. setColorValue("yearSparklineEndColor", endColor);
  5796. setTextValue("yearSparklineColorRange", colorRangeStr);
  5797. }
  5798. }
  5799. function addPieSparklineColor(count, color, isMinusSymbol) {
  5800. var defaultColor = "rgb(237, 237, 237)";
  5801. color = color ? color : defaultColor;
  5802. var symbolFunClass, symbolClass;
  5803. if (isMinusSymbol) {
  5804. symbolFunClass = "remove-pie-color";
  5805. symbolClass = "ui-pie-sparkline-icon-minus";
  5806. }
  5807. else {
  5808. symbolFunClass = "add-pie-color";
  5809. symbolClass = "ui-pie-sparkline-icon-plus";
  5810. }
  5811. var $pieSparklineColorContainer = $("#pieSparklineColorContainer");
  5812. var pieColorDataName = "pieColorName";
  5813. var $colorDiv = $("<div>" +
  5814. "<div class=\"insp-row\">" +
  5815. "<div>" +
  5816. "<div class=\"insp-color-picker insp-inline-row\" data-name=\"" + pieColorDataName + count + "\">" +
  5817. "<div class=\"title insp-inline-row-item insp-col-6 localize\">" + uiResource.sparklineExTab.pieSparkline.values.color + count + "</div>" +
  5818. "<div class=\"picker insp-inline-row-item insp-col-4\">" +
  5819. "<div style=\"width: 100%; height: 100%\">" +
  5820. "<div class=\"color-view\" style=\"background-color: " + color + ";\"></div>" +
  5821. "</div>" +
  5822. "</div>" +
  5823. "<div class=\"" + symbolFunClass + " insp-inline-row-item insp-col-2\"><span class=\"ui-pie-sparkline-icon " + symbolClass + "\"></span></div>" +
  5824. "</div>" +
  5825. "</div>" +
  5826. "</div>" +
  5827. "</div>");
  5828. $colorDiv.appendTo($pieSparklineColorContainer);
  5829. }
  5830. function addPieColor(count, color, isMinusSymbol) {
  5831. var $colorSpanDiv = $(".add-pie-color");
  5832. $colorSpanDiv.addClass("remove-pie-color").removeClass("add-pie-color");
  5833. $colorSpanDiv.find("span").addClass("ui-pie-sparkline-icon-minus").removeClass("ui-pie-sparkline-icon-plus");
  5834. addPieSparklineColor(count, color, isMinusSymbol);
  5835. $(".add-pie-color").unbind("click");
  5836. $(".add-pie-color").bind("click", function (evt) {
  5837. var count = $("#pieSparklineColorContainer").find("span").length;
  5838. addPieColor(count + 1);
  5839. });
  5840. $(".remove-pie-color").unbind("click");
  5841. $(".remove-pie-color").bind("click", function (evt) {
  5842. resetPieColor($(evt.target));
  5843. });
  5844. $("div.insp-color-picker .picker").click(showColorPicker);
  5845. }
  5846. function resetPieColor($colorSpanDiv) {
  5847. if (!$colorSpanDiv.hasClass("ui-pie-sparkline-icon")) {
  5848. return;
  5849. }
  5850. $colorDiv = $colorSpanDiv.parent().parent().parent().parent().parent();
  5851. $colorDiv.remove();
  5852. var $pieSparklineColorContainer = $("#pieSparklineColorContainer");
  5853. var colorArray = [];
  5854. $pieSparklineColorContainer.find(".color-view").each(function () {
  5855. colorArray.push($(this).css("background-color"));
  5856. });
  5857. $pieSparklineColorContainer.empty();
  5858. addMultiPieColor(colorArray);
  5859. }
  5860. function addMultiPieColor(colorArray) {
  5861. if (!colorArray || colorArray.length === 0) {
  5862. return;
  5863. }
  5864. var length = colorArray.length;
  5865. var i = 0;
  5866. for (i; i < length - 1; i++) {
  5867. addPieSparklineColor(i + 1, colorArray[i], true);
  5868. }
  5869. addPieColor(i + 1, colorArray[i]);
  5870. }
  5871. function getPieSparklineSetting(formulaArgs, row, col) {
  5872. var agrsLength = formulaArgs.length;
  5873. if (formulaArgs && agrsLength > 0) {
  5874. var range = unParseFormula(formulaArgs[0], row, col);
  5875. setTextValue("pieSparklinePercentage", range);
  5876. var actualLen = agrsLength - 1;
  5877. if (actualLen === 0) {
  5878. addPieColor(1);
  5879. }
  5880. else {
  5881. var colorArray = [];
  5882. for (var i = 1; i <= actualLen; i++) {
  5883. var colorItem = null;
  5884. var color = parseColorExpression(formulaArgs[i], row, col);
  5885. colorArray.push(color);
  5886. }
  5887. addMultiPieColor(colorArray);
  5888. }
  5889. }
  5890. }
  5891. var sparklineName;
  5892. function showSparklineSetting(row, col) {
  5893. var expr = parseFormulaSparkline(row, col);
  5894. if (!expr || !expr.arguments) {
  5895. return false;
  5896. }
  5897. var formulaSparkline = spread.getSparklineEx(expr.functionName);
  5898. if (formulaSparkline) {
  5899. var $sparklineSettingDiv = $("#sparklineExTab>div>div");
  5900. var formulaArgs = expr.arguments;
  5901. $sparklineSettingDiv.hide();
  5902. if (formulaSparkline instanceof Sparklines.PieSparkline) {
  5903. $("#pieSparklineSetting").show();
  5904. $("#pieSparklineColorContainer").empty();
  5905. getPieSparklineSetting(formulaArgs, row, col);
  5906. return true;
  5907. }
  5908. else if (formulaSparkline instanceof Sparklines.AreaSparkline) {
  5909. $("#areaSparklineSetting").show();
  5910. getAreaSparklineSetting(formulaArgs, row, col);
  5911. return true;
  5912. }
  5913. else if (formulaSparkline instanceof Sparklines.BoxPlotSparkline) {
  5914. $("#boxplotSparklineSetting").show();
  5915. getBoxPlotSparklineSetting(formulaArgs, row, col);
  5916. return true;
  5917. }
  5918. else if (formulaSparkline instanceof Sparklines.BulletSparkline) {
  5919. $("#bulletSparklineSetting").show();
  5920. getBulletSparklineSetting(formulaArgs, row, col);
  5921. return true;
  5922. }
  5923. else if (formulaSparkline instanceof Sparklines.CascadeSparkline) {
  5924. $("#cascadeSparklineSetting").show();
  5925. getCascadeSparklineSetting(formulaArgs, row, col);
  5926. return true;
  5927. }
  5928. else if (formulaSparkline instanceof Sparklines.LineSparkline || formulaSparkline instanceof Sparklines.ColumnSparkline || formulaSparkline instanceof Sparklines.WinlossSparkline) {
  5929. $("#compatibleSparklineSetting").show();
  5930. if (expr.function.name) {
  5931. sparklineName = expr.function.name;
  5932. }
  5933. getCompatibleSparklineSetting(formulaArgs, row, col);
  5934. return true;
  5935. }
  5936. else if (formulaSparkline instanceof Sparklines.ScatterSparkline) {
  5937. $("#scatterSparklineSetting").show();
  5938. getScatterSparklineSetting(formulaArgs, row, col);
  5939. return true;
  5940. }
  5941. else if (formulaSparkline instanceof Sparklines.HBarSparkline) {
  5942. $("#hbarSparklineSetting").show();
  5943. getHBarSparklineSetting(formulaArgs, row, col);
  5944. return true;
  5945. }
  5946. else if (formulaSparkline instanceof Sparklines.VBarSparkline) {
  5947. $("#vbarSparklineSetting").show();
  5948. getVBarSparklineSetting(formulaArgs, row, col);
  5949. return true;
  5950. }
  5951. else if (formulaSparkline instanceof Sparklines.ParetoSparkline) {
  5952. $("#paretoSparklineSetting").show();
  5953. getParetoSparklineSetting(formulaArgs, row, col);
  5954. return true;
  5955. }
  5956. else if (formulaSparkline instanceof Sparklines.SpreadSparkline) {
  5957. $("#spreadSparklineSetting").show();
  5958. getSpreadSparklineSetting(formulaArgs, row, col);
  5959. return true;
  5960. }
  5961. else if (formulaSparkline instanceof Sparklines.StackedSparkline) {
  5962. $("#stackedSparklineSetting").show();
  5963. getStackedSparklineSetting(formulaArgs, row, col);
  5964. return true;
  5965. }
  5966. else if (formulaSparkline instanceof Sparklines.VariSparkline) {
  5967. $("#variSparklineSetting").show();
  5968. getVariSparklineSetting(formulaArgs, row, col);
  5969. return true;
  5970. }
  5971. else if (formulaSparkline instanceof Sparklines.MonthSparkline) {
  5972. $("#monthSparklineSetting").show();
  5973. getMonthSparklineSetting(formulaArgs, row, col);
  5974. return true;
  5975. }
  5976. else if (formulaSparkline instanceof Sparklines.YearSparkline) {
  5977. $("#yearSparklineSetting").show();
  5978. getYearSparklineSetting(formulaArgs, row, col);
  5979. return true;
  5980. }
  5981. }
  5982. return false;
  5983. }
  5984. function attachSparklineSettingEvents() {
  5985. $("#setAreaSparkline").click(applyAreaSparklineSetting);
  5986. $("#setBoxPlotSparkline").click(applyBoxPlotSparklineSetting);
  5987. $("#setBulletSparkline").click(applyBulletSparklineSetting);
  5988. $("#setCascadeSparkline").click(applyCascadeSparklineSetting);
  5989. $("#setCompatibleSparkline").click(applyCompatibleSparklineSetting);
  5990. $("#setScatterSparkline").click(applyScatterSparklineSetting);
  5991. $("#setHbarSparkline").click(applyHbarSparklineSetting);
  5992. $("#setVbarSparkline").click(applyVbarSparklineSetting);
  5993. $("#setParetoSparkline").click(applyParetoSparklineSetting);
  5994. $("#setSpreadSparkline").click(applySpreadSparklineSetting);
  5995. $("#setStackedSparkline").click(applyStackedSparklineSetting);
  5996. $("#setVariSparkline").click(applyVariSparklineSetting);
  5997. $("#setPieSparkline").click(applyPieSparklineSetting);
  5998. $("#setMonthSparkline").click(applyMonthSparklineSetting);
  5999. $("#setYearSparkline").click(applyYearSparklineSetting);
  6000. }
  6001. function updateFormulaBar() {
  6002. var sheet = spread.getActiveSheet();
  6003. var formulaBar = $("#formulabox");
  6004. if (formulaBar.length > 0) {
  6005. var formula = sheet.getFormula(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex());
  6006. if (formula) {
  6007. formula = "=" + formula;
  6008. formulaBar.text(formula);
  6009. }
  6010. }
  6011. }
  6012. function removeContinuousComma(parameter) {
  6013. var len = parameter.length;
  6014. while (len > 0 && parameter[len - 1] === ",") {
  6015. len--;
  6016. }
  6017. return parameter.substr(0, len);
  6018. }
  6019. function formatFormula(paraArray) {
  6020. var params = "";
  6021. for (var i = 0; i < paraArray.length; i++) {
  6022. var item = paraArray[i];
  6023. if (item !== undefined && item !== null) {
  6024. params += item + ",";
  6025. }
  6026. else {
  6027. params += ",";
  6028. }
  6029. }
  6030. params = removeContinuousComma(params);
  6031. return params;
  6032. }
  6033. function getFormula(params) {
  6034. var len = params.length;
  6035. while (len > 0 && params[len - 1] === "") {
  6036. len--;
  6037. }
  6038. var temp = "";
  6039. for (var i = 0; i < len; i++) {
  6040. temp += params[i];
  6041. if (i !== len - 1) {
  6042. temp += ",";
  6043. }
  6044. }
  6045. return "=AREASPARKLINE(" + temp + ")";
  6046. }
  6047. function setFormulaSparkline(formula) {
  6048. var sheet = spread.getActiveSheet();
  6049. var row = sheet.getActiveRowIndex();
  6050. var col = sheet.getActiveColumnIndex();
  6051. if (formula) {
  6052. sheet.setFormula(row, col, formula);
  6053. }
  6054. }
  6055. function applyAreaSparklineSetting() {
  6056. var points = getTextValue("areaSparklinePoints");
  6057. var mini = getNumberValue("areaSparklineMinimumValue");
  6058. var maxi = getNumberValue("areaSparklineMaximumValue");
  6059. var line1 = getNumberValue("areaSparklineLine1");
  6060. var line2 = getNumberValue("areaSparklineLine2");
  6061. var colorPositive = "\"" + getBackgroundColor("areaSparklinePositiveColor") + "\"";
  6062. var colorNegative = "\"" + getBackgroundColor("areaSparklineNegativeColor") + "\"";
  6063. var paramArr = [points, mini, maxi, line1, line2, colorPositive, colorNegative];
  6064. var formula = getFormula(paramArr);
  6065. setFormulaSparkline(formula);
  6066. updateFormulaBar();
  6067. }
  6068. function applyBoxPlotSparklineSetting() {
  6069. var pointsValue = getTextValue("boxplotSparklinePoints");
  6070. var boxPlotClassValue = getDropDownValue("boxplotClassType");
  6071. var showAverageValue = getCheckValue("boxplotSparklineShowAverage");
  6072. var scaleStartValue = getTextValue("boxplotSparklineScaleStart");
  6073. var scaleEndValue = getTextValue("boxplotSparklineScaleEnd");
  6074. var acceptableStartValue = getTextValue("boxplotSparklineAcceptableStart");
  6075. var acceptableEndValue = getTextValue("boxplotSparklineAcceptableEnd");
  6076. var colorValue = getBackgroundColor("boxplotSparklineColorScheme");
  6077. var styleValue = getDropDownValue("boxplotSparklineStyleType");
  6078. var verticalValue = getCheckValue("boxplotSparklineVertical");
  6079. var boxplotClassStr = boxPlotClassValue ? "\"" + boxPlotClassValue + "\"" : null;
  6080. var colorStr = colorValue ? "\"" + colorValue + "\"" : null;
  6081. var paraPool = [
  6082. pointsValue,
  6083. boxplotClassStr,
  6084. showAverageValue,
  6085. scaleStartValue,
  6086. scaleEndValue,
  6087. acceptableStartValue,
  6088. acceptableEndValue,
  6089. colorStr,
  6090. styleValue,
  6091. verticalValue
  6092. ];
  6093. var params = formatFormula(paraPool);
  6094. var formula = "=BOXPLOTSPARKLINE(" + params + ")";
  6095. setFormulaSparkline(formula);
  6096. updateFormulaBar();
  6097. }
  6098. function applyBulletSparklineSetting() {
  6099. var measureValue = getTextValue("bulletSparklineMeasure");
  6100. var targetValue = getTextValue("bulletSparklineTarget");
  6101. var maxiValue = getTextValue("bulletSparklineMaxi");
  6102. var goodValue = getTextValue("bulletSparklineGood");
  6103. var badValue = getTextValue("bulletSparklineBad");
  6104. var forecastValue = getTextValue("bulletSparklineForecast");
  6105. var tickunitValue = getTextValue("bulletSparklineTickUnit");
  6106. var colorSchemeValue = getBackgroundColor("bulletSparklineColorScheme");
  6107. var verticalValue = getCheckValue("bulletSparklineVertical");
  6108. var colorSchemeString = colorSchemeValue ? "\"" + colorSchemeValue + "\"" : null;
  6109. var paraPool = [
  6110. measureValue,
  6111. targetValue,
  6112. maxiValue,
  6113. goodValue,
  6114. badValue,
  6115. forecastValue,
  6116. tickunitValue,
  6117. colorSchemeString,
  6118. verticalValue
  6119. ];
  6120. var params = formatFormula(paraPool);
  6121. var formula = "=BULLETSPARKLINE(" + params + ")";
  6122. var sheet = spread.getActiveSheet();
  6123. var sels = sheet.getSelections();
  6124. setFormulaSparkline(formula);
  6125. updateFormulaBar();
  6126. }
  6127. function applyCascadeSparklineSetting() {
  6128. var pointsRangeValue = getTextValue("cascadeSparklinePointsRange");
  6129. var pointIndexValue = getTextValue("cascadeSparklinePointIndex");
  6130. var labelsRangeValue = getTextValue("cascadeSparklineLabelsRange");
  6131. var minimumValue = getTextValue("cascadeSparklineMinimum");
  6132. var maximumValue = getTextValue("cascadeSparklineMaximum");
  6133. var colorPositiveValue = getBackgroundColor("cascadeSparklinePositiveColor");
  6134. var colorNegativeValue = getBackgroundColor("cascadeSparklineNegativeColor");
  6135. var verticalValue = getCheckValue("cascadeSparklineVertical");
  6136. var colorPositiveStr = colorPositiveValue ? "\"" + colorPositiveValue + "\"" : null;
  6137. var colorNegativeStr = colorNegativeValue ? "\"" + colorNegativeValue + "\"" : null;
  6138. paraPool = [
  6139. pointsRangeValue,
  6140. pointIndexValue,
  6141. labelsRangeValue,
  6142. minimumValue,
  6143. maximumValue,
  6144. colorPositiveStr,
  6145. colorNegativeStr,
  6146. verticalValue
  6147. ];
  6148. var params = formatFormula(paraPool);
  6149. var formula = "=CASCADESPARKLINE(" + params + ")";
  6150. setFormulaSparkline(formula);
  6151. updateFormulaBar();
  6152. }
  6153. function applyCompatibleSparklineSetting() {
  6154. var data = getTextValue("compatibleSparklineData");
  6155. var dataOrientation = getDropDownValue("dataOrientationType");
  6156. var dateAxisData = getTextValue("compatibleSparklineDateAxisData");
  6157. var dateAxisOrientation = getDropDownValue("dateAxisOrientationType");
  6158. if (dateAxisOrientation === undefined) {
  6159. dateAxisOrientation = "";
  6160. }
  6161. var sparklineSetting = {}, minAxisType, maxAxisType;
  6162. sparklineSetting.displayEmptyCellsAs = getDropDownValue("emptyCellDisplayType");
  6163. sparklineSetting.displayHidden = getCheckValue("showDataInHiddenRowOrColumn");
  6164. sparklineSetting.showFirst = getCheckValue("compatibleSparklineShowFirst");
  6165. sparklineSetting.showLast = getCheckValue("compatibleSparklineShowLast");
  6166. sparklineSetting.showHigh = getCheckValue("compatibleSparklineShowHigh");
  6167. sparklineSetting.showLow = getCheckValue("compatibleSparklineShowLow");
  6168. sparklineSetting.showNegative = getCheckValue("compatibleSparklineShowNegative");
  6169. sparklineSetting.showMarkers = getCheckValue("compatibleSparklineShowMarkers");
  6170. minAxisType = getDropDownValue("minAxisType");
  6171. sparklineSetting.minAxisType = Sparklines.SparklineAxisMinMax[minAxisType];
  6172. sparklineSetting.manualMin = getTextValue("manualMin");
  6173. maxAxisType = getDropDownValue("maxAxisType");
  6174. sparklineSetting.maxAxisType = Sparklines.SparklineAxisMinMax[maxAxisType];
  6175. sparklineSetting.manualMax = getTextValue("manualMax");
  6176. sparklineSetting.rightToLeft = getCheckValue("rightToLeft");
  6177. sparklineSetting.displayXAxis = getCheckValue("displayXAxis");
  6178. sparklineSetting.negativeColor = getBackgroundColor("compatibleSparklineNegativeColor");
  6179. sparklineSetting.markersColor = getBackgroundColor("compatibleSparklineMarkersColor");
  6180. sparklineSetting.axisColor = getBackgroundColor("compatibleSparklineAxisColor");
  6181. sparklineSetting.seriesColor = getBackgroundColor("compatibleSparklineSeriesColor");
  6182. sparklineSetting.highMarkerColor = getBackgroundColor("compatibleSparklineHighMarkerColor");
  6183. sparklineSetting.lowMarkerColor = getBackgroundColor("compatibleSparklineLowMarkerColor");
  6184. sparklineSetting.firstMarkerColor = getBackgroundColor("compatibleSparklineFirstMarkerColor");
  6185. sparklineSetting.lastMarkerColor = getBackgroundColor("compatibleSparklineLastMarkerColor");
  6186. sparklineSetting.lineWeight = getTextValue("compatibleSparklineLastLineWeight");
  6187. var settingArray = [];
  6188. for (var item in sparklineSetting) {
  6189. if (sparklineSetting[item] !== undefined && sparklineSetting[item] !== "") {
  6190. settingArray.push(item + ":" + sparklineSetting[item]);
  6191. }
  6192. }
  6193. var settingString = "";
  6194. if (settingArray.length > 0) {
  6195. settingString = "\"{" + settingArray.join(",") + "}\"";
  6196. }
  6197. var formula = "";
  6198. if (settingString !== "") {
  6199. formula = "=" + sparklineName + "(" + data + "," + dataOrientation +
  6200. "," + dateAxisData + "," + dateAxisOrientation + "," + settingString + ")";
  6201. }
  6202. else {
  6203. if (dateAxisOrientation !== "") {
  6204. formula = "=" + sparklineName + "(" + data + "," + dataOrientation +
  6205. "," + dateAxisData + "," + dateAxisOrientation + ")";
  6206. }
  6207. else {
  6208. if (dateAxisData !== "") {
  6209. formula = "=" + sparklineName + "(" + data + "," + dataOrientation +
  6210. "," + dateAxisData + ")";
  6211. }
  6212. else {
  6213. formula = "=" + sparklineName + "(" + data + "," + dataOrientation + ")";
  6214. }
  6215. }
  6216. }
  6217. setFormulaSparkline(formula);
  6218. updateFormulaBar();
  6219. }
  6220. function applyScatterSparklineSetting() {
  6221. var paraPool = [];
  6222. var inputList = ["scatterSparklinePoints1", "scatterSparklinePoints2", "scatterSparklineMinX", "scatterSparklineMaxX",
  6223. "scatterSparklineMinY", "scatterSparklineMaxY", "scatterSparklineHLine", "scatterSparklineVLine",
  6224. "scatterSparklineXMinZone", "scatterSparklineXMaxZone", "scatterSparklineYMinZone", "scatterSparklineYMaxZone"];
  6225. for (var i = 0; i < inputList.length; i++) {
  6226. var textValue = getTextValue(inputList[i]);
  6227. paraPool.push(textValue);
  6228. }
  6229. var tags = getCheckValue("scatterSparklineTags");
  6230. var drawSymbol = getCheckValue("scatterSparklineDrawSymbol");
  6231. var drawLines = getCheckValue("scatterSparklineDrawLines");
  6232. var color1 = getBackgroundColor("scatterSparklineColor1");
  6233. var color2 = getBackgroundColor("scatterSparklineColor2");
  6234. var dashLine = getCheckValue("scatterSparklineDashLine");
  6235. color1 = color1 ? "\"" + color1 + "\"" : null;
  6236. color2 = color2 ? "\"" + color2 + "\"" : null;
  6237. paraPool.push(tags);
  6238. paraPool.push(drawSymbol);
  6239. paraPool.push(drawLines);
  6240. paraPool.push(color1);
  6241. paraPool.push(color2);
  6242. paraPool.push(dashLine);
  6243. var params = formatFormula(paraPool);
  6244. var formula = "=SCATTERSPARKLINE(" + params + ")";
  6245. setFormulaSparkline(formula);
  6246. updateFormulaBar();
  6247. }
  6248. function applyHbarSparklineSetting() {
  6249. var paraPool = [];
  6250. var value = getTextValue("hbarSparklineValue");
  6251. var colorScheme = getBackgroundColor("hbarSparklineColorScheme");
  6252. colorScheme = "\"" + colorScheme + "\"";
  6253. paraPool.push(value);
  6254. paraPool.push(colorScheme);
  6255. var params = formatFormula(paraPool);
  6256. var formula = "=HBARSPARKLINE(" + params + ")";
  6257. setFormulaSparkline(formula);
  6258. updateFormulaBar();
  6259. }
  6260. function applyVbarSparklineSetting() {
  6261. var paraPool = [];
  6262. var value = getTextValue("vbarSparklineValue");
  6263. var colorScheme = getBackgroundColor("vbarSparklineColorScheme");
  6264. colorScheme = "\"" + colorScheme + "\"";
  6265. paraPool.push(value);
  6266. paraPool.push(colorScheme);
  6267. var params = formatFormula(paraPool);
  6268. var formula = "=VBARSPARKLINE(" + params + ")";
  6269. setFormulaSparkline(formula);
  6270. updateFormulaBar();
  6271. }
  6272. function applyParetoSparklineSetting() {
  6273. var pointsRangeValue = getTextValue("paretoSparklinePoints");
  6274. var pointIndexValue = getTextValue("paretoSparklinePointIndex");
  6275. var colorRangeValue = getTextValue("paretoSparklineColorRange");
  6276. var targetValue = getTextValue("paretoSparklineTarget");
  6277. var target2Value = getTextValue("paretoSparklineTarget2");
  6278. var highlightPositionValue = getTextValue("paretoSparklineHighlightPosition");
  6279. var labelValue = getDropDownValue("paretoLabelType");
  6280. var verticalValue = getCheckValue("paretoSparklineVertical");
  6281. var paraPool = [
  6282. pointsRangeValue,
  6283. pointIndexValue,
  6284. colorRangeValue,
  6285. targetValue,
  6286. target2Value,
  6287. highlightPositionValue,
  6288. labelValue,
  6289. verticalValue
  6290. ];
  6291. var params = formatFormula(paraPool);
  6292. var formula = "=PARETOSPARKLINE(" + params + ")";
  6293. setFormulaSparkline(formula);
  6294. updateFormulaBar();
  6295. }
  6296. function applySpreadSparklineSetting() {
  6297. var pointsValue = getTextValue("spreadSparklinePoints");
  6298. var showAverageValue = getCheckValue("spreadSparklineShowAverage");
  6299. var scaleStartValue = getTextValue("spreadSparklineScaleStart");
  6300. var scaleEndValue = getTextValue("spreadSparklineScaleEnd");
  6301. var styleValue = getDropDownValue("spreadSparklineStyleType");
  6302. var colorSchemeValue = getBackgroundColor("spreadSparklineColorScheme");
  6303. var verticalValue = getCheckValue("spreadSparklineVertical");
  6304. var colorSchemeString = colorSchemeValue ? "\"" + colorSchemeValue + "\"" : null;
  6305. var paraPool = [
  6306. pointsValue,
  6307. showAverageValue,
  6308. scaleStartValue,
  6309. scaleEndValue,
  6310. styleValue,
  6311. colorSchemeString,
  6312. verticalValue
  6313. ];
  6314. var params = formatFormula(paraPool);
  6315. var formula = "=SPREADSPARKLINE(" + params + ")";
  6316. setFormulaSparkline(formula);
  6317. updateFormulaBar();
  6318. }
  6319. function applyStackedSparklineSetting() {
  6320. var pointsValue = getTextValue("stackedSparklinePoints");
  6321. var colorRangeValue = getTextValue("stackedSparklineColorRange");
  6322. var labelRangeValue = getTextValue("stackedSparklineLabelRange");
  6323. var maximumValue = getNumberValue("stackedSparklineMaximum");
  6324. var targetRedValue = getNumberValue("stackedSparklineTargetRed");
  6325. var targetGreenValue = getNumberValue("stackedSparklineTargetGreen");
  6326. var targetBlueValue = getNumberValue("stackedSparklineTargetBlue");
  6327. var targetYellowValue = getNumberValue("stackedSparklineTargetYellow");
  6328. var colorValue = getBackgroundColor("stackedSparklineColor");
  6329. var highlightPositionValue = getNumberValue("stackedSparklineHighlightPosition");
  6330. var verticalValue = getCheckValue("stackedSparklineVertical");
  6331. var textOrientationValue = getDropDownValue("stackedSparklineTextOrientation");
  6332. var textSizeValue = getNumberValue("stackedSparklineTextSize");
  6333. var colorString = colorValue ? "\"" + colorValue + "\"" : null;
  6334. var paraPool = [
  6335. pointsValue,
  6336. colorRangeValue,
  6337. labelRangeValue,
  6338. maximumValue,
  6339. targetRedValue,
  6340. targetGreenValue,
  6341. targetBlueValue,
  6342. targetYellowValue,
  6343. colorString,
  6344. highlightPositionValue,
  6345. verticalValue,
  6346. textOrientationValue,
  6347. textSizeValue
  6348. ];
  6349. var params = formatFormula(paraPool);
  6350. var formula = "=STACKEDSPARKLINE(" + params + ")";
  6351. setFormulaSparkline(formula);
  6352. updateFormulaBar();
  6353. }
  6354. function applyVariSparklineSetting() {
  6355. var varianceValue = getTextValue("variSparklineVariance");
  6356. var referenceValue = getTextValue("variSparklineReference");
  6357. var miniValue = getTextValue("variSparklineMini");
  6358. var maxiValue = getTextValue("variSparklineMaxi");
  6359. var markValue = getTextValue("variSparklineMark");
  6360. var tickunitValue = getTextValue("variSparklineTickUnit");
  6361. var colorPositiveValue = getBackgroundColor("variSparklineColorPositive");
  6362. var colorNegativeValue = getBackgroundColor("variSparklineColorNegative");
  6363. var legendValue = getCheckValue("variSparklineLegend");
  6364. var verticalValue = getCheckValue("variSparklineVertical");
  6365. var colorPositiveStr = colorPositiveValue ? "\"" + colorPositiveValue + "\"" : null;
  6366. var colorNegativeStr = colorNegativeValue ? "\"" + colorNegativeValue + "\"" : null;
  6367. var paraPool = [
  6368. varianceValue,
  6369. referenceValue,
  6370. miniValue,
  6371. maxiValue,
  6372. markValue,
  6373. tickunitValue,
  6374. legendValue,
  6375. colorPositiveStr,
  6376. colorNegativeStr,
  6377. verticalValue
  6378. ];
  6379. var params = formatFormula(paraPool);
  6380. var formula = "=VARISPARKLINE(" + params + ")";
  6381. setFormulaSparkline(formula);
  6382. updateFormulaBar();
  6383. }
  6384. function applyMonthSparklineSetting() {
  6385. var dataRangeStr = getTextValue("monthSparklineData");
  6386. var year = getTextValue("monthSparklineYear");
  6387. var month = getTextValue("monthSparklineMonth");
  6388. var emptyColor = getBackgroundColor("monthSparklineEmptyColor");
  6389. var startColor = getBackgroundColor("monthSparklineStartColor");
  6390. var middleColor = getBackgroundColor("monthSparklineMiddleColor");
  6391. var endColor = getBackgroundColor("monthSparklineEndColor");
  6392. var colorRangeStr = getTextValue("monthSparklineColorRange");
  6393. var formulaStr;
  6394. if (!colorRangeStr) {
  6395. formulaStr = "=" + "MONTHSPARKLINE" + "(" + year + "," + month + "," + dataRangeStr + "," + parseSparklineColorOptions(emptyColor) + "," + parseSparklineColorOptions(startColor) + "," + parseSparklineColorOptions(middleColor) + "," + parseSparklineColorOptions(endColor) + ")";
  6396. } else {
  6397. formulaStr = "=" + "MONTHSPARKLINE" + "(" + year + "," + month + "," + dataRangeStr + "," + colorRangeStr + ")";
  6398. }
  6399. setFormulaSparkline(formulaStr);
  6400. updateFormulaBar();
  6401. }
  6402. function applyYearSparklineSetting() {
  6403. var dataRangeStr = getTextValue("yearSparklineData");
  6404. var year = getTextValue("yearSparklineYear");
  6405. var emptyColor = getBackgroundColor("yearSparklineEmptyColor");
  6406. var startColor = getBackgroundColor("yearSparklineStartColor");
  6407. var middleColor = getBackgroundColor("yearSparklineMiddleColor");
  6408. var endColor = getBackgroundColor("yearSparklineEndColor");
  6409. var colorRangeStr = getTextValue("yearSparklineColorRange");
  6410. var formulaStr;
  6411. if (!colorRangeStr) {
  6412. formulaStr = "=" + "YEARSPARKLINE" + "(" + year + "," + dataRangeStr + "," + parseSparklineColorOptions(emptyColor) + "," + parseSparklineColorOptions(startColor) + "," + parseSparklineColorOptions(middleColor) + "," + parseSparklineColorOptions(endColor) + ")";
  6413. } else {
  6414. formulaStr = "=" + "YEARSPARKLINE" + "(" + year + "," + dataRangeStr + "," + colorRangeStr + ")";
  6415. }
  6416. setFormulaSparkline(formulaStr);
  6417. updateFormulaBar();
  6418. }
  6419. function applyPieSparklineSetting() {
  6420. var paraPool = [];
  6421. var range = getTextValue("pieSparklinePercentage");
  6422. paraPool.push(range);
  6423. $("#pieSparklineColorContainer").find(".color-view").each(function () {
  6424. var color = "\"" + $(this).css("background-color") + "\"";
  6425. paraPool.push(color);
  6426. });
  6427. var params = formatFormula(paraPool);
  6428. var formula = "=PIESPARKLINE(" + params + ")";
  6429. setFormulaSparkline(formula);
  6430. updateFormulaBar();
  6431. }
  6432. // Sparkline related items (end)
  6433. // Zoom related items
  6434. function processZoomSetting(value, title) {
  6435. if (typeof value === 'number') {
  6436. spread.getActiveSheet().zoom(value);
  6437. }
  6438. else {
  6439. console.log("processZoomSetting not process with ", value, title);
  6440. }
  6441. }
  6442. // Zoom related items (end)
  6443. function getResource(key) {
  6444. key = key.replace(/\./g, "_");
  6445. return resourceMap[key];
  6446. }
  6447. function getResourceMap(src) {
  6448. function isObject(item) {
  6449. return typeof item === "object";
  6450. }
  6451. function addResourceMap(map, obj, keys) {
  6452. if (isObject(obj)) {
  6453. for (var p in obj) {
  6454. var cur = obj[p];
  6455. addResourceMap(map, cur, keys.concat(p));
  6456. }
  6457. } else {
  6458. var key = keys.join("_");
  6459. map[key] = obj;
  6460. }
  6461. }
  6462. addResourceMap(resourceMap, src, []);
  6463. }
  6464. $(document).ready(function () {
  6465. function localizeUI() {
  6466. function getLocalizeString(text) {
  6467. var matchs = text.match(/(?:(@[\w\d\.]*@))/g);
  6468. if (matchs) {
  6469. matchs.forEach(function (item) {
  6470. var s = getResource(item.replace(/[@]/g, ""));
  6471. text = text.replace(item, s);
  6472. });
  6473. }
  6474. return text;
  6475. }
  6476. $(".localize").each(function () {
  6477. var text = $(this).text();
  6478. $(this).text(getLocalizeString(text));
  6479. });
  6480. $(".localize-tooltip").each(function () {
  6481. var text = $(this).prop("title");
  6482. $(this).prop("title", getLocalizeString(text));
  6483. });
  6484. $(".localize-value").each(function () {
  6485. var text = $(this).attr("value");
  6486. $(this).attr("value", getLocalizeString(text));
  6487. });
  6488. }
  6489. getResourceMap(uiResource);
  6490. localizeUI();
  6491. spread = new spreadNS.Workbook($("#ss")[0], {tabStripRatio: 0.88});
  6492. excelIO = new GC.Spread.Excel.IO();
  6493. getThemeColor();
  6494. initSpread();
  6495. //Change default allowCellOverflow the same with Excel.
  6496. spread.sheets.forEach(function (sheet) {
  6497. sheet.options.allowCellOverflow = true;
  6498. });
  6499. //window resize adjust
  6500. $(".insp-container").draggable();
  6501. checkMediaSize();
  6502. screenAdoption();
  6503. var resizeTimeout = null;
  6504. $(window).bind("resize", function () {
  6505. if (resizeTimeout === null) {
  6506. resizeTimeout = setTimeout(function () {
  6507. screenAdoption();
  6508. clearTimeout(resizeTimeout);
  6509. resizeTimeout = null;
  6510. }, 100);
  6511. }
  6512. });
  6513. doPrepareWork();
  6514. $("ul.dropdown-menu>li>a").click(function () {
  6515. var value = $(this).text(),
  6516. $divhost = $(this).parents("div.btn-group"),
  6517. groupName = $divhost.data("name"),
  6518. sheet = spread.getActiveSheet();
  6519. $divhost.find("button:first").text(value);
  6520. switch (groupName) {
  6521. case "fontname":
  6522. setStyleFont(sheet, "font-family", false, [value], value);
  6523. break;
  6524. case "fontsize":
  6525. setStyleFont(sheet, "font-size", false, [value], value);
  6526. break;
  6527. }
  6528. });
  6529. var toolbarHeight = $("#toolbar").height(),
  6530. formulaboxDefaultHeight = $("#formulabox").outerHeight(true),
  6531. verticalSplitterOriginalTop = formulaboxDefaultHeight - $("#verticalSplitter").height();
  6532. $("#verticalSplitter").draggable({
  6533. axis: "y", // vertical only
  6534. containment: "#inner-content-container", // limit in specified range
  6535. scroll: false, // not allow container scroll
  6536. zIndex: 100, // set to move on top
  6537. stop: function (event, ui) {
  6538. var $this = $(this),
  6539. top = $this.offset().top,
  6540. offset = top - toolbarHeight - verticalSplitterOriginalTop;
  6541. // limit min size
  6542. if (offset < 0) {
  6543. offset = 0;
  6544. }
  6545. // adjust size of related items
  6546. $("#formulabox").css({height: formulaboxDefaultHeight + offset});
  6547. var height = $("div.insp-container").height() - $("#formulabox").outerHeight(true);
  6548. $("#controlPanel").height(height);
  6549. $("#ss").height(height);
  6550. spread.refresh();
  6551. // reset
  6552. $(this).css({top: 0});
  6553. }
  6554. });
  6555. attachEvents();
  6556. $(document).on("contextmenu", function (e) {
  6557. var evt = window.event || e;
  6558. if (!$(evt.target).data('contextmenu')) {
  6559. evt.preventDefault();
  6560. return false;
  6561. }
  6562. });
  6563. $("#download").on("click", function (e) {
  6564. e.preventDefault();
  6565. return false;
  6566. });
  6567. spread.focus();
  6568. syncSheetPropertyValues();
  6569. syncSpreadPropertyValues();
  6570. onCellSelected();
  6571. updatePositionBox(spread.getActiveSheet());
  6572. //fix bug 220484
  6573. if (isIE) {
  6574. $("#formulabox").css('padding', 0);
  6575. }
  6576. });
  6577. // context menu related items
  6578. function getCellInSelections(selections, row, col) {
  6579. var count = selections.length, range;
  6580. for (var i = 0; i < count; i++) {
  6581. range = selections[i];
  6582. if (range.contains(row, col)) {
  6583. return range;
  6584. }
  6585. }
  6586. return null;
  6587. }
  6588. function getHitTest(pageX, pageY, sheet) {
  6589. var offset = $("#ss").offset(),
  6590. x = pageX - offset.left,
  6591. y = pageY - offset.top;
  6592. return sheet.hitTest(x, y);
  6593. }
  6594. function showMergeContextMenu() {
  6595. // use the result of updateMergeButtonsState
  6596. if ($("#mergeCells").attr("disabled")) {
  6597. $(".context-merge").hide();
  6598. } else {
  6599. $(".context-cell.divider").show();
  6600. $(".context-merge").show();
  6601. }
  6602. if ($("#unmergeCells").attr("disabled")) {
  6603. $(".context-unmerge").hide();
  6604. } else {
  6605. $(".context-cell.divider").show();
  6606. $(".context-unmerge").show();
  6607. }
  6608. }
  6609. function processSpreadContextMenu(e) {
  6610. // move the context menu to the position of the mouse point
  6611. var sheet = spread.getActiveSheet(),
  6612. target = getHitTest(e.pageX, e.pageY, sheet),
  6613. hitTestType = target.hitTestType,
  6614. row = target.row,
  6615. col = target.col,
  6616. selections = sheet.getSelections();
  6617. var isHideContextMenu = false;
  6618. if (hitTestType === spreadNS.SheetArea.colHeader) {
  6619. if (getCellInSelections(selections, row, col) === null) {
  6620. sheet.setSelection(-1, col, sheet.getRowCount(), 1);
  6621. }
  6622. if (row !== undefined && col !== undefined) {
  6623. $(".context-header").show();
  6624. $(".context-cell").hide();
  6625. }
  6626. } else if (hitTestType === spreadNS.SheetArea.rowHeader) {
  6627. if (getCellInSelections(selections, row, col) === null) {
  6628. sheet.setSelection(row, -1, 1, sheet.getColumnCount());
  6629. }
  6630. if (row !== undefined && col !== undefined) {
  6631. $(".context-header").show();
  6632. $(".context-cell").hide();
  6633. }
  6634. } else if (hitTestType === spreadNS.SheetArea.viewport) {
  6635. if (getCellInSelections(selections, row, col) === null) {
  6636. sheet.clearSelection();
  6637. sheet.endEdit();
  6638. sheet.setActiveCell(row, col);
  6639. updateMergeButtonsState();
  6640. }
  6641. if (row !== undefined && col !== undefined) {
  6642. $(".context-header").hide();
  6643. $(".context-cell").hide();
  6644. showMergeContextMenu();
  6645. } else {
  6646. isHideContextMenu = true;
  6647. }
  6648. } else if (hitTestType === spreadNS.SheetArea.corner) {
  6649. sheet.setSelection(-1, -1, sheet.getRowCount(), sheet.getColumnCount());
  6650. if (row !== undefined && col !== undefined) {
  6651. $(".context-header").hide();
  6652. $(".context-cell").show();
  6653. }
  6654. }
  6655. var $contextMenu = $("#spreadContextMenu");
  6656. $contextMenu.data("sheetArea", hitTestType);
  6657. if (isHideContextMenu) {
  6658. hideSpreadContextMenu();
  6659. } else {
  6660. $contextMenu.css({left: e.pageX, top: e.pageY});
  6661. $contextMenu.show();
  6662. $(document).on("mousedown.contextmenu", function () {
  6663. if ($(event.target).parents("#spreadContextMenu").length === 0) {
  6664. hideSpreadContextMenu();
  6665. }
  6666. });
  6667. }
  6668. }
  6669. function hideSpreadContextMenu() {
  6670. $("#spreadContextMenu").hide();
  6671. $(document).off("mousedown.contextmenu");
  6672. }
  6673. function processContextMenuClicked() {
  6674. var action = $(this).data("action");
  6675. var sheet = spread.getActiveSheet();
  6676. var sheetArea = $("#spreadContextMenu").data("sheetArea");
  6677. hideSpreadContextMenu();
  6678. switch (action) {
  6679. case "cut":
  6680. spread.commandManager().execute({cmd: "cut", sheetName: sheet.name()});
  6681. break;
  6682. case "copy":
  6683. spread.commandManager().execute({cmd: "copy", sheetName: sheet.name()});
  6684. break;
  6685. case "paste":
  6686. spread.commandManager().execute({cmd: "paste", sheetName: sheet.name()});
  6687. break;
  6688. case "insert":
  6689. if (sheetArea === spreadNS.SheetArea.colHeader) {
  6690. var insertColumnIndex = sheet.getActiveColumnIndex();
  6691. var colCount = sheet.getSelections()[0].colCount;
  6692. sheet.addColumns(insertColumnIndex, colCount);
  6693. for (var i = 0; i < colCount; i++) {
  6694. sheet.copyTo(-1, insertColumnIndex - 1, -1, insertColumnIndex + i, -1, 1, GC.Spread.Sheets.CopyToOptions.style);
  6695. }
  6696. } else if (sheetArea === spreadNS.SheetArea.rowHeader) {
  6697. var insertRowIndex = sheet.getActiveRowIndex();
  6698. var rowCount = sheet.getSelections()[0].rowCount;
  6699. sheet.addRows(insertRowIndex, rowCount);
  6700. for (var i = 0; i < rowCount; i++) {
  6701. sheet.copyTo(insertRowIndex - 1, -1, insertRowIndex + i, -1, 1, -1, GC.Spread.Sheets.CopyToOptions.style);
  6702. }
  6703. }
  6704. break;
  6705. case "delete":
  6706. if (sheetArea === spreadNS.SheetArea.colHeader) {
  6707. sheet.deleteColumns(sheet.getActiveColumnIndex(), sheet.getSelections()[0].colCount);
  6708. } else if (sheetArea === spreadNS.SheetArea.rowHeader) {
  6709. sheet.deleteRows(sheet.getActiveRowIndex(), sheet.getSelections()[0].rowCount);
  6710. }
  6711. break;
  6712. case "merge":
  6713. var sel = sheet.getSelections();
  6714. if (sel.length > 0) {
  6715. sel = sel[sel.length - 1];
  6716. sheet.addSpan(sel.row, sel.col, sel.rowCount, sel.colCount, spreadNS.SheetArea.viewport);
  6717. }
  6718. updateMergeButtonsState();
  6719. break;
  6720. case "unmerge":
  6721. var sels = sheet.getSelections();
  6722. for (var i = 0; i < sels.length; i++) {
  6723. var sel = getActualCellRange(sheet, sels[i], sheet.getRowCount(), sheet.getColumnCount());
  6724. for (var r = 0; r < sel.rowCount; r++) {
  6725. for (var c = 0; c < sel.colCount; c++) {
  6726. var span = sheet.getSpan(r + sel.row, c + sel.col, spreadNS.SheetArea.viewport);
  6727. if (span) {
  6728. sheet.removeSpan(span.row, span.col, spreadNS.SheetArea.viewport);
  6729. }
  6730. }
  6731. }
  6732. }
  6733. updateMergeButtonsState();
  6734. break;
  6735. default:
  6736. break;
  6737. }
  6738. }
  6739. // context menu related items (end)
  6740. // import / export related items
  6741. function processExportAction($dropdown, action) {
  6742. switch (action) {
  6743. case "exportJson":
  6744. exportToJSON();
  6745. break;
  6746. case "exportExcel":
  6747. exportToExcel();
  6748. break;
  6749. default:
  6750. break;
  6751. }
  6752. hideExportActionDropDown();
  6753. }
  6754. function importFile(file) {
  6755. var fileName = file.name;
  6756. var index = fileName.lastIndexOf('.');
  6757. var fileExt = fileName.substr(index + 1).toLowerCase();
  6758. if (fileExt === 'json' || fileExt === 'ssjson') {
  6759. importSpreadFromJSON(file);
  6760. } else if (fileExt === 'xlsx') {
  6761. importSpreadFromExcel(file);
  6762. } else {
  6763. alert(getResource("messages.invalidImportFile"));
  6764. }
  6765. }
  6766. function importSpreadFromExcel(file, options) {
  6767. function processPasswordDialog() {
  6768. importSpreadFromExcel(file, {password: getTextValue("txtPassword")});
  6769. setTextValue("txtPassword", "");
  6770. }
  6771. var PASSWORD_DIALOG_WIDTH = 300;
  6772. excelIO.open(file, function (json) {
  6773. importJson(json);
  6774. }, function (e) {
  6775. if (e.errorCode === 0 || e.errorCode === 1) {
  6776. alert(getResource("messages.invalidImportFile"));
  6777. } else if (e.errorCode === 2) {
  6778. $("#passwordError").hide();
  6779. showModal(uiResource.passwordDialog.title, PASSWORD_DIALOG_WIDTH, $("#passwordDialog").children(), processPasswordDialog);
  6780. } else if (e.errorCode === 3) {
  6781. $("#passwordError").show();
  6782. showModal(uiResource.passwordDialog.title, PASSWORD_DIALOG_WIDTH, $("#passwordDialog").children(), processPasswordDialog);
  6783. }
  6784. }, options);
  6785. }
  6786. function importSpreadFromJSON(file) {
  6787. function importSuccessCallback(responseText) {
  6788. var spreadJson = JSON.parse(responseText);
  6789. importJson(spreadJson);
  6790. }
  6791. var reader = new FileReader();
  6792. reader.onload = function () {
  6793. importSuccessCallback(this.result);
  6794. };
  6795. reader.readAsText(file);
  6796. return true;
  6797. }
  6798. function importJson(spreadJson) {
  6799. function updateActiveCells() {
  6800. for (var i = 0; i < spread.getSheetCount(); i++) {
  6801. var sheet = spread.getSheet(i);
  6802. columnIndex = sheet.getActiveColumnIndex(),
  6803. rowIndex = sheet.getActiveRowIndex();
  6804. if (columnIndex !== undefined && rowIndex !== undefined) {
  6805. spread.getSheet(i).setActiveCell(rowIndex, columnIndex);
  6806. } else {
  6807. spread.getSheet(i).setActiveCell(0, 0);
  6808. }
  6809. }
  6810. }
  6811. if (spreadJson.version && spreadJson.sheets) {
  6812. spread.unbindAll();
  6813. spread.fromJSON(spreadJson);
  6814. attachSpreadEvents(true);
  6815. updateActiveCells();
  6816. spread.focus();
  6817. fbx.workbook(spread);
  6818. onCellSelected();
  6819. syncSpreadPropertyValues();
  6820. syncSheetPropertyValues();
  6821. } else {
  6822. alert(getResource("messages.invalidImportFile"));
  6823. }
  6824. }
  6825. function getFileName() {
  6826. function to2DigitsString(num) {
  6827. return ("0" + num).substr(-2);
  6828. }
  6829. var date = new Date();
  6830. return [
  6831. "export",
  6832. date.getFullYear(), to2DigitsString(date.getMonth() + 1), to2DigitsString(date.getDate()),
  6833. to2DigitsString(date.getHours()), to2DigitsString(date.getMinutes()), to2DigitsString(date.getSeconds())
  6834. ].join("");
  6835. }
  6836. function exportToJSON() {
  6837. var json = spread.toJSON({includeBindingSource: true}),
  6838. text = JSON.stringify(json);
  6839. var fileName = getFileName();
  6840. if (isSafari) {
  6841. showModal(uiResource.toolBar.downloadTitle, DOWNLOAD_DIALOG_WIDTH, $("#downloadDialog").children(), function () {
  6842. $("#downloadDialog").hide();
  6843. });
  6844. var link = $("#download");
  6845. link[0].href = "data:text/plain;" + text;
  6846. } else {
  6847. saveAs(new Blob([text], {type: "text/plain;charset=utf-8"}), fileName + ".json");
  6848. }
  6849. }
  6850. function exportToExcel() {
  6851. var fileName = getFileName();
  6852. var json = spread.toJSON({includeBindingSource: true});
  6853. excelIO.save(json, function (blob) {
  6854. if (isSafari) {
  6855. var reader = new FileReader();
  6856. reader.onloadend = function () {
  6857. showModal(uiResource.toolBar.downloadTitle, DOWNLOAD_DIALOG_WIDTH, $("#downloadDialog").children(), function () {
  6858. $("#downloadDialog").hide();
  6859. });
  6860. var link = $("#download");
  6861. link[0].href = reader.result;
  6862. };
  6863. reader.readAsDataURL(blob);
  6864. } else {
  6865. saveAs(blob, fileName + ".xlsx");
  6866. }
  6867. }, function (e) {
  6868. alert(e);
  6869. });
  6870. }
  6871. // import / export related items (end)
  6872. // format related items
  6873. function processFormatSetting(name, title) {
  6874. switch (name) {
  6875. case "nullValue":
  6876. name = null;
  6877. case "0.00":
  6878. case "$#,##0.00":
  6879. case "$ #,##0.00;$ (#,##0.00);$ '-'??;@":
  6880. case "m/d/yyyy":
  6881. case "dddd, mmmm dd, yyyy":
  6882. case "h:mm:ss AM/PM":
  6883. case "0%":
  6884. case "# ?/?":
  6885. case "0.00E+00":
  6886. case "@":
  6887. setFormatter(name);
  6888. break;
  6889. default:
  6890. console.log("processFormatSetting not process with ", name, title);
  6891. break;
  6892. }
  6893. }
  6894. function setFormatter(value) {
  6895. var sheet = spread.getActiveSheet();
  6896. execInSelections(sheet, "formatter", function (sheet, row, column) {
  6897. var style = sheet.getStyle(row, column);
  6898. if (!style) {
  6899. style = new spreadNS.Style();
  6900. }
  6901. style.formatter = value;
  6902. sheet.setStyle(row, column, style);
  6903. });
  6904. }
  6905. function execInSelections(sheet, styleProperty, func) {
  6906. var selections = sheet.getSelections();
  6907. for (var k = 0; k < selections.length; k++) {
  6908. var selection = selections[k];
  6909. var col = selection.col, row = selection.row,
  6910. rowCount = selection.rowCount, colCount = selection.colCount;
  6911. if ((col === -1 || row === -1) && styleProperty) {
  6912. var style, r, c;
  6913. // whole sheet was selected, need set row / column' style one by one
  6914. if (col === -1 && row === -1) {
  6915. for (r = 0; r < rowCount; r++) {
  6916. if ((style = sheet.getStyle(r, -1)) && style[styleProperty] !== undefined) {
  6917. func(sheet, r, -1);
  6918. }
  6919. }
  6920. for (c = 0; c < colCount; c++) {
  6921. if ((style = sheet.getStyle(-1, c)) && style[styleProperty] !== undefined) {
  6922. func(sheet, -1, c);
  6923. }
  6924. }
  6925. }
  6926. // Get actual range for whole rows / columns / sheet selection
  6927. if (col === -1) {
  6928. col = 0;
  6929. }
  6930. if (row === -1) {
  6931. row = 0;
  6932. }
  6933. // set to each cell with style that in the adjusted selection range
  6934. for (var i = 0; i < rowCount; i++) {
  6935. r = row + i;
  6936. for (var j = 0; j < colCount; j++) {
  6937. c = col + j;
  6938. if ((style = sheet.getStyle(r, c)) && style[styleProperty] !== undefined) {
  6939. func(sheet, r, c);
  6940. }
  6941. }
  6942. }
  6943. }
  6944. if (selection.col == -1 && selection.row == -1) {
  6945. func(sheet, -1, -1);
  6946. }
  6947. else if (selection.row == -1) {
  6948. for (var i = 0; i < selection.colCount; i++) {
  6949. func(sheet, -1, selection.col + i);
  6950. }
  6951. }
  6952. else if (selection.col == -1) {
  6953. for (var i = 0; i < selection.rowCount; i++) {
  6954. func(sheet, selection.row + i, -1);
  6955. }
  6956. }
  6957. else {
  6958. for (var i = 0; i < selection.rowCount; i++) {
  6959. for (var j = 0; j < selection.colCount; j++) {
  6960. func(sheet, selection.row + i, selection.col + j);
  6961. }
  6962. }
  6963. }
  6964. }
  6965. }
  6966. // format related items (end)
  6967. // dialog related items
  6968. function showModal(title, width, content, callback) {
  6969. var $dialog = $("#modalTemplate"),
  6970. $body = $(".modal-body", $dialog);
  6971. $(".modal-title", $dialog).text(title);
  6972. $dialog.data("content-parent", content.parent());
  6973. $body.append(content);
  6974. // remove old and add new event handler since this modal is common used (reused)
  6975. $("#dialogConfirm").off("click");
  6976. $("#dialogConfirm").on("click", function () {
  6977. var result = callback();
  6978. // return an object with { canceled: true } to tell not close the modal, otherwise close the modal
  6979. if (!(result && result.canceled)) {
  6980. $("#modalTemplate").modal("hide");
  6981. }
  6982. });
  6983. if (!$dialog.data("event-attached")) {
  6984. $dialog.on("hidden.bs.modal", function () {
  6985. var $originalParent = $(this).data("content-parent");
  6986. if ($originalParent) {
  6987. $originalParent.append($(".modal-body", this).children());
  6988. }
  6989. });
  6990. $dialog.data("event-attached", true);
  6991. }
  6992. // set width of the dialog
  6993. $(".modal-dialog", $dialog).css({width: width});
  6994. $dialog.modal("show");
  6995. }
  6996. // dialog related items (end)
  6997. // clear related items
  6998. function processClearAction($dropdown, action) {
  6999. switch (action) {
  7000. case "clearAll":
  7001. doClear(255, true); // Laze mark all types with 255 (0xFF)
  7002. break;
  7003. case "clearFormat":
  7004. doClear(spreadNS.StorageType.style, true);
  7005. break;
  7006. default:
  7007. break;
  7008. }
  7009. hideClearActionDropDown();
  7010. }
  7011. function clearSpansInSelection(sheet, selection) {
  7012. if (sheet && selection) {
  7013. var ranges = [],
  7014. row = selection.row, col = selection.col,
  7015. rowCount = selection.rowCount, colCount = selection.colCount;
  7016. sheet.getSpans().forEach(function (range) {
  7017. if (range.intersect(row, col, rowCount, colCount)) {
  7018. ranges.push(range);
  7019. }
  7020. });
  7021. ranges.forEach(function (range) {
  7022. sheet.removeSpan(range.row, range.col);
  7023. });
  7024. }
  7025. }
  7026. function doClear(types, clearSpans) {
  7027. var sheet = spread.getActiveSheet(),
  7028. selections = sheet.getSelections();
  7029. selections.forEach(function (selection) {
  7030. sheet.clear(selection.row, selection.col, selection.rowCount, selection.colCount, spreadNS.SheetArea.viewport, types);
  7031. if (clearSpans) {
  7032. clearSpansInSelection(sheet, selection);
  7033. }
  7034. });
  7035. }
  7036. // clear related items (end)
  7037. // positionbox related items
  7038. function getSelectedRangeString(sheet, range) {
  7039. var selectionInfo = "",
  7040. rowCount = range.rowCount,
  7041. columnCount = range.colCount,
  7042. startRow = range.row + 1,
  7043. startColumn = range.col + 1;
  7044. if (rowCount == 1 && columnCount == 1) {
  7045. selectionInfo = getCellPositionString(sheet, startRow, startColumn);
  7046. }
  7047. else {
  7048. if (rowCount < 0 && columnCount > 0) {
  7049. selectionInfo = columnCount + "C";
  7050. }
  7051. else if (columnCount < 0 && rowCount > 0) {
  7052. selectionInfo = rowCount + "R";
  7053. }
  7054. else if (rowCount < 0 && columnCount < 0) {
  7055. selectionInfo = sheet.getRowCount() + "R x " + sheet.getColumnCount() + "C";
  7056. }
  7057. else {
  7058. selectionInfo = rowCount + "R x " + columnCount + "C";
  7059. }
  7060. }
  7061. return selectionInfo;
  7062. }
  7063. function getCellPositionString(sheet, row, column) {
  7064. if (row < 1 || column < 1) {
  7065. return null;
  7066. }
  7067. else {
  7068. var letters = "";
  7069. switch (spread.options.referenceStyle) {
  7070. case spreadNS.ReferenceStyle.a1: // 0
  7071. while (column > 0) {
  7072. var num = column % 26;
  7073. if (num === 0) {
  7074. letters = "Z" + letters;
  7075. column--;
  7076. }
  7077. else {
  7078. letters = String.fromCharCode('A'.charCodeAt(0) + num - 1) + letters;
  7079. }
  7080. column = parseInt((column / 26).toString());
  7081. }
  7082. letters += row.toString();
  7083. break;
  7084. case spreadNS.ReferenceStyle.r1c1: // 1
  7085. letters = "R" + row.toString() + "C" + column.toString();
  7086. break;
  7087. default:
  7088. break;
  7089. }
  7090. return letters;
  7091. }
  7092. }
  7093. // positionbox related items (end)
  7094. // theme color related items
  7095. function setThemeColorToSheet(sheet) {
  7096. sheet.suspendPaint();
  7097. sheet.getCell(2, 3).text("Background 1").themeFont("Body");
  7098. sheet.getCell(2, 4).text("Text 1").themeFont("Body");
  7099. sheet.getCell(2, 5).text("Background 2").themeFont("Body");
  7100. sheet.getCell(2, 6).text("Text 2").themeFont("Body");
  7101. sheet.getCell(2, 7).text("Accent 1").themeFont("Body");
  7102. sheet.getCell(2, 8).text("Accent 2").themeFont("Body");
  7103. sheet.getCell(2, 9).text("Accent 3").themeFont("Body");
  7104. sheet.getCell(2, 10).text("Accent 4").themeFont("Body");
  7105. sheet.getCell(2, 11).text("Accent 5").themeFont("Body");
  7106. sheet.getCell(2, 12).text("Accent 6").themeFont("Body");
  7107. sheet.getCell(4, 1).value("100").themeFont("Body");
  7108. sheet.getCell(4, 3).backColor("Background 1");
  7109. sheet.getCell(4, 4).backColor("Text 1");
  7110. sheet.getCell(4, 5).backColor("Background 2");
  7111. sheet.getCell(4, 6).backColor("Text 2");
  7112. sheet.getCell(4, 7).backColor("Accent 1");
  7113. sheet.getCell(4, 8).backColor("Accent 2");
  7114. sheet.getCell(4, 9).backColor("Accent 3");
  7115. sheet.getCell(4, 10).backColor("Accent 4");
  7116. sheet.getCell(4, 11).backColor("Accent 5");
  7117. sheet.getCell(4, 12).backColor("Accent 6");
  7118. sheet.getCell(5, 1).value("80").themeFont("Body");
  7119. sheet.getCell(5, 3).backColor("Background 1 80");
  7120. sheet.getCell(5, 4).backColor("Text 1 80");
  7121. sheet.getCell(5, 5).backColor("Background 2 80");
  7122. sheet.getCell(5, 6).backColor("Text 2 80");
  7123. sheet.getCell(5, 7).backColor("Accent 1 80");
  7124. sheet.getCell(5, 8).backColor("Accent 2 80");
  7125. sheet.getCell(5, 9).backColor("Accent 3 80");
  7126. sheet.getCell(5, 10).backColor("Accent 4 80");
  7127. sheet.getCell(5, 11).backColor("Accent 5 80");
  7128. sheet.getCell(5, 12).backColor("Accent 6 80");
  7129. sheet.getCell(6, 1).value("60").themeFont("Body");
  7130. sheet.getCell(6, 3).backColor("Background 1 60");
  7131. sheet.getCell(6, 4).backColor("Text 1 60");
  7132. sheet.getCell(6, 5).backColor("Background 2 60");
  7133. sheet.getCell(6, 6).backColor("Text 2 60");
  7134. sheet.getCell(6, 7).backColor("Accent 1 60");
  7135. sheet.getCell(6, 8).backColor("Accent 2 60");
  7136. sheet.getCell(6, 9).backColor("Accent 3 60");
  7137. sheet.getCell(6, 10).backColor("Accent 4 60");
  7138. sheet.getCell(6, 11).backColor("Accent 5 60");
  7139. sheet.getCell(6, 12).backColor("Accent 6 60");
  7140. sheet.getCell(7, 1).value("40").themeFont("Body");
  7141. sheet.getCell(7, 3).backColor("Background 1 40");
  7142. sheet.getCell(7, 4).backColor("Text 1 40");
  7143. sheet.getCell(7, 5).backColor("Background 2 40");
  7144. sheet.getCell(7, 6).backColor("Text 2 40");
  7145. sheet.getCell(7, 7).backColor("Accent 1 40");
  7146. sheet.getCell(7, 8).backColor("Accent 2 40");
  7147. sheet.getCell(7, 9).backColor("Accent 3 40");
  7148. sheet.getCell(7, 10).backColor("Accent 4 40");
  7149. sheet.getCell(7, 11).backColor("Accent 5 40");
  7150. sheet.getCell(7, 12).backColor("Accent 6 40");
  7151. sheet.getCell(8, 1).value("-25").themeFont("Body");
  7152. sheet.getCell(8, 3).backColor("Background 1 -25");
  7153. sheet.getCell(8, 4).backColor("Text 1 -25");
  7154. sheet.getCell(8, 5).backColor("Background 2 -25");
  7155. sheet.getCell(8, 6).backColor("Text 2 -25");
  7156. sheet.getCell(8, 7).backColor("Accent 1 -25");
  7157. sheet.getCell(8, 8).backColor("Accent 2 -25");
  7158. sheet.getCell(8, 9).backColor("Accent 3 -25");
  7159. sheet.getCell(8, 10).backColor("Accent 4 -25");
  7160. sheet.getCell(8, 11).backColor("Accent 5 -25");
  7161. sheet.getCell(8, 12).backColor("Accent 6 -25");
  7162. sheet.getCell(9, 1).value("-50").themeFont("Body");
  7163. sheet.getCell(9, 3).backColor("Background 1 -50");
  7164. sheet.getCell(9, 4).backColor("Text 1 -50");
  7165. sheet.getCell(9, 5).backColor("Background 2 -50");
  7166. sheet.getCell(9, 6).backColor("Text 2 -50");
  7167. sheet.getCell(9, 7).backColor("Accent 1 -50");
  7168. sheet.getCell(9, 8).backColor("Accent 2 -50");
  7169. sheet.getCell(9, 9).backColor("Accent 3 -50");
  7170. sheet.getCell(9, 10).backColor("Accent 4 -50");
  7171. sheet.getCell(9, 11).backColor("Accent 5 -50");
  7172. sheet.getCell(9, 12).backColor("Accent 6 -50");
  7173. sheet.resumePaint();
  7174. }
  7175. function getColorName(sheet, row, col) {
  7176. var colName = sheet.getCell(2, col).text();
  7177. var rowName = sheet.getCell(row, 1).text();
  7178. return colName + " " + rowName;
  7179. }
  7180. function getThemeColor() {
  7181. var sheet = spread.getActiveSheet();
  7182. setThemeColorToSheet(sheet); // Set current theme color to sheet
  7183. var $colorUl = $("#default-theme-color");
  7184. var $themeColorLi, cellBackColor;
  7185. for (var col = 3; col < 13; col++) {
  7186. var row = 4;
  7187. cellBackColor = sheet.getActualStyle(row, col).backColor;
  7188. $themeColorLi = $("<li class=\"color-cell seed-color-column\"></li>");
  7189. $themeColorLi.css("background-color", cellBackColor).attr("data-name", sheet.getCell(2, col).text()).appendTo($colorUl);
  7190. for (row = 5; row < 10; row++) {
  7191. cellBackColor = sheet.getActualStyle(row, col).backColor;
  7192. $themeColorLi = $("<li class=\"color-cell\"></li>");
  7193. $themeColorLi.css("background-color", cellBackColor).attr("data-name", getColorName(sheet, row, col)).appendTo($colorUl);
  7194. }
  7195. }
  7196. sheet.clear(2, 1, 8, 12, spreadNS.SheetArea.viewport, 255); // Clear sheet theme color
  7197. }
  7198. // theme color related items (end)
  7199. // slicer related items
  7200. function processAddSlicer() {
  7201. addTableColumns(); // get table header data from table, and add them to slicer dialog
  7202. var SLICER_DIALOG_WIDTH = 230; // slicer dialog width
  7203. showModal(uiResource.slicerDialog.insertSlicer, SLICER_DIALOG_WIDTH, $("#insertslicerdialog").children(), addSlicerEvent);
  7204. }
  7205. function addTableColumns() {
  7206. var table = _activeTable;
  7207. if (!table) {
  7208. return;
  7209. }
  7210. var $slicerContainer = $("#slicer-container");
  7211. $slicerContainer.empty();
  7212. for (var col = 0; col < table.range().colCount; col++) {
  7213. var columnName = table.getColumnName(col);
  7214. var $slicerDiv = $(
  7215. "<div>"
  7216. + "<div class='insp-row'>"
  7217. + "<div>"
  7218. + "<div class='insp-checkbox insp-inline-row'>"
  7219. + "<div class='button insp-inline-row-item'></div>"
  7220. + "<div class='text insp-inline-row-item localize'>" + columnName + "</div>"
  7221. + "</div>"
  7222. + "</div>"
  7223. + "</div>"
  7224. + "</div>");
  7225. $slicerDiv.appendTo($slicerContainer);
  7226. }
  7227. $("#slicer-container .insp-checkbox").click(checkedChanged);
  7228. }
  7229. function getSlicerName(sheet, columnName) {
  7230. var autoID = 1;
  7231. var newName = columnName;
  7232. while (sheet.slicers.get(newName)) {
  7233. newName = columnName + '_' + autoID;
  7234. autoID++;
  7235. }
  7236. return newName;
  7237. }
  7238. function addSlicerEvent() {
  7239. var table = _activeTable;
  7240. if (!table) {
  7241. return;
  7242. }
  7243. var checkedColumnIndexArray = [];
  7244. $("#slicer-container div.button").each(function (index) {
  7245. if ($(this).hasClass("checked")) {
  7246. checkedColumnIndexArray.push(index);
  7247. }
  7248. });
  7249. var sheet = spread.getActiveSheet();
  7250. var posX = 100, posY = 200;
  7251. spread.suspendPaint();
  7252. for (var i = 0; i < checkedColumnIndexArray.length; i++) {
  7253. var columnName = table.getColumnName(checkedColumnIndexArray[i]);
  7254. var slicerName = getSlicerName(sheet, columnName);
  7255. var slicer = sheet.slicers.add(slicerName, table.name(), columnName);
  7256. slicer.position(new spreadNS.Point(posX, posY));
  7257. posX = posX + 30;
  7258. posY = posY + 30;
  7259. }
  7260. spread.resumePaint();
  7261. slicer.isSelected(true);
  7262. initSlicerTab();
  7263. }
  7264. function bindSlicerEvents(sheet, slicer, propertyName) {
  7265. if (!slicer) {
  7266. return;
  7267. }
  7268. if (propertyName === "isSelected") {
  7269. if (slicer.isSelected()) {
  7270. if (sheet.options.protectionOptions.allowEditObjects || !(sheet.options.isProtected && slicer.isLocked())) {
  7271. setActiveTab("slicer");
  7272. initSlicerTab();
  7273. }
  7274. }
  7275. else {
  7276. // setActiveTab("cell");
  7277. // The events' execution sequence is different between V10 and V9.
  7278. // In V9, EnterCell event will execute after SlicerChanged event. But in V10, SlicerChanged event will execute after EnterCell event.
  7279. // So, when I move focus from table slicer to table cell, table tab will not be active.
  7280. // In this situation, code above should be removed to make table be active.
  7281. }
  7282. }
  7283. else {
  7284. changeSlicerInfo(slicer, propertyName);
  7285. }
  7286. }
  7287. function initSlicerTab() {
  7288. var sheet = spread.getActiveSheet();
  7289. var selectedSlicers = getSelectedSlicers(sheet);
  7290. if (!selectedSlicers || selectedSlicers.length === 0) {
  7291. return;
  7292. }
  7293. if (selectedSlicers.length > 1) {
  7294. getMultiSlicerSetting(selectedSlicers);
  7295. setTextDisabled("slicerName", true);
  7296. }
  7297. else if (selectedSlicers.length === 1) {
  7298. getSingleSlicerSetting(selectedSlicers[0]);
  7299. setTextDisabled("slicerName", false);
  7300. }
  7301. }
  7302. function getSingleSlicerSetting(slicer) {
  7303. if (!slicer) {
  7304. return;
  7305. }
  7306. setTextValue("slicerName", slicer.name());
  7307. setTextValue("slicerCaptionName", slicer.captionName());
  7308. setDropDownValue("slicerItemSorting", slicer.sortState());
  7309. setCheckValue("displaySlicerHeader", slicer.showHeader());
  7310. setNumberValue("slicerColumnNumber", slicer.columnCount());
  7311. setNumberValue("slicerButtonWidth", getSlicerItemWidth(slicer.columnCount(), slicer.width()));
  7312. setNumberValue("slicerButtonHeight", slicer.itemHeight());
  7313. if (slicer.dynamicMove()) {
  7314. if (slicer.dynamicSize()) {
  7315. setRadioItemChecked("slicerMoveAndSize", "slicer-move-size");
  7316. }
  7317. else {
  7318. setRadioItemChecked("slicerMoveAndSize", "slicer-move-nosize");
  7319. }
  7320. }
  7321. else {
  7322. setRadioItemChecked("slicerMoveAndSize", "slicer-nomove-size");
  7323. }
  7324. setCheckValue("lockSlicer", slicer.isLocked());
  7325. selectedCurrentSlicerStyle(slicer);
  7326. }
  7327. function getMultiSlicerSetting(selectedSlicers) {
  7328. if (!selectedSlicers || selectedSlicers.length === 0) {
  7329. return;
  7330. }
  7331. var slicer = selectedSlicers[0];
  7332. var isDisplayHeader = false,
  7333. isSameSortState = true,
  7334. isSameCaptionName = true,
  7335. isSameColumnCount = true,
  7336. isSameItemHeight = true,
  7337. isSameItemWidth = true,
  7338. isSameLocked = true,
  7339. isSameDynamicMove = true,
  7340. isSameDynamicSize = true;
  7341. var sortState = slicer.sortState(),
  7342. captionName = slicer.captionName(),
  7343. columnCount = slicer.columnCount(),
  7344. itemHeight = slicer.itemHeight(),
  7345. itemWidth = getSlicerItemWidth(columnCount, slicer.width()),
  7346. dynamicMove = slicer.dynamicMove(),
  7347. dynamicSize = slicer.dynamicSize();
  7348. for (var item in selectedSlicers) {
  7349. var slicer = selectedSlicers[item];
  7350. isDisplayHeader = isDisplayHeader || slicer.showHeader();
  7351. isSameLocked = isSameLocked && slicer.isLocked();
  7352. if (slicer.sortState() !== sortState) {
  7353. isSameSortState = false;
  7354. }
  7355. if (slicer.captionName() !== captionName) {
  7356. isSameCaptionName = false;
  7357. }
  7358. if (slicer.columnCount() !== columnCount) {
  7359. isSameColumnCount = false;
  7360. }
  7361. if (slicer.itemHeight() !== itemHeight) {
  7362. isSameItemHeight = false;
  7363. }
  7364. if (getSlicerItemWidth(slicer.columnCount(), slicer.width()) !== itemWidth) {
  7365. isSameItemWidth = false;
  7366. }
  7367. if (slicer.dynamicMove() !== dynamicMove) {
  7368. isSameDynamicMove = false;
  7369. }
  7370. if (slicer.dynamicSize() !== dynamicSize) {
  7371. isSameDynamicSize = false;
  7372. }
  7373. selectedCurrentSlicerStyle(slicer);
  7374. }
  7375. setTextValue("slicerName", "");
  7376. if (isSameCaptionName) {
  7377. setTextValue("slicerCaptionName", captionName);
  7378. }
  7379. else {
  7380. setTextValue("slicerCaptionName", "");
  7381. }
  7382. if (isSameSortState) {
  7383. setDropDownValue("slicerItemSorting", sortState);
  7384. }
  7385. else {
  7386. setDropDownValue("slicerItemSorting", "");
  7387. }
  7388. setCheckValue("displaySlicerHeader", isDisplayHeader);
  7389. if (isSameDynamicMove && isSameDynamicSize && dynamicMove) {
  7390. if (dynamicSize) {
  7391. setRadioItemChecked("slicerMoveAndSize", "slicer-move-size");
  7392. }
  7393. else {
  7394. setRadioItemChecked("slicerMoveAndSize", "slicer-move-nosize");
  7395. }
  7396. }
  7397. else {
  7398. setRadioItemChecked("slicerMoveAndSize", "slicer-nomove-size");
  7399. }
  7400. if (isSameColumnCount) {
  7401. setNumberValue("slicerColumnNumber", columnCount);
  7402. }
  7403. else {
  7404. setNumberValue("slicerColumnNumber", "");
  7405. }
  7406. if (isSameItemHeight) {
  7407. setNumberValue("slicerButtonHeight", Math.round(itemHeight));
  7408. }
  7409. else {
  7410. setNumberValue("slicerButtonHeight", "");
  7411. }
  7412. if (isSameItemWidth) {
  7413. setNumberValue("slicerButtonWidth", itemWidth);
  7414. }
  7415. else {
  7416. setNumberValue("slicerButtonWidth", "");
  7417. }
  7418. setCheckValue("lockSlicer", isSameLocked);
  7419. }
  7420. function changeSlicerInfo(slicer, propertyName) {
  7421. if (!slicer) {
  7422. return;
  7423. }
  7424. switch (propertyName) {
  7425. case "width":
  7426. setNumberValue("slicerButtonWidth", getSlicerItemWidth(slicer.columnCount(), slicer.width()));
  7427. break;
  7428. }
  7429. }
  7430. function setSlicerSetting(property, value) {
  7431. var sheet = spread.getActiveSheet();
  7432. var selectedSlicers = getSelectedSlicers(sheet);
  7433. if (!selectedSlicers || selectedSlicers.length === 0) {
  7434. return;
  7435. }
  7436. for (var item in selectedSlicers) {
  7437. setSlicerProperty(selectedSlicers[item], property, value);
  7438. }
  7439. }
  7440. function setSlicerProperty(slicer, property, value) {
  7441. switch (property) {
  7442. case "name":
  7443. var sheet = spread.getActiveSheet();
  7444. var slicerPreName = slicer.name();
  7445. if (!value) {
  7446. alert(getResource("messages.invalidSlicerName"));
  7447. setTextValue("slicerName", slicerPreName);
  7448. }
  7449. else if (value && value !== slicerPreName) {
  7450. if (sheet.floatingObjects.get(value)) {
  7451. alert(getResource("messages.duplicatedSlicerName"));
  7452. setTextValue("slicerName", slicerPreName);
  7453. }
  7454. else {
  7455. slicer.name(value);
  7456. }
  7457. }
  7458. break;
  7459. case "captionName":
  7460. slicer.captionName(value);
  7461. break;
  7462. case "sortState":
  7463. slicer.sortState(value);
  7464. break;
  7465. case "showHeader":
  7466. slicer.showHeader(value);
  7467. break;
  7468. case "columnCount":
  7469. slicer.columnCount(value);
  7470. break;
  7471. case "itemHeight":
  7472. slicer.itemHeight(value);
  7473. break;
  7474. case "itemWidth":
  7475. slicer.width(getSlicerWidthFromItem(slicer.columnCount(), value));
  7476. break;
  7477. case "moveSize":
  7478. if (value === "slicer-move-size") {
  7479. slicer.dynamicMove(true);
  7480. slicer.dynamicSize(true);
  7481. }
  7482. if (value === "slicer-move-nosize") {
  7483. slicer.dynamicMove(true);
  7484. slicer.dynamicSize(false);
  7485. }
  7486. if (value === "slicer-nomove-size") {
  7487. slicer.dynamicMove(false);
  7488. slicer.dynamicSize(false);
  7489. }
  7490. break;
  7491. case "lock":
  7492. slicer.isLocked(value);
  7493. break;
  7494. case "style":
  7495. slicer.style(value);
  7496. break;
  7497. default:
  7498. console.log("Slicer doesn't have property:", property);
  7499. break;
  7500. }
  7501. }
  7502. function setTextDisabled(name, isDisabled) {
  7503. var $item = $("div.insp-text[data-name='" + name + "']");
  7504. var $input = $item.find("input");
  7505. if (isDisabled) {
  7506. $item.addClass("disabled");
  7507. $input.attr("disabled", true);
  7508. }
  7509. else {
  7510. $item.removeClass("disabled");
  7511. $input.attr("disabled", false);
  7512. }
  7513. }
  7514. function setRadioItemChecked(groupName, itemName) {
  7515. var $radioGroup = $("div.insp-checkbox[data-name='" + groupName + "']");
  7516. var $radioItems = $("div.radiobutton[data-name='" + itemName + "']");
  7517. $radioGroup.find(".radiobutton").removeClass("checked");
  7518. $radioItems.addClass("checked");
  7519. }
  7520. function getSlicerItemWidth(count, slicerWidth) {
  7521. if (count <= 0) {
  7522. count = 1; //Column count will be converted to 1 if it is set to 0 or negative number.
  7523. }
  7524. var SLICER_PADDING = 6;
  7525. var SLICER_ITEM_SPACE = 2;
  7526. var itemWidth = Math.round((slicerWidth - SLICER_PADDING * 2 - (count - 1) * SLICER_ITEM_SPACE) / count);
  7527. if (itemWidth < 0) {
  7528. return 0;
  7529. }
  7530. else {
  7531. return itemWidth;
  7532. }
  7533. }
  7534. function getSlicerWidthFromItem(count, itemWidth) {
  7535. if (count <= 0) {
  7536. count = 1; //Column count will be converted to 1 if it is set to 0 or negative number.
  7537. }
  7538. var SLICER_PADDING = 6;
  7539. var SLICER_ITEM_SPACE = 2;
  7540. return Math.round(itemWidth * count + (count - 1) * SLICER_ITEM_SPACE + SLICER_PADDING * 2);
  7541. }
  7542. function getSelectedSlicers(sheet) {
  7543. if (!sheet) {
  7544. return null;
  7545. }
  7546. var slicers = sheet.slicers.all();
  7547. if (!slicers || slicers.length === 0) {
  7548. return null;
  7549. }
  7550. var selectedSlicers = [];
  7551. for (var item in slicers) {
  7552. if (slicers[item].isSelected()) {
  7553. selectedSlicers.push(slicers[item]);
  7554. }
  7555. }
  7556. return selectedSlicers;
  7557. }
  7558. function processSlicerItemSorting(sortValue) {
  7559. switch (sortValue) {
  7560. case 0:
  7561. case 1:
  7562. case 2:
  7563. setSlicerSetting("sortState", sortValue);
  7564. break;
  7565. default:
  7566. console.log("processSlicerItemSorting not process with ", name);
  7567. return;
  7568. }
  7569. }
  7570. function selectedCurrentSlicerStyle(slicer) {
  7571. var slicerStyle = slicer.style(),
  7572. styleName = slicerStyle && slicerStyle.name();
  7573. $("#slicerStyles .slicer-format-item").removeClass("slicer-format-item-selected");
  7574. styleName = styleName.split("SlicerStyle")[1];
  7575. if (styleName) {
  7576. $("#slicerStyles .slicer-format-item div[data-name='" + styleName.toLowerCase() + "']").parent().addClass("slicer-format-item-selected");
  7577. }
  7578. }
  7579. function changeSlicerStyle() {
  7580. spread.suspendPaint();
  7581. var styleName = $(">div", this).data("name");
  7582. setSlicerSetting("style", spreadNS.Slicers.SlicerStyles[styleName]());
  7583. $("#slicerStyles .slicer-format-item").removeClass("slicer-format-item-selected");
  7584. $(this).addClass("slicer-format-item-selected");
  7585. spread.resumePaint();
  7586. }
  7587. // slicer related items (end)
  7588. // spread theme related items
  7589. function processChangeSpreadTheme(value) {
  7590. $("link[title='spread-theme']").attr("href", value);
  7591. setTimeout(
  7592. function () {
  7593. spread.refresh();
  7594. }, 300);
  7595. }
  7596. // spread theme related items (end)
  7597. //cell label related item
  7598. function setLabelOptions(sheet, value, option) {
  7599. var selections = sheet.getSelections(),
  7600. rowCount = sheet.getRowCount(),
  7601. columnCount = sheet.getColumnCount();
  7602. sheet.suspendPaint();
  7603. for (var n = 0; n < selections.length; n++) {
  7604. var sel = getActualCellRange(sheet, selections[n], rowCount, columnCount);
  7605. for (var r = sel.row; r < sel.row + sel.rowCount; r++) {
  7606. for (var c = sel.col; c < sel.col + sel.colCount; c++) {
  7607. var style = sheet.getStyle(r, c);
  7608. if (!style) {
  7609. style = new spreadNS.Style();
  7610. }
  7611. if (!style.labelOptions) {
  7612. style.labelOptions = {};
  7613. }
  7614. if (option === "foreColor") {
  7615. style.labelOptions.foreColor = value;
  7616. } else if (option === "margin") {
  7617. style.labelOptions.margin = value;
  7618. } else if (option === "visibility") {
  7619. style.labelOptions.visibility = GC.Spread.Sheets.LabelVisibility[value];
  7620. } else if (option === "alignment") {
  7621. style.labelOptions.alignment = GC.Spread.Sheets.LabelAlignment[value];
  7622. }
  7623. sheet.setStyle(r, c, style);
  7624. }
  7625. }
  7626. }
  7627. sheet.resumePaint();
  7628. }
  7629. function setWatermark(sheet, value) {
  7630. var selections = sheet.getSelections(),
  7631. rowCount = sheet.getRowCount(),
  7632. columnCount = sheet.getColumnCount();
  7633. sheet.suspendPaint();
  7634. for (var n = 0; n < selections.length; n++) {
  7635. var sel = getActualCellRange(sheet, selections[n], rowCount, columnCount);
  7636. for (var r = sel.row; r < sel.row + sel.rowCount; r++) {
  7637. for (var c = sel.col; c < sel.col + sel.colCount; c++) {
  7638. var style = sheet.getStyle(r, c);
  7639. if (!style) {
  7640. style = new spreadNS.Style();
  7641. }
  7642. style.watermark = value;
  7643. sheet.setStyle(r, c, style);
  7644. }
  7645. }
  7646. }
  7647. sheet.resumePaint();
  7648. }
  7649. function setCellPadding(sheet, value) {
  7650. var selections = sheet.getSelections(),
  7651. rowCount = sheet.getRowCount(),
  7652. columnCount = sheet.getColumnCount();
  7653. sheet.suspendPaint();
  7654. for (var n = 0; n < selections.length; n++) {
  7655. var sel = getActualCellRange(sheet, selections[n], rowCount, columnCount);
  7656. for (var r = sel.row; r < sel.row + sel.rowCount; r++) {
  7657. for (var c = sel.col; c < sel.col + sel.colCount; c++) {
  7658. var style = sheet.getStyle(r, c);
  7659. if (!style) {
  7660. style = new spreadNS.Style();
  7661. }
  7662. style.cellPadding = value;
  7663. sheet.setStyle(r, c, style);
  7664. }
  7665. }
  7666. }
  7667. sheet.resumePaint();
  7668. }
  7669. //cell label related item (end)